我正在尝试创建一个简单的解析器。
cond: T_IF '(' exp ')' '#' stmt_block opt_elseifs opt_else end {if($3 == 0) return;}
opt_elseifs : /* Nothing */
| opt_elseifs T_ELSIF '(' exp ')' '#' stmt_block '#'
;
opt_else : /* Nothing */
| T_ELSE '#' stmt_block '#'
;
end : '#'
;
例如,
a = 0;
if(a) #
c = 10 + 20;
#
我不想要打印c的值,但这是c的打印值。 我在这里做错了什么?
答案 0 :(得分:0)
阅读野牛手册后找到解决方案。所以,我想我最好也在这里分享一下。 我应该做
cond: T_IF '(' exp ')' { if($3 == 0) return; }
'#' stmt_block opt_elseifs opt_else end
;
因此,如果exp被评估为false,则它不会进一步解析。