user574183
user574183

Reputation: 716

bison calculator problem

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 ?

Upvotes: 0

Views: 290

Answers (1)

Linus Kleen
Linus Kleen

Reputation: 34642

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.

Upvotes: 1

Related Questions