Presentation is loading. Please wait.

Presentation is loading. Please wait.

Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2.

Similar presentations


Presentation on theme: "Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2."— Presentation transcript:

1 Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2

2 Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude Compilation Phases Source program Tokens Parse tree Abstract syntax tree w. attr. Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code Optimized Intermediate code Target machine code Intermediate-code generator Intermediate-code optimizer Target-code generator

3 Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude The Languages Source language – thinned down version of Pascal. Target computer – abstract machine, the P machine. –The architecture was designed to make compiling Pascal into its machine language.

4 Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude Language Constructs & Compilation Variables – containers for data objects –Contents may be change during the execution. –The set of values of the variables at any given time form a part of the state of the program. –Identifier: variable, constant, procedure, etc. –Variables are assign memory locations. –Recursion assign new incarnations of the var. thus using stack-like memory management.

5 Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude Language Constructs & Compilation Expressions – terms formed from constants, names & operators which are evaluated during execution. –Their value is generally state dependent.

6 Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude Language Constructs & Compilation Control flow: –goto: directly compiled into unconditional branch instruction. –Conditional (if) or iterative (while, for..) statement are compiled into conditional branches. –Procedures: branch instructions that does not forget its origin, actual parameters, etc..

7 Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude L-values versus R-values Assignment x := exp is compiled into: Compute the address of x ; Compute the value of exp. Store the value of exp at the address of x. R-value: r-val( x ) = value of x. r-val( 5 ) = 5. r-val( x+y ) = r-val( x ) + r-val( y ). L-value: l-val( x ) = address of x. l-val( 5 ) = undefined. l-val( x+y ) = undefined. l-val( a[i] ) = l-val( a ) + some function of r-val( i ).

8 Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude The P-Machine


Download ppt "Winter 2006-761102 Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2."

Similar presentations


Ads by Google