According to the following context - free grammar, write a yacc file as a intege
ID: 3676887 • Letter: A
Question
According to the following context - free grammar, write a yacc file as a integer calculator that can do +, - , *, /, and ^ with or without ( ) .
command expr
expr expr + term | expr – term | term
term term * term2 | term / term2 | term2 | - factor
term2 factor ^ term2 | factor factor ( expr ) | NUMBER.
Also: In order to run calculator on real numbers, add the following in the definition section and make other necessary changes accordingly :
%token NUMBER
%union { double val; char op; }
%type <val> exp term factor NUMBER
%type <op> '+' ' - ' '*' '/' '(' ')'
%%
Explanation / Answer
simple calculator using yacc
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.