Question
Given the following Flex and Bison specs (only the rules sections are shown, reasonable assumptions can be made about the missing parts), create the tree
Given the following Flex and Bison specs (only the rules sections are shown, reasonable assumptions can be made about the missing parts), create the tree diagrams including final value for the following input: 3 7 + 3 4 + - n
%% [ \t] ; // ignore all whitespace [0-9]+ {yylval.ival = atoi(yytext); return T_INT;} {return T_NEWLINE;} "+" {return T_PLUS;} "-" {return T_MINUS;} "*" {return T_MULTIPLY;} "^" {return T_EXP;} "/" {return T_DIVIDE;} "(" {return T_LEFT;} ")" {return T_RIGHT;} "n" {return NEG;} "exit" {return T_QUIT;} "quit" {return T_QUIT;} %%
///////////////////////////////////////////////////////////////////////////////////////////////
%% input: /* empty */ | input line ; line: T_NEWLINE | expr T_NEWLINE { printf ("\t%d ", $1); } ; expr: T_INT {$$ = $1; } | expr expr T_PLUS { $$ = $1 + $2; } | expr expr T_MINUS { $$ = $1 - $2; } | expr expr T_MULTIPLY { $$ = $1 * $2; } | expr expr T_DIVIDE { $$ = $1 / $2; } | expr expr T_EXP { $$ = pow ($1, $2); } | expr NEG { $$ = -$1; } ; %%
*Note that the upper case words are terminals and lower case words are non-terminals **The empty option for input is a null production
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started