











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












CSC373-Compiler Construction Week-3 Lecture- Semester-#5 Fall 2019 Prepared by: Eisha Tir Razia Lahore Garrison University
(^) Compilation Process in brief (^) How a source program gets compiled? (^) Phases of Compiler
(^) Understanding related (^) Symbol table
Some commonly used compiler-construction tools include: (^) Scanner generators that produce lexical analyzers from a regular- expression description of the tokens of a language. (^) Parser generators that automatically produce syntax analyzers from a grammatical description of a programming language. (^) Syntax-directed translation engines that produce collections of routines for walking a parse tree and generating intermediate code. (^) Code-generator generators that produce a code generator from a collection of rules for translating each operation of the intermediate language into the machine language for a target machine.
(^) It is a memory that is constructed in our language. Symbol table is implemented by # table.
(^) An essential function of a compiler is to record the variable names used in the source program and collect information about the various attributes of each name. (^) A symbol table is a data structure containing all the identifies (name of variables, procedures etc.) of a source program together with all the attributes of each identifier. (^) The symbol table stores information about the entire source program, is used by all phases of the compiler.
(^) To store the names of all entities in a structured form at one place. (^) Provide quick and uniform access to identifier attributes throughout the compiler process (^) To verify if a variable has been declared. (^) To implement type checking, by verifying assignments and expressions in the source code are semantically correct. (^) To determine the scope of a name (scope resolution)
(^) Virtually every phase of the compiler will use the symbol table. (^) Initialization phase will place keywords, operators, and standard identifiers in it. (^) Scanner will place user-defined identifiers and literals in it and will return the corresponding token. (^) The parser uses these token to create the phase tree, the product of the syntactic analysis of the program. (^) The semantic action routines place data type in its entries and uses this information in performing basic type checking. (^) The intermediate code generation phase use pointers to entries in symbol table in creating the intermediate representation of the program. (^) The object code generation phase uses pointers to entries in the symbol table in allocating storage of its variables and constants, as well as to store the addresses of its procedures and functions.
(^) Next, the scanner assembles the lexeme (^) The Symbol Table manager can’t find it when it looks it up. Therefore, it installs the main in the Symbol Table with the token identifier. During semantic analysis, it will be given the semantic property of int. ‘m’ ‘a’ ‘i’ ‘n’
(^) Let’s take a look at the kinds of information stored in the symbol table for different types of elements within a program Lexem e Token Class Symbol Type Data Type Value Scope while TokWhile Keyword None 0 Global
(^) Deleting symbols When the compiler is finished with a given scope of the program, all the symbols belonging to that scope must be effectively removed before beginning to process a different scope of the program. (^) The data regarding these variables may be hidden from the compiler’s view or dumped into a temporary file. (^) Searching for symbols Looking up a lexeme in the symbol table and retrieving any and all of the properties belonging to that symbol
(^) One-pass Compiler (^) Two-pass Compiler
(^) These lecture notes were taken from following source: (^) Compilers: Principles, Techniques, and Tools By Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman, Contributor Jeffrey D. Ullman, Addison- Wesley Pub. Co., 2nd edition, 2006