Question
3. Consider the following grammar for infix arithmetic expressions. E -> E + T -> E - T -> + T -> - T ->
3. Consider the following grammar for infix arithmetic expressions.
E -> E + T
-> E - T
-> + T
-> - T
-> T
T -> T * F
-> T / F
-> F
F -> ( E )
-> i
a) Add semantic actions in appropriate positions in the rules to effect
a translation from infix to postfix code for the 8087 FPU. The
instructions corresponding to the various stack operations are given
in the following table.
load i on stack: fld i
negate: fchs
add: fadd
subtract: fsub
multiply: fmul
divide: fdiv
b) Construct a parse tree with actions to derive the output for the
expression -a + b*c - d/e.
c) Convert the translation grammar produced in (a) to a form that can be
parsed by a recursive descent parser.
d) Write procedures E, T, and F for a recursive descent parser for the
grammar in (c). Include any extra code needed for the translation.
4. Consider the following grammar G (with start symbol A).
A -> i B := e
B -> S B
B ->
S -> [ e C ]
S -> .i
C -> , e C
C ->
a) Construct the leftmost derivation and the associated parse tree
for the input i [ e ] := e.
b) Calculate the FIRST and FOLLOW sets for all non-terminals in the
grammar G.
c) Calculate the SELECT sets for each production.
d) Construct the LL( 1) parsing table for this grammar.
e) Show the sequence of configurations of an LL( 1) parser for the
input i [ e ] := e.
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