Professional Documents
Culture Documents
Compiler Construction
Lexical Analysis, (Part-I)
by Safdar Hussain
Topics
• Lexical analyzer as separate phase, Interaction of Lexical Analyzer and Parser, lexical errors
• Tokens, lexemes, patterns, Attributes of tokens, Specification of tokens for patterns
(Terminology, String & language operations, RE, Regular Definitions, Notational Shorthands
Overview
This chapter contains comprehensive material
• Building a simple Lexical Analyzer
– Lexical Analysis (Every perspective)
– Interaction of Lexical analyzer & Parsing
– Implementing Transition Diagrams
– Design of a Lexical Analyzer (RENFADFA)
– The Subset Construction Algorithm
– Minimization of number of states of a DFA
– Conversion RE to DFA directly (Algorithm & Tree
annotation)
Symbol Table
<id, “y”> <assign, > <num, 31> <+, > <num, 28> <*, > <id, “x”>
token
tokenval
(token attribute) Parser
Answer:
<text, “Here is a photo of”> <nodestart, b> <text, “my house”> <nodeend, b>
<Nodestart, p> <selfendnode, img> <selfendnode, br>
<text, “see”> <nodestart, a> <text, “More Pictures”> <nodeend, a>
<text, “if you liked that one.”> <nodeend, p>
letter A | B | … | Z | a | b | … | z
digit 0 | 1 | … | 9
id letter ( letter | digit )*
25