JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY
CS153 (CS132)
Class notes
Compiler Construction CS132(CS153)
0 view 0 purchase
Course
CS153 (CS132)
Institution
JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY
The notes include topics touching on Lexical Analysis, syntax analysis, top-down parsing, bottom-up parsing which are key concepts when learning about compiler construction.
JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY
CS153 (CS132)
All documents for this subject (5)
Seller
Follow
roykibet
Content preview
Introduction
A compiler is a system software that converts a program written in high-level language that is suitable for
programmers into a low-level language required by computers. During the process, the compiler will also
attempt to spot and report obvious programmer mistakes. This is illustrated below:
Source Compiler Target
Program Program
Error Warnings
Messa
There are two parts of compilation:
i). The analysis part – breaks up the source program into constant pieces and creates an
intermediate representation of the source program.
ii). Synthesis part – constructs desired target program from the intermediate representation.
Phases of a Compiler
To ease the process of development and understanding, a compiler can be conceptually divided into the
following phases:
i) Lexical analysis
ii) Syntax analysis
iii) Semantic analysis
iv) Intermediate generation
v) Target code generation
vi) Code optimization
vii) Symbol table management
viii) Error handling and recovery
The following diagram shows the relationship between these modules:
Compiler Construction Notes ~ Wainaina Page 1 of 12
, Source Program
Lexical Analysis
Tokens
Syntax Analysis
Parse Tree
Semantic Analysis
Symbol table Error Handling
Semantic Correctness and Recovery
management
Intermediate
Code generation
i). Lexical Analysis
This is the initial part of reading and analysing the program text; the text is read and divided into tokens,
each of which corresponds to a symbol in the programming language e.g. a variable name, number,
keyword, etc. It is basically used to identify valid words in the input source program.
ii). Syntax Analysis
This phase takes the list of tokens produced by the lexical analysis and arranges them into a tree structure
(syntax tree) that reflects the structure of the program. It is generally used to establish if the program is
grammatically correct. This phase is often called parsing.
iii). Semantic Analysis
This phase analyses the syntax tree to determine if the program violates certain consistency requirements
e.g. if a variable is used and not declared or if it is used in a context that doesn’t make sense given the type
of variable such as trying to assign a value greater than the variable.
iv). Intermediate Code Generation
This phase is used to translate the program into a simple machine independent intermediate language. This
process helps to retarget the compiler generating code from one processor to another.
Generally, generating machine code directly from source code entails two problems
With m languages and n target machines, we need to write m × n compilers
The code optimizer which is one of the largest and very-difficult-to-write components of any
compiler cannot be reused
By converting source code to an intermediate code, a machine-independent code optimizer may be written
Compiler Construction Notes ~ Wainaina Page 2 of 12
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller roykibet. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $10.49. You're not tied to anything after your purchase.