




























































































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!





























































































Syllabus
Subject blue print ∙ Basics of compiler (0 marks) o Language Process System, pre-processor, compiler, assembler, loader/linker o Phases and pass in a compiler o Compiler vs interpreter o Symbol table and error handler o Types of error ∙ Lexical Analysis (1-2 marks question, most of the time theoretical question) o Basics, Lexemes, Tokens o Functions of lexical analyser o Lexical analyser implementation ∙ Parsing Techniques (2-3, marks question mostly on numerical one theoretical) o Basics of parsing o CFG grammar, ambiguity, derivation, determinism o Top down parsing, LL (1) o Bottom up parsing, LR (0), SLR (1), CLR (1) and LALR (1) o OPP ∙ Syntax Directed Translation (1-2 basic question) o Basics o Types of attributes o DAG o Types of SDT, S/L attributes ∙ Code Generation and Optimization (1-2 marks theory or numerical) o Basics o 3 address code o Code optimization
High Level Language
Compiler Design
- Analysis Phase: - Converts source code into an intermediate representation (IR). - Focuses on understanding the program's structure and semantics. - Synthesis Phase: - Transforms the intermediate representation into the target program (e.g., assembly or machine code). - Produces executable code equivalent to the original source.
Assembly Language
- Assembly Language Overview: It serves as an intermediate representation between high-level languages and binary machine code. Consists of machine instructions and additional useful data required for execution. - Platform-Specific Nature: Each hardware and operating system (platform) has its unique assembler. Assembly languages are not universal and vary based on the platform. - Assembler Functionality: Translates assembly language into machine code. Produces an output called the object file , which can be executed on the target platform.
BASIS FOR COMPARISON COMPILER INTERPRETER Input It takes an entire program at a time. It takes a single line of code or instruction at a time. Output It generates intermediate object code. It does not produce any intermediate object code. Working mechanism The compilation is done before execution. Compilation and execution take place simultaneously. Speed Comparatively faster Slower Memory Memory requirement is more due to the creation of object code.
It requires less memory as it does not create intermediate object code. Errors Display all errors after compilation, all at the same time.
Displays error of each line one by one.
Error detection Difficult Easier comparatively Code Optimization Code Optimization is possible to a much greater extent
Code Optimization is not very effective
Pertaining Programming languages
C, C++, C#, Scala, typescript uses compiler. PHP, Perl, Python, Ruby uses an interpreter.
Lexical Analyzer
- Purpose of Lexical Analysis: Reads the program and breaks it into lexemes (smallest units of meaningful text). Converts lexemes into tokens , which are predefined structures recognized by the lexical analyzer. - Tokenization: Tokens are categorized using regular expressions. The lexical analyzer identifies and assigns token types like identifiers, operators, and constants.
Float x, y, z; x = y+ z*
X -> token -> identifier = -> token -> operator Y -> token -> identifier
id 1 = id 2 + id 3 * 60
- Role: Responsible for analyzing the structure of the code. Ensures the code adheres to the grammatical rules of the programming language. - Key Features: Constructs a Parse Tree or Syntax Tree to represent the program's grammatical structure. Utilizes Context-Free Grammar (CFG) rules to build the parse tree. - Process: Reads tokens generated by the lexical analyzer, one by one. Verifies the syntax based on predefined production rules.
S -> id = E E -> E + T / T T -> T * F / F F -> id / num id 1 = id 2 + id 3 * 60
- Role: Ensures that the parse tree constructed by the syntax analyzer is meaningful and adheres to semantic rules. - Key Features: Verifies the logical correctness of the parse tree. Checks for semantic errors like type mismatches, undeclared variables, or invalid operations. - Output: Produces a verified or annotated parse tree that includes additional information, such as data types and scope rules, for further processing.
Intermediate Code Generator
- Role: Produces an intermediate code that is simpler than source code and easier for machines to interpret. Acts as a bridge between the front-end (language-dependent) and back-end (platform-dependent) of the compiler. - Characteristics: Intermediate code is platform-independent. Common formats include three-address code (TAC) , among others. - Process Example: For the expression - x = y + z * 60: - t 1 = z * 60 - t 2 = y + t (^1) - x = t (^2) - Advantages: Simplifies the development of new compilers by reusing intermediate code from existing compilers. Final translation to machine code depends on the platform and occurs in the last two compiler phases, making it platform-dependent.
Target Code Generator
- Purpose: Converts intermediate code into machine-understandable code. Handles register allocation and instruction selection to optimize the code for execution. - Characteristics: The output is dependent on the type of assembler and the target machine architecture. This is the final phase of the compilation process.
Symbol Table