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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!