Analysis Phases:: The Structure of A Compiler
Analysis Phases:: The Structure of A Compiler
Type of tokens
There are five types of token as below:
.
The Structure of a Compiler
Syntax Analyzer (Parser):
Groups tokens together into syntactic structures called Expressions. Expressions might further be combined to
form Statements. Often the syntactic structure can be regarded as a Tree (parse tree) whose leaves are the tokens.
The interior nodes of the tree represent strings of tokens that logically belong together.
Every programming language has rules that prescribe the syntactic structure of well –formed programs. Syntax
analysis takes an out of lexical analyzer and produce a large tree call parse tree
Semantics:.
is a term used to describe "meaning", and so the constraint analyzer is often called the static semantic analyzer,
or simply the semantic analyzer. Semantic analyzer takes the output of syntax analyzer and produces another
tree.The output of the syntax analyzer and semantic analyzer phases is sometimes expressed in the form of a
Abstract Syntax Tree (AST). This is a very useful representation, as it can be used in clever ways to optimize
code generation at a later phase.
The Structure of a Compiler
It is Recently added a stage to analyze in terms of sentence meaning, in other words, will reject the sentence in
the case of the discovery of the meaning of error (Note: The sentence can be true in terms of the syntax but have
no meaning).
For example the English sentence : "The man eat the house " This is in the natural language, put in
programming languages can either write inter correct the hand, but wrong in the sense rules .
The Structure of a Compiler
Intermediate Code Generator:
Create a stream of simple instructions. Many style of intermediate code are possible. One common style uses
instructions with one operator and a small number of operands.
This phase is used structures built in the previous stages and convert them into intermediate codes by using a
most famous meta language such as:
- Postfix notation
- Polish notation
In some versions be enforceable as is the case in the interpreter for the BASIC language and commands
interpreter of the DOS operating system
The Structure of a Compiler
Code Optimization:
Is an optional phase designed to improve the intermediate code so that the ultimate object
program runs faster and/or takes less space.
Code Generation:
In a real compiler this phase takes the output from the previous phase and produces the object
code, by deciding on the memory locations for data, generating code to access such locations,
selecting registers for intermediate calculations and indexing, and so on.
The Structure of a Compiler
Table Management:
Portion of the compiler keeps tracks of the name used by the program and records essential
information about each, such as its type integer, real, … etc. the data structure used to record
this information is called a Symbolic Table.
Error Handler:
One of the most important functions of a compiler is the detection and reporting of errors in
the source program. The error messages should allow the programmer to determine exactly
where the errors have occurred. Whenever a phase of the compiler discovers an error, it must
report the error to the error handler, which issues an appropriate diagnostic message.