edited by
656 views
0 votes
0 votes
E → number  | E '+' E    | E '×' E  

This grammar is fed to a YACC tool for parsing.

What will be the output for expression 3×2+1?

 

/* How to solve this? please explain*/
edited by

1 Answer

0 votes
0 votes
Since you are not printing anything with the grammar, you can't expect an output.

Plus considering the precedence from left to right in any production of YACC.

3 will be parsed as "number" (because it has the highest precedence according to your production). Then "*" will be the next token for the compiler and it won't match any, resulting in an ERROR.

Related questions

0 votes
0 votes
2 answers
1
0 votes
0 votes
1 answer
2
Aboveallplayer asked Feb 3, 2017
487 views
in case of shift-reduce and R-R conflict, which is favored by YACC?
1 votes
1 votes
1 answer
3
LavTheRawkstar asked Nov 10, 2016
1,179 views
The difference between a Lex Compiler and a YACC compiler is ?