CS453 Intro and PA1 1CS453 Lecture NFAs and DFAs 1Prelude Other uses of compiler technology– Used in CS410 to parse graphics model– Used frequently throughout career to embed languages withinapplications– domain-specific XML Notice also that ...– JLex is also a compiler– I wonder how it parses its input? Did it use a parser generator?CS453 Lecture NFAs and DFAs 2Plan for Today Previously ...– Tokens can be expressed to the lexer generator JLex as regular expressions How do lexer generators work?– Convert regular expressions to NFA– Converting an NFA to DFA– Implementing the DFACS453 Lecture NFAs and DFAs 3Structure of the MiniJava Compiler“sentences”SynthesisoptimizationAssem (MIPS)IR code generationAssem (MIPS)Analysischaracter streamlexical analysis“words”tokenssemantic analysissyntactic analysisASTAST and symbol tablecode genMIPSPA3PA4PA5PA6553CS453 Lecture NFAs and DFAs 4Specifying Tokens with JFlex 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 ...CS453 Intro and PA1 2CS453 Lecture NFAs and DFAs 5Example NFA for Multiple TokensCS453 Lecture NFAs and DFAs 6DFA from IF and ID
View Full Document