CMPE 152: Compiler Design September 11/13 Lab

Slides:



Advertisements
Similar presentations
CS 153: Concepts of Compiler Design October 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Advertisements

CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 153: Concepts of Compiler Design August 24 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
CS 235: User Interface Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 14 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 152: Programming Language Paradigms April 2 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CS 153: Concepts of Compiler Design August 26 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CMPE 226 Database Systems October 7 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design October 10 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Recursive Descent Parsers Lecture 6 Mon, Feb 2, 2004.
CS 153: Concepts of Compiler Design September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
CSC 4181 Compiler Construction
CS 153: Concepts of Compiler Design October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 14 Class Meeting
CS 153: Concepts of Compiler Design August 24 Class Meeting
CS 153: Concepts of Compiler Design August 29 Class Meeting
CS 153: Concepts of Compiler Design October 17 Class Meeting
CS 153: Concepts of Compiler Design October 5 Class Meeting
CS 153: Concepts of Compiler Design October 3 Class Meeting
CS 153: Concepts of Compiler Design November 30 Class Meeting
CMPE 152: Compiler Design December 5 Class Meeting
CMPE 152: Compiler Design January 25 Class Meeting
CMPE 152: Compiler Design ANTLR 4 and C++
CMPE 152: Compiler Design September 25 Class Meeting
CMPE 152: Compiler Design September 4 Class Meeting
CMPE 152: Compiler Design September 6 Class Meeting
CMPE 152: Compiler Design September 11 Class Meeting
CMPE 152: Compiler Design September 18 Class Meeting
CMPE 152: Compiler Design September 13 Class Meeting
CMPE 152: Compiler Design October 2 Class Meeting
CMPE 152: Compiler Design October 4 Class Meeting
CMPE 152: Compiler Design October 4 Class Meeting
CMPE 152: Compiler Design August 23 Class Meeting
CMPE 152: Compiler Design August 21/23 Lab
CMPE 152: Compiler Design December 6 Class Meeting
CMPE 152: Compiler Design September 27 Class Meeting
CMPE 152: Compiler Design August 28/30 Lab
CS 153: Concepts of Compiler Design November 6 Class Meeting
CMPE 152: Compiler Design February 14 Class Meeting
CMPE 152: Compiler Design February 28 Class Meeting
CMPE 152: Compiler Design March 7 Class Meeting
CMPE 152: Compiler Design April 9 Class Meeting
CMPE 152: Compiler Design January 29 Class Meeting
CMPE 152: Compiler Design February 12 Class Meeting
CMPE 152: Compiler Design February 7 Class Meeting
CMPE 152: Compiler Design February 21/26 Lab
CMPE 152: Compiler Design February 28 / March 5 Lab
CMPE 152: Compiler Design March 26 – April 16 Labs
CS 144 Advanced C++ Programming January 31 Class Meeting
CMPE 152: Compiler Design February 21 Class Meeting
CMPE 152: Compiler Design February 19 Class Meeting
CMPE 152: Compiler Design March 7 Class Meeting
CMPE 152: Compiler Design April 18 – 30 Labs
CMPE 152: Compiler Design March 5 Class Meeting
CMPE 152: Compiler Design April 16 Class Meeting
CMPE 152: Compiler Design December 4 Class Meeting
CMPE 152: Compiler Design March 7/12 Lab
CMPE 152: Compiler Design September 3 Class Meeting
CMPE 152: Compiler Design August 27 Class Meeting
CMPE 152: Compiler Design September 17 Class Meeting
CMPE 152: Compiler Design February 7 Class Meeting
CMPE 152: Compiler Design September 26 Class Meeting
CMPE 152: Compiler Design September 19 Class Meeting
Presentation transcript:

CMPE 152: Compiler Design September 11/13 Lab Department of Computer Engineering San Jose State University Fall 2018 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Today’s Lab Work on Assignment #3: WHEN statement. Modify the Chapter 8 source code to parse and execute a new statement added to Pascal.

Assignment #3: WHEN Statement Add a new WHEN statement to Pascal! Example: Semantically similar to: WHEN i = 1 => f := 10; i = 2 => f := 20; i = 3 => f := 30; i = 4 => f := 40; OTHERWISE => f := -1 END IF i = 1 THEN f := 10 ELSE IF i = 2 THEN f := 20 ELSE IF i = 3 THEN t := 30 ELSE IF i = 4 THEN f := 40 ELSE f := -1;

Assignment #3, cont’d Draw a syntax diagram to describe the grammar of the WHEN statement. Start with Chapter 8’s source code. Do the work in two stages: Modify the frontend parser to parse the WHEN statement and build an appropriate parse tree. Modify the backend executor to execute the parse tree.

Assignment #3, cont’d Modify and add files, roughly in this order: Stage 1 PascalToken.h PascalToken.cpp PascalSpecialSymbolToken.cpp ICodeNodeImpl.h ICodeNodeImpl.cpp WhenStatementParser.h WhenStatementParser.cpp StatementParser.cpp Stage 2 WhenExecutor.h WhenExecutor.cpp StatementExecutor.cpp

Assignment #3, cont’d Parse and execute file when.txt: BEGIN i := 3;          WHEN         i = 1 => f := 10;         i = 2 => f := 20;         i = 3 => f := 30;         i = 4 => f := 40;         OTHERWISE => f := -1     END;     range := 5.7;         (1.0 <= range) AND (range < 3.0) => level := 1;         (4.5 <= range) AND (range < 7.5) => BEGIN                                                level := 2;                                                alpha := range;                                            END;         (8.0 <= range) AND (range < 9.9) => level := 3;         OTHERWISE => level := -1 END.  

Assignment #3, cont’d Flag and recover from syntax errors in file whenerrors.txt: Due Friday, September 28. BEGIN WHEN i := 3 => k > 5; m = n : m := 2*n; END; END.