Unit-1 CD
Unit-1 CD
Phases of program
a complier
Llexical Analyzer
LSyntax Analyzer
Ssymbol table
manager semantic
Analyzer
Error Handler
Lintermediate
code generator
L code optimizer
Target
L code generator program
Let us consider the statement
position:=initial + rate*60
• Lexical Analyzer:
• It reads the character in the source program and groups into a stream
of tokens in which each token represents an identifiers, keywords(if,
while….),punctuation character :=,…..
• Linear analysis is also refered as lexical analysis or scanning
• The character sequence forming a token is called lexence for the
token
• The statement of identifiers are entered into symbol table
• Symbol Table
Identifiers Type of identifiers
60 const int
• These attributes may provide information about the storage allocated for an
identifier ,its type , its scope.
• It is a data structure containing a record for each identifier and to store/retrieve
data quickly
• Whenever an identifier is detected by a lexical analyzer it is entered into the
symbol table
• ERROR DETECTION AND REPORTING
• Each phase can encounter error after detecting an error how to deal for
compilation proceed that should be identified
• A complier stops when it finds the first error
• The syntax and sematic analysis usually handle large fraction of error
• Lexical phase can detect error
• syntax of the danger is detect during syntax analysis
LEXICAL ANALYZER
• It is the first phase of complier or scanner
• It converts the high level input program into a sequence of tokens
• LA is implemented with the DFA
• Output is a sequence of tokens that is sent to the parser for syntax
analysis
• Read chars tokens