CS453 Intro and PA1 1CS453 Lecture Midterm review 1Structure of the MiniJava Compiler“sentences”SynthesisoptimizationAssem (MIPS)IR code generationAssem (MIPS)Analysischaracter streamlexical analysis“words”tokenssemantic analysissyntactic analysisASTAST and symbol tablecode genMIPSPA3PA4PA5PA6553CS453 Lecture Midterm review 2Plan for Today Studying for the midterm– review all slides and notes taken in class– do suggested exercises– redo any examples we did in class– reread assigned reading– the midterm WILL NOT have anything about MIPS Lexical Analysis, or scanning Syntactic Analysis, or parsingCS453 Lecture Midterm review 3Lexical Analysis, or scanning Terminology– regular expressions– tokens– DFA– NFA– longest match and priority Techniques– creating a scanner for a set of tokensCS453 Lecture Midterm review 4Syntactic Analysis, or parsing Terminology– context-free grammars, terminal, non-terminal, symbol, derivation– syntax-directed translation, actions, attributes– LR(0) versus LR(1) grammars– parse trees versus abstract syntax trees– ambiguity– LL(k) and left recursion– top-down and bottom-up parsing– precedence and associativity– pre- and post-order depth-first traversals– error handlingCS453 Intro and PA1 2CS453 Lecture Midterm review 5Syntactic Analysis, or parsing cont... Techniques– rewrite a grammar so that it is LL(1)– calculate FIRST and FOLLOW sets– write a predictive parser with panic mode error handling– disambiguate expression and list grammars– create an LR(0) or LR(1) parse table– parse a string of tokens with an LR parse tableCS453 Lecture Midterm review 6Grammar HierarchyCS453 Lecture Midterm review 7Predictive parser for Float Assignment Grammarvoid S() { switch (lookahead) { case ID: case EOF:// the 2 characters in the FIRST(StmList EOF)try { StmList(); match(EOF); } catch { panic(S); } break; default: panic(S); break;}}void StmList() { switch (lookahead) { case ID: // FIRST( Stm StmList ) = { ID } try { Stm(); StmList(); } catch { panic(StmList) } break; case EOF: // FOLLOW(StmList) = { EOF } break; default: panic(StmList); break;}}void Stm() { switch (lookahead) { case ID: try { match(ID); match(ASSIGN); match(FLOAT); } catch { panic(Stm); } break; default: panic(Stm); break;}}CS453 Lecture Midterm review 8Example LR Parse Table(1) S -> S ( S )(2) S ->
View Full Document