Question: *NOTE THAT THE SOURCE CODE IS NOT PROVIDED, BUT CAN BE. PLEASE HELP* A. Add the new token to X: ';' a semicolon B. Modify

*NOTE THAT THE SOURCE CODE IS NOT PROVIDED, BUT CAN BE. PLEASE HELP*

A. Add the new token to X: ';' a semicolon B. Modify the Parser according to the notes below:

Parse the new rules specified in the modified grammar and build the indicated AST's

PROGRAM -> 'program' BLOCK ==> program BLOCK -> '{' D* S* } ==> block D -> TYPE NAME ==> decl -> TYPE NAME FUNHEAD BLOCK ==> functionDecl TYPE -> 'int' -> 'boolean' -> 'float' <-------------NEW RULE -> 'void' <-------------NEW RULE FUNHEAD -> '(' (D list ',')? ')' ==> formals S -> 'if' E 'then' BLOCK 'else' BLOCK ==> if -> 'while' E BLOCK ==> while -> 'return' E ==> return -> 'return' ';' ==> return <-------------NEW RULE -> BLOCK -> NAME '=' E ==> assign -> NAME '(' (E list ',')? ')' ==> call <-------------NEW RULE E -> SE -> SE '==' SE ==> = -> SE '!=' SE ==> != -> SE '<' SE ==> < -> SE '<=' SE ==> <= -> SE '>' SE ==> > <-------------NEW RULE SE -> T -> SE '+' T ==> + -> SE '-' T ==> - -> SE '|' T ==> or T -> F -> T '*' F ==> * -> T '/' F ==> / -> T '&' F ==> and

F -> '(' E ')' -> NAME -> -> NAME '(' (E list ',')? ')' ==> call NAME ->

REMOVE ALL DEBUG statements not required The output for the simple.x program should be the following (note that the token printout is no longer included):

1. program { int i int j 2. i = i + j + 7 3. j = write(i) 4. }

---------------AST------------- 1: Program 2: Block 5: Decl 3: IntType 4: Id: i 8: Decl 6: IntType 7: Id: j 10: Assign 9: Id: i 14: AddOp: + 12: AddOp: + 11: Id: i 13: Id: j 15: Int: 7 17: Assign 16: Id: j 19: Call 18: Id: write 20: Id: i

-----------------------------------------------------------------

Since you will not be using constrainer or codegen you must: 1. Comment out the code, as indicated in the Compiler.java class. 2. Comment out the constrainer/codegen import statements in Compiler.java 3. When you build a project DO NOT include constrainer/codegen files

REMOVE ALL DEBUG statements not required. YOU MUST follow these directions to avoid losing points.

Q. What should the Parser output look like? Following demonstrates a test case (note that the token printout is no longer included):

1. program { int i 2. factorial(20) 3. }

---------------AST-------------

1:Program 2: Block 3: Decl 4: IntType 5: Id: i 8: Call 6: Id: factorial 7: Int: 20 Note: The numbers attached to nodes are arbitrary so don't worry about your numbering matching mine. The only constraint is that each node has a unique number.

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!