Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following grammar: (1) expr -> term term_tail (2) term_tail -> add_

ID: 649679 • Letter: C

Question

Consider the following grammar:
(1) expr -> term term_tail
(2) term_tail -> add_op term term_tail | ?
(3) term -> factor factor_tail
(4) factor_tail -> mult_op factor factor_tail | ?
(5) factor -> (expr) | id | literal
(6) add_op -> + | -
(7) mult_op -> * | /
Show the stack snapshots, step by step, and the corresponding current token in the
input for parsing the expression 18*a4 + bc , and draw a syntax tree for this expression.
Do lexical analysis first. Do not skip a step, otherwise a penalty will apply. Try to make
your writing and drawing small to fit into the space. You may use an extra page if
needed. Note that normally we have to build a parsing table first before parsing. Since
this grammar is simple enough, we can visually determine what rule to apply for each
snapshot.(25 pts)

Explanation / Answer

The content of stack are as follows

3

3

6

6

6

last 6 is at top

variable a is declared in memory

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote