PDF Crop
PDF Crop
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
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.