CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm [email protected]...
-
Upload
geoffrey-moore -
Category
Documents
-
view
214 -
download
2
Transcript of CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm [email protected]...
![Page 1: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/1.jpg)
CS453 Lecture Introduction 1
CS453 Compiler Construction
Instructor: Wim Bohm
Computer Science Building 470
TA: tba
URL: http://www.cs.colostate.edu/~cs453
![Page 2: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/2.jpg)
Course Logistics (Highlights, see web page for more detail)Schedule Page and Home/News
Read both of these daily. Lots of reading in the first couple of weeks.
Resources Page
Syllabus and Grading
Professional Conduct
Do your own work.
Act like a professional in the lab.
Participate
Come to class and recitation.
Ask questions and post answers on the RamCT discussion board.
CS453 Lecture Introduction 2
![Page 3: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/3.jpg)
CS453 Lecture Introduction 3
Plan for Today
Course Logistics (done)
Interpreter and Compiler Structure, or Software Architecture
A scanner/parser/interpreter for a simple expression language What is the difference between a compiler and an interpreter?
Compilers class and reality– Why study compilers?
Overview of Programming Assignments– The MeggyJava compiler we will be building.
![Page 4: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/4.jpg)
CS453 Lecture Introduction 4
Structure of a Typical Compiler
“sentences”
Synthesis
optimization
code generation
target language
IR
IR code generation
IR
Analysis
character stream
lexical analysis
“words”tokens
semantic analysis
syntactic analysis
AST
annotated AST
interpreter
![Page 5: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/5.jpg)
Expression Language: tokens
Tokens: keyword(s): “print” operators/delimiters: “+”, ”-”, “*”, “;” integer literals: “0”, “1”, “2” ,…,”10”, “11”, … , “100”, …
Symbols (Tokens+optional value) are formed by a scanner performing lexical analysis, while reading from a character stream eg: PRINT token+null, SEMI token+null, NUMBER token + Integer-value
Valid tokens are defined by regular expressions, e.g.:
NUMBER: [0-9]+ CS453 Lecture Introduction 5
![Page 6: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/6.jpg)
CS453 Lecture Introduction 6
Simple example: Expression Interpreter
character stream (print 2+3*4; …)
lexical analysis
tokens
syntactic analysisplus
calls to evaluate andprint
scanner
parser plusinterpreter
text (14, …)
![Page 7: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/7.jpg)
Expression Language: sentences
Sentences: Program sentences (statements here) are recognized by a parser.
Valid programs are defined by a Grammar:
Program::= stmts
stmts::= stmts stmt | <empty>
stmt::= PRINT exp SEMI
exp::= exp + exp | exp – exp | exp * exp | NUMBER
In our case, the parser evaluates the expressions and prints their
values, i.e. the parser interprets the language
In this week’s recitation you will be exercising with this language, and use tools to generate a scanner and a parser / interpreter
CS453 Lecture Introduction 7
![Page 8: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/8.jpg)
Why Compilers?
CS453 Lecture Introduction 8
![Page 9: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/9.jpg)
A LOT OF CONCEPTS, TOOLS, and CODE
Compilers are large and complex software structures In this course you will learn a lot of concepts Regular and Context Free grammars, visitor pattern, architecture In this course you will use A LOT of tools Scanner generators and Parser Generators (recitation this week) Eclipse + version control Makefiles jar files assemblers (Meggy) hardware In this course you will write a lot of code 1000s of lines
Don’t get behind! It will be hard, if not impossible, to catch up.
CS453 Lecture Introduction 9
![Page 10: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/10.jpg)
CS453 Lecture Introduction 10
Example MeggyJava program
MeggyJava: a Java subset for the Meggy toy we are playing with in this course. Example code:
import meggy.Meggy;
class PA3Flower {public static void main(String[] whatever){
{ // Upper left petal, clockwise Meggy.setPixel( (byte)1, (byte)1, Meggy.Color.WHITE ); Meggy.setPixel( (byte)2, (byte)1, Meggy.Color.WHITE ); … }}
![Page 11: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/11.jpg)
CS453 Lecture Introduction 11
Structure of the MeggyJava Compiler
“sentences”
SynthesisAnalysis
character stream
lexical analysis
“words”tokens
semantic analysis
syntactic analysis
AST
AST and symbol table
code gen
Atmel assembly code
PA1: Write test cases in C++ and MeggyJava, and Atmel warmupPA2: MeggyJava scanner and setPixelPA3: add exps and control flow (AST)PA4: add methods (symbol table)PA5: add variables and objects
![Page 12: CS453 LectureIntroduction1 CS453 Compiler Construction Instructor:Wim Bohm bohm@cs.colostate.edu Computer Science Building 470 TA: tba tba@cs.colostate.edu.](https://reader036.fdocuments.us/reader036/viewer/2022083005/56649f0e5503460f94c22bb3/html5/thumbnails/12.jpg)
Before Next Time
See schedule.
Read all the pages of the website.
Make sure you can ssh into CS linux machines.
CS453 Lecture Introduction 12