80 likes | 172 Views
Compiling Assignments and Expressions. Lecturer: Esti Stein brd4.ort.org.il/~esti2. Source program. Intermediate-code generator. Intermediate code. Lexical analyzer. Tokens. Intermediate-code optimizer. Syntax analyzer. Optimized Intermediate code. Parse tree. Target-code generator.
E N D
Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2 61102 Compilers Software Eng. Dept. – Ort Braude
Source program Intermediate-code generator Intermediate code Lexical analyzer Tokens Intermediate-code optimizer Syntax analyzer Optimized Intermediate code Parse tree Target-code generator Semantic analyzer Target machine code Abstract syntax tree w. attr. Compilation Phases 61102 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. 61102 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. 61102 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. 61102 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.. 61102 Compilers Software Eng. Dept. – Ort Braude
L-values versus R-values Assignment x := expis 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 ) . 61102 Compilers Software Eng. Dept. – Ort Braude
The P-Machine 61102 Compilers Software Eng. Dept. – Ort Braude