Lectures 04 to 06

Lectures 04 to 06 - HLLs Translation and Software...

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

View Full Document Right Arrow Icon
HLLs Translation and Software Simulation (HLL Virtual Machine Interpreters) A) HLLs Translators: i) Compilers : HLL program Scanner (Lexical Analyzer) : (Token Stream) Syntactic Analysis: (Abstract Syntax Parse Tree) Semantic Analysis & intermediate Code generation: (Intermediate code) Optimization Code Generation Machine Code Concepts of Programming Languages , Robert W. Sebesta, 8th Edition
Background image of page 1

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

View Full DocumentRight Arrow Icon
Scanner (lexical-analyzer) : scans the input program statements and extracts its composing tokens, e.g., keywords, ids, … . Example: Y := X + Z * 155; Output tokens: Y, := , X , + , Z , 155 ; Syntax Analyzer (parser): develops an abstract syntax parse tree (AST) detecting syntax errors. Semantic Analyzer: takes the above AST augments it with semantics info and build the symbol table; then checks for semantic consistency (e.g., consistent use of operators and data types). Optimization ( optional ) : optimizes the parsed tree for efficient intermediate code generation. Code Generation: uses the resultant augmented AST with the intermediate code to generate the target machine code which is not directly executable, it still needs to go through the operating system link/load phases. ii) Assemblers : Assembly program: mnemonic code Assembler: target machine code Linker/Loaders : executable machine code The machine code produced by the compiler (or assembler) is not directly executable, all unresolved addresses must be massaged first and all needed external units are to be linked; then the linked code is to be loaded in the memory before execution begins.
Background image of page 2
The Machine instruction cycle (von Neumann) Initialize the program counter Repeat forever Fetch the instruction (^ PC) Increment PC++ Decode the instruction (get all operands, if any) Execute the instruction (store results, if any) End repeat iii) Preprocessors : C++ Preprocessor : C code C Preprocessing to handle directives (“include”), macros (“#define”), and conditional macros (“#if”)
Background image of page 3

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

View Full DocumentRight Arrow Icon
B) Software Simulators (Interpreters): HLL program intermediate (or compiled) code program output Examples: Java (precompiled code), Lisp, ML, Smalltalk, Prolog. I) Pure: (APL, SNOBOL, LISP, PHP, JavaScript ): What? The HLL instructions are treated as if they were low level machine instructions: fetch/decode/execute. Why? Powerful and useful in debugging the program; direct pointers to erroneous HLL statements! Why Not? 1) very Slow! 2) needs large run-time space to store tables and AST Yet, they are back to use as Web Scripting languages! Concepts of Programming Languages , Robert W. Sebesta, 8th Edition
Background image of page 4
II) Hybrid: (Perl, and early Java VM) What? Go with the compilation until the “intermediate” code is generated, then feed it to byte-code interpreter. (compilation of
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

Lectures 04 to 06 - HLLs Translation and Software...

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

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