Professional Documents
Culture Documents
Compiler Design
KCS502
by
DR PARUL YADAV
Main Task:
Read the input characters of the source program
Group them into lexemes
Produce as output a sequence of tokens for each lexeme
Lexical Analysis
Other Tasks:
• Stripping out comments and whitespaces
• Correlating error messages Group them into lexemes
• May make copy of the source program with error messages inserted at appropriate
positions
• Macro preprocessing etc.
Lexical Analysis versus Parsing
• Simplicity of design
• Compiler efficiency is improved
• Compiler portability is enhanced
Token, Pattern and Lexemes
Finite Automata for Identifier
Finite Automata for Operators
Finite Automata for Numbers
Examples of Tokens
Tokens
Example: Token for FORTRAN Statement
Input Buffer
Counting Tokens
Thank you