Question: ( python code required ) 2 . Consider the grammar above which is an extension to what we had in class. PROGRAM - > STMTS

(python code required)2. Consider the grammar above which is an extension to what we had in class.
PROGRAM -> STMTS
STMTS -> STMT| STMT ; STMTS
STMT -> id = EXPR
EXPR -> EXPR + TERM | EXPR - TERM | TERM
TERM -> TERM * FACTOR | TERM / FACTOR | FACTOR
FACTOR ->( EXPR )| id | integer
Where{PROGRAM, STMTS, STMT, EXPR, TERM, FACTOR} are non-terminals and { ; ,=,+,-,*,/,(,), id, integer} are terminals. PROGRAM is the start non-terminal, and the terminal id is defined using the regular expression: letter(letter | digit)*.
a) Modify the grammar to add the power operator (^) and unary sign operators +and -.
b) Re-write the grammar such that it can be parsed by an LL(1)parser.
c) Use the written grammar as a base to implement LL(1)parser.
d) Test your code with a correct and incorrect input code.
e) Report (Code of the parser, parsing table, testing the codes, a screenshot of the outputs or GUI if any).

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!