Question: CS 415 Compilers: Problem Set 5 Due date: Monday, April 2, 11:59pm Problem - Syntax-Directed Translation Assume the following grammar of a simple, prefix expression

 CS 415 Compilers: Problem Set 5 Due date: Monday, April 2,

11:59pm Problem - Syntax-Directed Translation Assume the following grammar of a simple,

CS 415 Compilers: Problem Set 5 Due date: Monday, April 2, 11:59pm Problem - Syntax-Directed Translation Assume the following grammar of a simple, prefix expression language as introduced in homework 4, problem 3. The goal of this homework problem is to build a recursive descent LL(1) parser that generates ILOC code for this expression language Program ::- Stmtlist . Stmtlist- Stmt NextStmt NextStmtStmtlist I epsilon Stmt :- Assign I Print Assi Print:ID ExprExpr Expr I Expr Expr I Expr Expr I ID I ICONST ID::- alblc ICONST::-1 213 Specify your parser in a pseudo language using the recursive descent parser design pr 1. To generate code, call the pseudo utility function ciples. There are several guidelines you should follow codeGen (InstructionType, opl, op2, op3) For example, the call codeGen (LoadI, 5, reg) generates a loadI instruction that loads the constant 5 into the register with the number "reg", where reg is an integer valued variable. So if reg-- 1, then the call will generate instruction loadI 5ri Similarly, a call codeGen (Add, regl, reg2, reg3) generates an add instruction for the two operand registers "reg1" and "reg2", and the target register "reg3". Again, regl, reg2, and reg3 are integer valued variables 2. Your code generator should not reuse registers as target registers of instructions, so we want to follow the register-register model. You should use another pseudo utility function, namely integer next.register(). A call to this function returns a "fresh" register number that has not been used before. The first call to next register) returns the integer value 1 3. r0 is our base register, and our "standard" r0 based memory layout should be sup- ported. Your compiler should execute codeGen (LoadI, 1024, 0) before any other codeGen call CS 415 Compilers: Problem Set 5 Due date: Monday, April 2, 11:59pm Problem - Syntax-Directed Translation Assume the following grammar of a simple, prefix expression language as introduced in homework 4, problem 3. The goal of this homework problem is to build a recursive descent LL(1) parser that generates ILOC code for this expression language Program ::- Stmtlist . Stmtlist- Stmt NextStmt NextStmtStmtlist I epsilon Stmt :- Assign I Print Assi Print:ID ExprExpr Expr I Expr Expr I Expr Expr I ID I ICONST ID::- alblc ICONST::-1 213 Specify your parser in a pseudo language using the recursive descent parser design pr 1. To generate code, call the pseudo utility function ciples. There are several guidelines you should follow codeGen (InstructionType, opl, op2, op3) For example, the call codeGen (LoadI, 5, reg) generates a loadI instruction that loads the constant 5 into the register with the number "reg", where reg is an integer valued variable. So if reg-- 1, then the call will generate instruction loadI 5ri Similarly, a call codeGen (Add, regl, reg2, reg3) generates an add instruction for the two operand registers "reg1" and "reg2", and the target register "reg3". Again, regl, reg2, and reg3 are integer valued variables 2. Your code generator should not reuse registers as target registers of instructions, so we want to follow the register-register model. You should use another pseudo utility function, namely integer next.register(). A call to this function returns a "fresh" register number that has not been used before. The first call to next register) returns the integer value 1 3. r0 is our base register, and our "standard" r0 based memory layout should be sup- ported. Your compiler should execute codeGen (LoadI, 1024, 0) before any other codeGen call

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!