Question: In Python , create a parser that produces a parse tree composed of nodes, for the following grammar: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Sample BNF Grammar for expressions.

In Python, create a parser that produces a parse tree composed of "nodes", for the following grammar:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Sample BNF Grammar for expressions. Note: this grammar avoids left recursion ;; making it easier to support LL recursive descent parsing. ;; ;; ::- ADD ;; | ;; ;; ::- MULTIPLY ;; | ;; ;; ::- LPAREN RPAREN ;; | NUM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[3 points] Enhance your "node" data type to implement an interpreter that evaluates a parse tree composed of nodes. There is no need to generate code and then interpret the generated code. Your implementation may interpret the logic encapsulated within the parse tree directly. Provide test cases demonstrating this functionality.

[3 points] Enhance your parser to handle subtraction and division. Create suitable "node" instances for subtraction and division. Demonstrate that subtraction and division work with your interpreter.

[3 points] Enhance your parser to allow use of symbolic variables in as well as NUM. Provide and assignment operator that stores the result of an expression to a symbolic variable. Demonstrate that assignment works. Demonstrate that values assigned to variables may be used in other expressions.

[3 points] Enhance your parser to allow "if" and "if else" based conditional code execution. Google it if necessary. Demonstrate that you interpreter conditionally executes code.

[3 points] Enhance your parser to allow "do while" loops that conditionally evaluate expressions as long as a condition variable remains non-zero. Demonstrate that your interpreter correctly executes "do while" loops. Congratulations: You have created a Turing Complete programming language (more or less).

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!