{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Apr24 - CSE302 Compiler Design Instructor Dr Liang Cheng...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University April 24, 2007 Instructor: Dr. Liang Cheng CSE302: Compiler Design 04/24/07 Outline ¡ Recap ¡ Three address code generation ¡ Type checking ¡ Brief introduction to runtime environments ¡ Summary Instructor: Dr. Liang Cheng CSE302: Compiler Design 04/24/07 Translation of Expressions ¡ S → id = E ; ¡ S.code = E.code || gen(top.get(id.lexeme) ‘=’ E.addr) ¡ E → E1 + E2 ¡ E.addr = new Temp() ¡ E.code = E1.code || E2.code || gen(E.addr ‘=’ E1.addr ‘+’ E2.addr) ¡ E →- E1 ¡ E.addr = new Temp() ¡ E.code = E1.code || gen(E.addr ‘=’ ‘minus’ E1.addr) ¡ E → ( E1 ) ¡ E.addr = E1.addr ¡ E.code = E1.code ¡ E → id ¡ E.addr = top.get(id.lexeme) ¡ E.code = ‘’ Instructor: Dr. Liang Cheng CSE302: Compiler Design 04/24/07 SDT of Array Type Declaration ¡ T → B {t = B.type; w = B.width;} C { T.type = C.type; T.width = C.width; } ¡ B → int {B.type = integer; B.width = 4;} ¡ B → float {B.type = float; B.width = 8;} ¡ C → [ num ] C1 { C.type = array( num .value, C1.type); C.width = num .value × C1.width; } ¡ C → ε {C.type = t; C.width = w;} Instructor: Dr. Liang Cheng CSE302: Compiler Design 04/24/07 Translation of Array References ¡ L → id [ E ] ¡ L.array = top.get(id.lexeme) ¡ L.type = L.array.type.elem ¡ L.addr = new Temp() ¡ gen(L.addr ‘=’ E.addr ‘*’ L.type.width) ¡ L → L1 [ E ] ¡ L.array = L1.array ¡ L.type = L1.type.elem ¡ t = new Temp() ¡ L.addr = new Temp() ¡ gen(t ‘=’ E.addr ‘*’ L.type.width ) ¡ gen(L.addr ‘=’ L1.addr ‘+’ t) ¡ S → L = E ; ¡ gen(L.array.base ‘[’ L.addr ‘]’ ‘=’ E.addr ¡ E → L ¡ E.addr = new Temp() ¡ gen(E.addr ‘=’ L.array.base ‘[’ L.addr ‘]’) Instructor: Dr. Liang Cheng CSE302: Compiler Design 04/24/07 Translation of Control Flows and Boolean Expressions ¡ S → if( {B.true=newlabel(); B.false=S.next;} B) S1 {S.code= B.code || label(B.true) || S1.code ¡ if B goto L1 ¡...
View Full Document

{[ snackBarMessage ]}

Page1 / 26

Apr24 - CSE302 Compiler Design Instructor Dr Liang Cheng...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online