Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the first assignment And this is the solution for the first one which I also need help. My professor said that the PairExpList

Here is the first assignment

image text in transcribed

And this is the solution for the first one which I also need help. My professor said that the PairExpList constructor has an Exp as the first argument, not a Stm, so the PrintStm is the problem. Wrap the PrintStm in an EseqExp which extends Exp. But I am not quit understand it.

image text in transcribed

And this is the assignment THAT I NEED HELP WITH!

image text in transcribed

I would be grateful if you could help me with the details. I am really confused about these assignment. And please don't copy other answers to here.

One of the fundamental data structures of a complier is the tree structure. A tree is one of the forms to implement intermediate representations. The assignment is the implementation of an intermediate representation of the straight-line programming language, described by the following grammar. StmStm;Stm(CompoundStm)StmIdExp:=Exp(AssignStm)Stmprint(ExpList)(PrintStm)Expid(IdExp)Expnum(NumExp)ExpExpBinopExp(OpExp)Exp(Stm,Exp)(EseqExp)ExpListExp,ExpList(PairExpList)ExpListExp(LastExpList)Binop(PLus)Binop(Minus)Binop(Times)Binop(Div) The grammar can be translated directly into a tree structure definition, where each grammar symbol corresponds to an abstract class given below. Note that the id is represented as a string and the num is an int. The programs to be analyzed are already parsed into abstract syntax, using the data types specified below. To avoid parsing the language, the program is written using data constructors. For example, the program a:=5+3;b:=(p+int(a,a1),10+a);print(b) can be represented in the above abstract syntax tree and specified as follows: Stm prog = new Compoundstm ( new Assignmstm (new IdExp ("a"), new OpExp (new NumExp (5), OpExp.Plus, new NumExp (3))), new CompoundStm (new Assignstm ( new IdExp ("b"), new EsegExp( new PrintStm( new PairExpList( new IdExp("a"), new LastExpList ( new OpExp ( new IdExp ("a"), OpExp.Minus, new NumExp (1))))), new OpExp (new NumExp (10), OpExp. Times, new IdExp (an)))), new Printstm( new LastExplist( new IdExp("b"))))); This assignment is to implement a tree structure for the intermediate representation of the language. Write the program supporting the inclusion of a tree construction statement like the one given above. Output a trace of class instantiations. Encode the following program and its tree construction. a:=3; b:=a4; e:=(print(b),b+a); d:=(e:=5,(print((print(e),6),(f:=e/7,ef)),8)) To support the simultaneous compilation of multiple programs, avoid the use of static variables, unless they are constants (final). Submit an executable and the source files after a colleague has reviewed your work. 1234567891011121314151617181920212223242526272829303132CompoundStm:AssignStm:aNumExp:3CompoundStm:AssignStm:bIdExp:aNumExp:4OpExp:TimesCompoundStm:AssignStm:cPrintStm:IdExp:bOpExp:PlusIdExp:aCompoundStm:AssignStm:dCompoundStm:AssignStm:eNumExp:5PrintStm:EseqExp:PrintStm:IdExp:eOpExp:MinusAssignStm:fIdExp:eNumExp:7OpExp:DivNumExp:8PrintStm:IdExp:d This assignment builds on the SLP Intermediate Representation Implementation. Functionality is added to the program to support three visitors using the Visitor design pattern. 1. Leaf Node Visitor: This visitor will determine the number of leaf nodes within the tree represtation of the program. The leaf nodes of interest are either a NumExp or I dExp object. Remember that print statements can contain expressions that contain other print statements. For the sample program below, the visitor would report a total of 10 leaf nodes, 4 NumExp objects and 6 IdExp objects. a :=5+3; b:=(print(a,a1),10a); print (b) 2. Symbol Table Visitor: This visitor will build a symbol table of variables appearing in the program. The symbol table will contain the variable's name and its assigned value. Assume all variables are initialized to 0 . The visitor will report the final values of all variables. Assume the representation is in static single assignment form. Remember that EseqExp statements contain both a Stm and an Exp part. The value of the Exp part is what will be assigned if the EseqExp appears in an assignment statement. Exp (Stm,Exp) (EseqExp) public class EseqExp extends Exp \{ public Stm stm; public Exp exp; public EseqExp(Stm s, Exp e) \{stm=s; exp=e; \}\} The sample program above would report final values of " a=8 " and "b =80. 3. Pretty Print Visitor: This visitor will generate a formatted listing of the SLP. The EseqExp may be expanded to several lines as formatted below. Each statement must be on a separate line. Use consistent spacing and indentation. a:=5+3;b:=(print(a,a1),10a);print(b) Use the straight-line program from the previous assignment to demonstrate the correctness of the visitors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions

Question

Explain the difference between permanent and temporary accounts.

Answered: 1 week ago

Question

6. Conclude with the same strength as in the introduction

Answered: 1 week ago

Question

7. Prepare an effective outline

Answered: 1 week ago