comp229-slide-4 - Concordia university Department of...

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

View Full Document Right Arrow Icon
Lesson 4 - Compilers 1 Concordia university Department of computer science System software – COMP229 Lesson 4 : Compilers © Author : Kerly Titus
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lesson 4 - Compilers 2 Compilers Contents 1. Principles 3 2. Lexical analysis 14 3. Syntactic analysis 25 4. Code generation 39 5. Compiler design options 58 6. Key points 65 7. References 67
Background image of page 2
Lesson 4 - Compilers 3 1. Principles Introduction Phases of a compiler •G r a m m a r s
Background image of page 3

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

View Full DocumentRight Arrow Icon
Lesson 4 - Compilers 4 Principles Introduction Main functions of a compiler. – Analysis of a source program written in a high-level language. • Application of grammar rules to the language elements. • Detection and report of syntax errors. – Conversion of a source program into a target program. • Source and target programs are in different programming languages. • Target program may be in high-level, assembly, or machine language. Types of compilers. – One-pass, multi-pass, load-and-go, debugging, or optimizing compiler. Compiler construction tools. – Parser generator, scanner generator, syntax-directed translated engine, automatic code generator, data-flow engines.
Background image of page 4
Lesson 4 - Compilers 5 Principles Phases of a compiler Lexical analyzer Syntactic analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol table manager Error handler Source program Target program Preprocessor • Illustration of the phases of a compiler
Background image of page 5

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

View Full DocumentRight Arrow Icon
Lesson 4 - Compilers 6 Principles Phases of a compiler • Symbol table management. – The symbol table stores information on the identifiers. • Name, location, type, and scope of variables. • Number, type, and passing method of arguments for function names. – The symbol table is accessed during each of the phases to insert or to retrieve the attributes of the identifiers. • Error handling. – Each phase reports the errors that are detected. – Most errors are handled during the syntactic and semantic analyses. – Code generation and optimization is performed only if no errors were reported during the analysis phases.
Background image of page 6
Lesson 4 - Compilers 7 Principles Phases of a compiler • Preprocessing. – The preprocessor prepares the source program for the compiler. • Macro processing, file inclusion, symbol definition, etc. • Lexical analysis. – The lexical analyzer (or scanner) reads sequentially the characters in the source program and groups them into tokens. – A token is a sequence of characters that have a collective meaning. • A token can represent an identifier, a keyword, an operator, etc. – The blank spaces found in a token are normally eliminated. – A blank space, a newline character, or a punctuation mark is normally used as token delimiter.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Lesson 4 - Compilers 8 Principles Phases of a compiler • Syntactic analysis.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 67

comp229-slide-4 - Concordia university Department of...

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

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