[go: up one dir, main page]

Open In App

Compiler Design Tutorial

Last Updated : 12 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

compiler is software that translates or converts a program written in a high-level language (Source Language) into a low-level language (Machine Language). Compiler design is the process of developing a program or software that converts human-written code into machine code. It involves many stages like lexical analysis, parsing, semantic analysis, code generation, optimization, etc. The Key objective of compiler design is to automate the translation process, the correctness of output, and reporting errors in source code. The compiler is used by programming languages such as C, C++, C#, Java, etc.

In this compiler design tutorial, all the basic to advanced topics are included like lexical analysis, code generation, and optimization, runtime environment, etc.

Why do we learn compiler design?

A computer is a logical assembly of software and hardware. The hardware understands a language that is hard for humans to understand. So, we write programs in a high-level language, that is less complex for humans to understand and maintain in thoughts. Now, a series of transformations have been applied to high-level language programs to convert them into machine language.

Introduction :

  1. Introduction of Compiler design
  2. Compiler construction tools
  3. Phases of a Compiler
  4. Symbol Table in Compiler
  5. C++ Program to implement Symbol Table
  6. Error detection and Recovery in Compiler
  7. Error Handling in Compiler Design
  8. Language Processors: Assembler, Compiler and Interpreter
  9. Generation of Programming Languages

Lexical Analysis :

  1. Lexical Analysis
  2. C program to detect tokens in a C program
  3. Flex (Fast Lexical Analyzer Generator )

>> Quiz on Lexical Analyses

Syntax Analysis :

  1. Introduction to Syntax Analyses
  2. Why FIRST and FOLLOW?
  3. FIRST Set in Syntax Analyses
  4. FOLLOW Set in Syntax Analyses
  5. Program to calculate First and Follow sets of given grammar
  6. Classification of Context Free Grammars(CFG)
  7. Ambiguous Grammar
  8. Parsing | Set 1 (Introduction, Ambiguity and Parsers)
  9. Classification of top down parsers
  10. Parsing | Set 2 (Bottom Up or Shift Reduce Parsers)
  11. Shift Reduce Parser in Compiler
  12. Parsing | Set 3 (SLR, CLR and LALR Parsers)
  13. Theory of Computation | Operator grammar and precedence parser

Syntax Directed Translation :

  1. Syntax Directed Translation
  2. S – attributed and L – attributed SDTs in Syntax directed translation

>> Quiz on Parsing and Syntax Directed Translation

Code Generation and Optimization :

  1. Code Optimization
  2. Intermediate Code Generation
  3. Issues in the design of a code generator
  4. Three address code in Compiler
  5. Compiler Design | Detection of a Loop in Three Address Code
  6. Introduction of Object Code
  7. Data flow analysis in Compiler

>> Quiz on Code Generation and Optimization

Runtime Environments :

  1. Static and Dynamic Scoping
  2. Compiler Design | Runtime Environments
  3. Compiler Design | Linker
  4. Loader in C/C++
  5. Developing a Linux based shell

FAQs on Compiler Design

Q.1 Write types of compilers?

Answer:

There are three types of compilers given below:

  1. Single-Pass Compilers
  2. Two-Pass Compilers
  3. Multi-pass Compilers

Q.2 Difference between compiler and assembler?

Answer:

COMPILER ASSEMBLER
Compiler converts the source code which is written by the programmer to machine level language. Assembler converts the assembly code into the machine code.
Compiler converts the whole code into machine code. Assembler converts the code one by one.
It takes less execution time in conversion compared to an assembler. It takes more time than a compiler.
Input is the source code in a high-level language. Assembly level code as an input.
Examples: C, C++, Java compilers, etc. Examples: GAS, GNU assemblers.

Q.3 Discuss the various phases of a compiler?

Answer:

The various phases of the compiler are given below:

  • Lexical Analyzer
  • Syntax Analyzer
  • Semantic Analyzer
  • Intermediate code generator
  • Code optimizer
  • Code generator

Q.4 What are assembler?

Answer:

Assembler is a program that interprets assembly language written software programs into machine language that is known to the computer.

Quick Links :

Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above.



Similar Reads

Advantages of Multipass Compiler Over Single Pass Compiler
Programmers, write computer programs that make certain tasks easier for users. This program code is written in High-Level Programming languages like C, C++, etc. Computer device doesn't understand this language or the program written by a programmer, so the translator that translates the High-Level Program code into Machine Readable Instructions is
6 min read
Difference between Native compiler and Cross compiler
1. Native Compiler : Native compiler are compilers that generates code for the same Platform on which it runs. It converts high language into computer's native language. For example, Turbo C or GCC compiler. if a compiler runs on a Windows machine and produces executable code for Windows, then it is a native compiler. Native compilers are widely us
6 min read
Compiler Design - GATE CSE Previous Year Questions
Solving GATE Previous Year's Questions (PYQs) not only clears the concepts but also helps to gain flexibility, speed, accuracy, and understanding of the level of questions generally asked in the GATE exam, and that eventually helps you to gain good marks in the examination. Previous Year Questions help a candidate practice and revise for GATE, whic
4 min read
Peephole Optimization in Compiler Design
Peephole optimization is a type of code Optimization performed on a small part of the code. It is performed on a very small set of instructions in a segment of code. The small set of instructions or small part of code on which peephole optimization is performed is known as peephole or window. It basically works on the theory of replacement in which
2 min read
Compiler Design | Syntax Directed Definition
Prerequisite - Introduction to Syntax Analysis, Syntax Directed Translation Syntax Directed Definition (SDD) is a kind of abstract specification. It is generalization of context free grammar in which each grammar production X --> a is associated with it a set of production rules of the form s = f(b1, b2, ......bk) where s is the attribute obtain
4 min read
Compiler Design | Detection of a Loop in Three Address Code
Prerequisite - Three address code in Compiler Loop optimization is the phase after the Intermediate Code Generation. The main intention of this phase is to reduce the number of lines in a program. In any program majority of the time is spent actually inside the loop for an iterative program. In the case of the recursive program a block will be ther
3 min read
Loop Optimization in Compiler Design
Loop Optimization is the process of increasing execution speed and reducing the overheads associated with loops. It plays an important role in improving cache performance and making effective use of parallel processing capabilities. Most execution time of a scientific program is spent on loops. Loop Optimization is a machine independent optimizatio
4 min read
Types of Parsers in Compiler Design
The parser is that phase of the compiler which takes a token string as input and with the help of existing grammar, converts it into the corresponding Intermediate Representation(IR). The parser is also known as Syntax Analyzer. Types of Parser: The parser is mainly classified into two categories, i.e. Top-down Parser, and Bottom-up Parser. These a
2 min read
Semantic Analysis in Compiler Design
Semantic Analysis is the third phase of Compiler. Semantic Analysis makes sure that declarations and statements of program are semantically correct. It is a collection of procedures which is called by parser as and when required by grammar. Both syntax tree of previous phase and symbol table are used to check the consistency of the given code. Type
2 min read
Parse Tree in Compiler Design
Here we will study the concept and uses of Parse Tree in Compiler Design. First, let us check out two terms : Parse : It means to resolve (a sentence) into its component parts and describe their syntactic roles or simply it is an act of parsing a string or a text.Tree: A tree may be a widely used abstract data type that simulates a hierarchical tre
2 min read
Article Tags :