CS453 Intro and PA1 1CS453 Lecture Introduction and PA1 2CS453 Compiler ConstructionInstructor: Michelle [email protected] 227Office hours: Mon 3-4Lab hours: Wed 3-4, Thurs 1-2URL: http://www.cs.colostate.edu/~cs453Send around sheet to collect email addresses.CS453 Lecture Introduction and PA1 3Plan for Today Scanning/Lexing “Quiz” Motivation– Why study compilers? Programming Assignment Overview– The interpreter and compiler we will be building Logistics of the course– Syllabus– Discussion sectionCS453 Lecture Introduction and PA1 4Scanning/Lexing Quiz class Driver { public static void main ( String [] id ) { System.out.println( boolean && , new int [3], a.length ); } public int [] foo ( ) { } };CS453 Lecture Introduction and PA1 5Structure of a Typical Compiler“sentences”Synthesisoptimizationcode generationtarget languageIRIR code generationIRAnalysischaracter streamlexical analysis“words”tokenssemantic analysissyntactic analysisASTannotated ASTinterpreterCS453 Intro and PA1 2CS453 Lecture Introduction and PA1 6CS453 Lecture Introduction and PA1 7SVG Renderer<svg xmlns="http://www.w3.org/2000/svg"> <!-- rectangles --> <rect x="20" y=" 20" width="300" height="250" fill="red" /> <rect x="30" y="20" width="300" height="250" fill="blue" /> <rect x = "40" y = "20" width = "300" height = "250" fill="green" /> <!-- white circle on top of rectangles --> <circle cx="120" cy="150" r="60" fill="white" /> <!-- black diagonal line --> <line x1="0" y1="0" x2="300" y2="300" stroke="black" /></svg>CS453 Lecture Introduction and PA1 8Structure of the MiniJava Compiler“sentences”SynthesisoptimizationAssem (MIPS)IR code generationAssem (MIPS)Analysischaracter streamlexical analysis“words”tokenssemantic analysissyntactic analysisASTAST and symbol tablecode genMIPSPA3PA4PA5PA6553CS453 Lecture Introduction and PA1 9Specifying Tokens with JFlex Theory meets practice:– Regular expressions, formallanguages, grammars, parsing… JFlex example input file: package mjparser; import java_cup.runtime.Symbol; %% %line %char %cup %public %eofval{ return new Symbol(sym.EOF, newTokenValue("EOF", yyline,yychar)); %eofval} LETTER=[A-Za-z] DIGIT=[0-9] UNDERSCORE="_" LETT_DIG_UND={LETTER}|{DIGIT}|{UNDERSCORE} ID={LETTER}({LETT_DIG_UND})* %% "&&" { return new Symbol(sym.AND, newTokenValue(yytext(), yyline, yychar)); } "boolean" {return newSymbol(sym.BOOLEAN,... {ID} { return new Symbol(sym.ID, new
View Full Document