Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Extend the grammar of Figure 2.25 to include if statements and while loops, along the lines suggested by the following examples: abs := n if
Extend the grammar of Figure 2.25 to include if statements and while loops, along the lines suggested by the following examples:
abs := n if n 0 do read n sum := sum + n count := count - 1 od write sum
Q) Your grammar should support the six standard comparison operations in conditions, with arbitrary expressions as operands. It should also allow an arbitrary number of statements in the body of an if or while statement.
1. program stmt_list $$ 2. stmt_list + stmt_list stmt 3. stmt list stmt 4. stmt - id := expr 5. stmt + read id stmt + write expr expr + term 8. expr + expr add op term 9. term + factor 10. term + term mult_op factor 11. factor + ( expr ) 12. factor id 13. factor + number 14. add_op + + 15. add-op +- 16. mult_op * 17. mult_op 1 Figure 2.25 LR(1) grammar for the calculator language. Productions have been numbered for reference in future figuresStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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