CSE340Fall2010Project2MoreDetails

- CSE 340 Fall 2010 Project 2 Assigned Due LAST DAY of CLASSES Abstract The goal of this project is to give you some hands-on experience with

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 340 - Fall 2010 Project 2 Assigned November 14, 2010 - Due LAST DAY of CLASSES Abstract The goal of this project is to give you some hands-on experience with implementing a compiler. You will write a compiler for a simple language and the generated code will be an intermediate representation. The exe- cution of the program will be done after compilation by interpreting the generated intermediate representation. 1 GRAMMAR The grammar for this project is a greatly simplified form of the grammar of project 1 with a couple extensions. Program 7→ BEGIN Var Statement END id list 7→ id , id list | id id 7→ char ( char | digit ) * char 7→ a | b | ... | z | A | B | ... | Z Var 7→ VAR var decl var decl 7→ id list : int ; Statement 7→ ASSIGN stmt list stmt list 7→ stmt stmt list | stmt stmt 7→ id = expr | while | if | print expr 7→ id op id ; | id ; | integer literal ; op 7→ + | - | * | / integer literal 7→ digit integer literal | digit digit 7→ 0 | 1 | 2 | ... | 9 print 7→ print id while 7→ WHILE ( condition ) DO stmt list END if 7→ IF ( condition ) THEN stmt list END condition 7→ id > id | id <> id Some highlights of the grammar: 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1. assignment is renamed as stmt (statement) which more accurately captures its meaning. I kept the ASSIGN heading to keep it simpler. 2. There is only one type: int . 3. There are no user defined types or a type section. 4. There are no nested blocks. All variables are declared in the global pro- gram scope. 5. Division is integer division and the result of the division of two integers is an integer. 6. while statements are introduced. 7. if statement are introduced. 8. A boolean condition is introduced to control the execution of the while statement. 9. The comparison operators > (less than) and <> (not equal) are introduced and used in conditions. 10. A print statement is introduced 11. There is no variable declaration list. There is only one id list in the global scope scope and that contains all the variables. 2 Boolean Condition A boolean condition takes two operands as parameters and returns a boolean value. It is used to control the execution of while statements. 3 Execution Semantics All statements in a statement list are executed sequentially according to the order in which they appear. Exception is made for body of WHILE as explained below. 4
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2011 for the course CSE 340 taught by Professor Farley,t during the Fall '08 term at ASU.

Page1 / 9

- CSE 340 Fall 2010 Project 2 Assigned Due LAST DAY of CLASSES Abstract The goal of this project is to give you some hands-on experience with

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online