CSE340Fall2010Project2MoreDetails

CSE340Fall2010Project2MoreDetails - CSE 340 Fall 2010...

Info icon This 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
Image of page 1

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

View Full Document Right 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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern