Question: The final programming assignment will create a recursive descent parser for a little language polynomials, and will implement an interpreter for the language. There will
The final programming assignment will create a recursive descent parser for a little language polynomials, and will implement an interpreter for the language. There will be three weeks of deliverables for the assignment Monday April 17, April 24, and May 1. You will be given code segments in class that you can incorporate into your programs. The grammar for our language is as follows: Prog:= Stmt | Stmt Prog Stmt:= Set ID Expr SC | PRINT Expr SC Expr:* Term {(*|-) Expr} Term:= Primary {* Primary) Primary:= ICONST | FCONST | STRING | (Expr) | Poly Poly:= LCURLY Coeffs RCURLY {EvalAt) | ID {EvalAt) Coeffs:= Coeff {. Coeff} Coeff:= ICONST | FCONST EvalAt:=LSQ Expr RSQ Note that there are 9 rules so there may be 9 functions, one per rule: you may decide that you want to combine some rules together for ease of implementation. Some examples: set f{1, 2, 4}; # f is x^2 + 2x + 4 print f[0]; # should print 4 set f{2, 0, 0, 1}: # 2x^3 + 1 set g {1, 0, 0}; # x^2 set x 2: set gofx g[x]: ## should be 4 (2^2) set fofgofx f[gofx]: ### should be 129 print {1, 1, 1, 1)[2]: ## should print 2^3 + 2^2 + 2 + 1 or 15 print {1.1, 1)*2; ## should print {2, 2, 2} print 3 + 4*5; ## should print 23 The final programming assignment will create a recursive descent parser for a little language polynomials, and will implement an interpreter for the language. There will be three weeks of deliverables for the assignment Monday April 17, April 24, and May 1. You will be given code segments in class that you can incorporate into your programs. The grammar for our language is as follows: Prog:= Stmt | Stmt Prog Stmt:= Set ID Expr SC | PRINT Expr SC Expr:* Term {(*|-) Expr} Term:= Primary {* Primary) Primary:= ICONST | FCONST | STRING | (Expr) | Poly Poly:= LCURLY Coeffs RCURLY {EvalAt) | ID {EvalAt) Coeffs:= Coeff {. Coeff} Coeff:= ICONST | FCONST EvalAt:=LSQ Expr RSQ Note that there are 9 rules so there may be 9 functions, one per rule: you may decide that you want to combine some rules together for ease of implementation. Some examples: set f{1, 2, 4}; # f is x^2 + 2x + 4 print f[0]; # should print 4 set f{2, 0, 0, 1}: # 2x^3 + 1 set g {1, 0, 0}; # x^2 set x 2: set gofx g[x]: ## should be 4 (2^2) set fofgofx f[gofx]: ### should be 129 print {1, 1, 1, 1)[2]: ## should print 2^3 + 2^2 + 2 + 1 or 15 print {1.1, 1)*2; ## should print {2, 2, 2} print 3 + 4*5; ## should print 23
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
