0% found this document useful (0 votes)
59 views

Chapter 1 - Compiler Principles

This document provides information about the CST302 Compiler Principles course. The course covers the major parts of compiler construction including lexical analysis, syntax analysis, parsing, abstract syntax, symbol tables, semantic analysis, code generation, and optimization. Students will complete a compiler-related project applying concepts from the course. The course introduces the principles and techniques used in translating a program from a source language to an executable form.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Chapter 1 - Compiler Principles

This document provides information about the CST302 Compiler Principles course. The course covers the major parts of compiler construction including lexical analysis, syntax analysis, parsing, abstract syntax, symbol tables, semantic analysis, code generation, and optimization. Students will complete a compiler-related project applying concepts from the course. The course introduces the principles and techniques used in translating a program from a source language to an executable form.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

CST302 Compiler Principles

Office Number: A1-357


Prerequisite/co-requisite(if any)

➢Programming Languages(C) ,
➢Discrete Mathematics,
➢Data Structures

CST302
synopsis
➢ Any program written in a programming language must be translated before it can be executed.
➢ This translation is typically accomplished by a software system called a compiler.
➢ This module aims to introduce students to the principles and techniques used to perform this translation and
the issues that arise in the construction of a compiler.
➢ This course is concerned with providing the students with a firm theoretical basis for compiler construction
and sound engineering principles for selecting alternate methods and implementing them.
➢ It mainly focuses on the theory and techniques of the construction of a compiler, covers the major parts of a
compiler, including lexical analysis, syntax analysis, parser generators, abstract syntax, symbol tables,
semantic analysis, intermediate languages, code generation, code optimization, run-time storage management,
error handling.
➢ The course includes a special compiler-related project, which ties together concepts of algorithms, theory
(formal languages), programming languages, software engineering, computer architecture, and other subjects
covered in the curriculum.
➢ This project requires a programming effort, such as the construction of a language compilation or translation
system that includes lexical and syntactic analyzers, a semantic analysis, and a code generator.

CST302
CST302
COURSE OUTLINE
1. Introduction to compiler construction
(Structure of a Compiler, Applications of Compiler Technology)

2. A simple Syntax-Directed Translator (Syntax Definition, Syntax-Directed


Translation, Parsing, A Translator for Simple Expressions)

3. Finite Automata and Lexical Analysis (Recognition of Tokens, From Regular


Expressions to Automata, Design of a Lexical-Analyzer Generator)

4. Regular Expression
(Regular Definitions, Extensions of Regular Expressions)

5. Context-Free Grammars
(The Formal Definition of a Context-Free Grammar, Derivations, Parsing Trees,
Ambiguity, Writing a Grammar)

CST302
COURSE OUTLINE
6. Top-down parsing
( Recursive-Descent Parsing, FIRST and FOLLOW, LL(1) Grammars)

7. Bottom-up parsing
(LR-Parsing, SLR-Parsing, LR(1) Parsing, LALR Parsing, Parser Generator)

8. Syntax-Directed Definitions (Inherited and Synthesized Attributes, Evaluation Orders for SDD’s)

9. Syntax-Directed Translation Schemes


(Postfix Translation Schemes, Eliminating Left Recursion From SDT’s, SDT’s for L-Attributed
Definitions, Implementing L-Attributed SDD’s)

10. Intermediate-Code Generation (Three-Address Code, Types and Declarations, Translation of


Expressions, Type Checking, Control Flow, Backpatching)
11. Run-Time Environments
(Storage Organization, Stack Allocation of Space, Heap Management)

12. Code Generation


(Target Language, Addresses in the Target Code, Basic Blocks and Flow Blocks, A Simple Code
Generator)

CST302
CONTINUOUS ASSESSMENT

CST302
FINAL ASSESSMENT

CST302
REFERENCES
Required References
• Alfred V. Aho, Monica Lam, Ravi Sethi, and Jeffrey D. Ullman (2007). Compilers:
Principles, Techniques, and Tools (2nd ed). Addison-Wesley. *

• Thain, D. (2019). Introduction to Compilers and Language Design.

Further Readings
• Watson and Des (2017). A Practical Approach to Compiler Construction

• Halsey, T. (2018). Compiler Design: Principles, Techniques and Tools.

*Checks had been made with publishers as of the date of syllabus update. No newer
editions are released by publishers. The references listed above are indispensible.

CST302
CST302
CST302
Compiler principles lab
IMPORTANCE OF COMPILER DESIGN LAB
Compiler is a software which takes as input a program written in a High-Level language and
translates it into its equivalent program in Low Level program.
Compilers teaches us how real-world applications are working and how to design them. Learning
Compilers gives us with both theoretical and practical knowledge that is crucial in order to
implement a programming language.
It gives you a new level of understanding of a language in order to make better use of the
language (optimization is just one example). Sometimes just using a compiler is not enough.
You need to optimize the compiler itself for your application.
Compilers have a general structure that can be applied in many other applications, from
debuggers to simulators to 3D applications to a browser and even a cmd / shell. understanding
compilers and how they work makes it super simple to understand all the rest. a bit like a deep
understanding of math will help you to understand geometry or physics.

CST302
We cannot do physics without the math. not on the same level. Just using something
(read: tool, device, software, programming language) is usually enough when everything
goes as expected. But if something goes wrong, only a true understanding of the inner
workings and details will help to fix it.
Even more specifically, Compilers are super elaborated / sophisticated systems
(architecturally speaking). If you will say that can or have written a compiler by yourself -
there will be no doubt as to your capabilities as a programmer.
There is nothing you cannot do in the Software realm. So, better be a pilot who have the
knowledge and mechanics of an airplane than the one who just know how to fly.
Every computer scientist can do much better if have knowledge of compilers apart from
the domain and technical knowledge.
Compiler design lab provides deep understanding of how programming language Syntax,
Semantics are used in translation into machine equivalents apart from the knowledge of
various compiler generation tools like LEX,YACC etc.
CST302
A compiler or interpreter for a programming language is often decomposed into
two parts:
1. Read the source program and discover its structure.
2. Process this structure, e.g. to generate the target program.
Lex and Yacc can generate program fragments that solve the first task.
The task of discovering the source structure again is decomposed into subtasks:
1. Split the source file into tokens (Lex).
2. 2. Find the hierarchical structure of the program (Yacc).

CST302
lex
What is Lex? What is Yacc?
What is Lex?
Lex is officially known as a "Lexical Analyzer".

It's main job is to break up an input stream into more usable elements.

Or in, other words, to identify the "interesting bits" in a text file.

For example, if you are writing a compiler for the C programming language, the symbols { } ( ) ; all have
significance on their own. The letter a usually appears as part of a keyword or variable name, and is not
interesting on it's own. Instead, we are interested in the whole word. Spaces and newlines are completely
uninteresting, and we want to ignore them completely, unless they appear within quotes "like this"

All of these things are handled by the Lexical Analyser.

CST302
yaac
What is Yacc?
Yacc is officially known as a "parser".

It's job is to analyse the structure of the input stream, and operate of the "big picture".

In the course of it's normal work, the parser also verifies that the input is syntactically sound.

Consider again the example of a C-compiler. In the C-language, a word can be a function name
or a variable, depending on whether it is followed by a ( or a = There should be exactly one } for
each { in the program.

YACC stands for "Yet Another Compiler Compiler". This is because this kind of analysis of text
files is normally associated with writing compilers.

CST302

You might also like