Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I would be really thankful if you could help me out with the details. I am really confused about this assignment. And please don't copy

image text in transcribed

image text in transcribed

I would be really thankful if you could help me out with the details. I am really confused about this 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:= (print (a,a1),10a); 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 EseqExp ( 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("a")))), 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 c:=( 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

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions