



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




David Notkin Autumn 2008 Source Program [Higher-Level Programming Language] Compiler Target Program [Lower-Level Language/ Architecture] CSE
CSE401 Au08 3
Source Program (^) scan; Analyze: parse Representation^ Intermediate t 6 : = Fa c. Co mp u t e Fa c ( t h i s , t 3 ) ; Scan (lexical analysis) Token Stream Character Stream 28 characters not counting whitespace name=t6,assign,name=Fac,period, name=ComputeFac,lparen,name=this, comma,name=t3,rparen,semicolon (11 tokens) CSE401 Au08 13
name=^ name=t6,assign,name=ComputeFac,lparen,nameFac,period=this,, comma,name=t3,rparen,semicolon Assignment statement Lefthand side Identifier: t Righthand side invocation^ Method Method name QualifiedName Identifier: Fac Identifer ComputeFac: Parameter List Identifier: this Identifier: t Analyze: scan; parse Abstract syntax tree CSE401 Au08 14 statement^ Assign⦠Lefthand side Identifier : t Righthand side invocation^ Method Method name Qualified⦠Identifier: Fac Identifer ComputeFac: Parameter List Identifier: this Identifier : t
CSE401 Au08 15
Target Program Generate (back end) Annotated abstract syntax tree Intermediate Language Intermediate code generation Annotated abstract syntax tree Target code generation Target Program CSE401 Au08 16
CSE401 Au08 19
Sample (extended) MiniJava program: Factorial.java // Computes 10! and prints it out class Factorial { public static void main(String[] a) { System.out.println( new Fac().ComputeFac(10)); } } class Fac { // the recursive helper function public int ComputeFac(int num) { int numAux; if (num < 1) numAux = 1; else numAux = num * this.ComputeFac(num-1); return numAux; } } CSE401 Au08 25 Example: intermediate representation Int Fac.ComputeFac(? this, int num) { int t1, numAux, t8, t3, t7, t2, t6, t0; t0 := 1; t1 := num < t0; ifnonzero t1 goto L0; t2 := 1; t3 := num - t2; t6 := Fac.ComputeFac(this, t3); t7 := num * t6; numAux := t7; goto L2; label L0; t8 := 1; numAux := t label L2; return numAux }* CSE401 Au08 26
CSE401 Au08 27