开发者

bison calculator problem

开发者 https://www.devze.com 2023-02-08 20:31 出处:网络
开发者_开发问答stmt : expr{printf(\"%d\\n\",$1);} ; expr :expr \'+\' expr{$$ = $1 + $3;} |expr \'-\' expr{$$ = $1 - $3;}
开发者_开发问答stmt : expr  {printf("%d\n",$1);}
      ;

expr :  expr '+' expr  {$$ = $1 + $3;}
     |  expr '-' expr  {$$ = $1 - $3;}
     |  INTEGER        {$$ = $1;}
     ;

When is the stmt non terminal being executed by bison. When it sees which character ?


Assuming, these are all the rules from your bison input, the nonterminal symbol stmt gets "executed" as soon as EOF is reached (i.e.: no further input and the last expr has been reduced).

However, there are conflicts in your grammar.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号