1 / 8

Compiling Assignments and Expressions

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.

takoda
Download Presentation

Compiling Assignments and Expressions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. The P-Machine 61102 Compilers Software Eng. Dept. – Ort Braude

More Related