Zero Lecture

Course Objectives

The course of Compiler design has prerequisites: Data Structures, Algorithms, Computer Architecture, Discrete Mathematical structures, Operating systems, and Theory of Computation.

The objective the compiler course is to understand the basic principles of compiler design, its various constituent parts, algorithms and data structures required to be used in the compiler.

Yet, other objective is, to understand relations between computer architecture and how its understanding is useful in design of a compiler.

The other objective is, how to construct efficient algorithms for compilers.


Course Outcomes

  • The outcome of this course is to acquire basic skills for designing the compilers, as well as the knowledge of compiler design. After this course a student will know, in some depth, how a compiler works.
  • In particular, he/she should understand the structure of a compiler, and how the source and target languages influence various choices in its design.
  • It will give you a new appreciation for programming language features and the implementation challenges they pose, as well as for the actual hardware architecture and the run-time system in which your generated code executes.
  • Understanding the details of typical compilation models will also make you a more distinct programmer.
  • You will also understand some specific components of compiler technology, such as lexical analysis, grammars and parsing, type-checking, intermediate representations, static analysis,common optimizations, instruction selection, register allocation, code generation, and run-time organization.

Module 1: Lexical analysis

  • The Lexical analysis phase of compiler is concerned about generating tokens out of the source program, skipping the whitespaces and comments, and to point out the lexical errors.
  • For achieving its objectives lexical analyzer scans the source code from a buffer, constructs the finite automata from regular expressions, and assembles the source code in the form of tokens.
  • This phase also creates a symbol table where tokens and their attributes are entered, which used by the remaining phases of the compiler.
  • A lexical analyzer can be generated using a tool available, called Lex or Flex (for fast Lexical analyzer generator).

Module 2: SYNTAX analysis

The syntax analysis is compiler phase next to lexical analysis. It is concerned about the grammatical structure of the program and its statements.

The syntax analysis, also called Parsing, is hardware independent and its output, which is a Parse-tree for each HLL statement, is used for intermediate code generation for any machine.

The following lecture notes, presents LL(0), LL(1), LR(0),LR(1) techniques of parsing, their algorithms, and analysis of each technique in details.

In addition, there is exhaustive list of self-review questions for students, as well as list of exercises covering every topic of syntax analysis.

Introduction to Syntax Analysis, type of Errors
Top-down Parsing
Recursive descent Parser
Predictive parser
Non-recursive Predictive parser
Old Sample question papers: Midsem    Midsem    EndSem
Bottom-up Parsing, Shift-reduce Parsing
Items sets, LR(0) Parser
LR(1) Parser
Parser Generator-YACC

Module 3: syntax directed translation,  storage allocation, intermediate code generation, code optimization, code generation

  • The syntax Directed Translation (SDT) makes use of syntax of the grammar to carry out the translation of statements of the corresponding language. SDT is carried out using L-attributed translations, which covers virtually all translations that can be performed during parsing. There is also a smaller class, called ``S-attributed translation.
  • The lecture notes also present Specification of a type checker, Intermediate code forms and three address code, Representing TAC using triples and of assignment statement. Boolean expression and control structures.

Syntax directed translation, L-attributed translation
Attributed Grammars
Intermediate code generation
Memory allocation, Basic blocks, code optimization

┬ęCopyright 2023 by Prof. K R Chowdhary. All rights reversed.