====== Selected Phases of a Compiler ====== ++++source code| int i = 0; /* some comment */ int j = 0; while (i < 10) { System.out.println(j); i = i + 1; j = j + 2*i+1; } ++++ ^ [[Lecture 01|Lexer]] ^ ++++list of tokens| INT, Identifier("i"), EQUAL, IntNumeral(0), SEMICOLON, INT, Identifier("j"), EQUAL, ... WHILE, OPENPAREN, Identifier("i"), LESSTHAN, IntNumeral(10), CLOSEDPAREN, OPENBRACE, Identifier("System"), DOT, Identifier("out"), ... ++++ ^ [[Lecture 03|Parser]] ^ ++++concrete syntax tree| Declaration(INT, Identifier("i"), EQUAL, InitialExpression(IntConst(IntNumeral(0)), Declaration(INT, Identifier("j"), EQUAL, InitialExpression(IntConst(IntNumeral(0)), WhileStatememt(WHILE, OPENPAREN, LessThanExpr(Identifier("i"),LESSTHAN,IntNumeral(10)), CLOSEDPAREN, StatementBlock(OPENBRACE, Statement(MethodCall(DotExpr(Identifier("System"),DOT,Identifier("out")),DOT, Identifier("println"), OPENPAREN,ArgumentList(Identifier("j")),CLOSEDPAREN), SEMICOLON, ... ) ) ) ) ++++ ^ [[Lecture 04|Abstract Syntax Tree Construction]] ^ ++++abstract syntax tree| Declaration("i",IntType,Some(IntConst(0)), Declaration("j",IntType,Some(IntConst(0)), WhileStatememt(LessThan(Ident("i"),IntConst(10)), StatementBlock( MethodCall(DotExpr(Ident("System"),"out"), "println", List(Ident("j"))), Assignment("i", Plus(Ident("i"),IntConst(1))), Assignment("j", Plus(Ident("j"), Times(IntConst(2),Ident("i"), IntConst(1)) ) ) ) ) ++++ ^ [[Lecture 06|Semantic Analysis and Type Checking]] ^ ++++resolved tree and symbol table| Declaration("i",IntType,Some(IntConst(0)), Declaration("j",IntType,Some(IntConst(0)), WhileStatememt(LessThan(Ident("i"),IntConst(10)), StatementBlock( MethodCall(DotExpr(Ident("System"),"out"), "println", List(Ident("j"))), Assignment("i", TYPE(Plus(TYPE(Ident("i"),INT),IntConst(1))),INT), Assignment("j", TYPE(Plus(TYPE(Ident("j"),INT), TYPE(Times(IntConst(2),TYPE(Ident("i"),INT),INT), TYPE(IntConst(1),INT)),INT) ) ) ) ) i -> (LocalVar,INT) j -> (LocalVar,INT) ++++ ^ [[Intermediate Code Generation]] ^ ++++source- and taget-independent format| control-flow graph containing three-address code instructions ---- {{cc09:cfg.png|CFG?640}} ---- ++++ ^ [[Lecture 08|Target Code Generation]] ^ ++++translated program| [[test.jvm]] ++++