0% found this document useful (0 votes)
24 views7 pages

PDF Crop

Uploaded by

minaxijadeja2110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

PDF Crop

Uploaded by

minaxijadeja2110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Introduction to

Compiler Technology
A compiler is a program that translates code written in one language into
another language. The process of compilation involves several stages, each
with its own distinct purpose.
Parsing
1 Syntax Analysis
The parser takes the stream of tokens generated by the
lexical analyzer and checks if they form a valid syntax
according to the grammar of the programming language.

2 Parse Tree
If the syntax is valid, the parser creates a parse tree, a
hierarchical representation of the program's structure.

3 Error Handling
If the syntax is invalid, the parser identifies syntax errors and
reports them to the programmer.
Semantic Analysis
Type Checking Symbol Table Intermediate Code Generation

The semantic analyzer checks if the The semantic analyzer uses a symbol After semantic analysis, the compiler
operations and expressions in the code table to store information about the generates an intermediate
are semantically valid, ensuring that program's variables, functions, and representation of the program, typically
variables are used correctly and that other identifiers, ensuring that they are in a form that is easier to optimize and
operations are performed on declared and used correctly. translate to machine code.
compatible data types.
Intermediate Code Generation
Intermediate Representation
The intermediate code generation phase translates the parse
1
tree into a form that is easier to optimize and translate to
machine code.

Three-Address Code
A common intermediate representation is three-address code,
2
which represents each operation as a distinct instruction with
at most three operands.

Optimization
3 The intermediate code is then optimized to improve its
efficiency and reduce its size.
Code Optimization
Optimization Techniques Description

Constant Folding Evaluating constant expressions


at compile time to reduce
runtime computations.

Dead Code Elimination Removing unnecessary or


unreachable code sections.

Register Allocation Assigning variables to processor


registers for faster access.
Code Generation
Machine Code Assembly Language Target Architecture
The code generator translates the Sometimes the code generator The code generator needs to consider
optimized intermediate code into produces assembly language, a low- the specific architecture of the target
machine code, a sequence of level programming language that is processor, ensuring that the
instructions that the target processor closer to machine code and can be generated code is compatible with the
can understand and execute. easily translated into machine code by processor's instruction set and
an assembler. memory organization.
Conclusion and Applications

Software Development
Compilers are essential for creating software, allowing developers to write
code in high-level languages that are easier to understand and maintain.

Mobile Apps
Compilers are also used to develop mobile applications, translating code
written for different platforms into the native machine code of the target
devices.

Game Development
Compilers are used in game development to translate code that defines
game logic and graphics into machine code that can be executed on gaming
consoles or PCs.

You might also like