UNIT I BKS Lesson 3 Lexical Analysis and Role of Lexical Analyzer
UNIT I BKS Lesson 3 Lexical Analysis and Role of Lexical Analyzer
Sharma
UNIT I
Unit I: Syllabus
• Introduction to Compiler
• Structure of a compiler
• Lexical Analysis
• Role of Lexical Analyzer
• Input Buffering
• Specification of Tokens
• Recognition of Tokens
Learn Compiler Design: From B. K. Sharma
Unit I: Syllabus
• Lex
• Finite Automata
• Regular
• Expressions to Automata
• Minimizing DFA.
Learn Compiler Design: From B. K. Sharma
Tokens IR
Source Scanner Parser
code
Errors
Lexical Analysis:
The task concerned with breaking an input into its
smallest meaningful units, called tokens.
Lexical Analyzer (Scanner):
Program that reads input characters and produces
a sequence of tokens as output.
Learn Compiler Design: From B. K. Sharma
Other Roles:
Remove the white space/tab Remove the comments
if (x==3)
Tokens are:
Keyword, LPAR, IDENT, EQ, NUMBER, RPAR
<id, “y”> <assign, “:=“> <num, 31> <+, > <num, 28> <*, > <id, “x”>
token
tokenval
(token attribute)
Parser
Learn Compiler Design: From B. K. Sharma
a) 10 b) 35 c) 12 d) 46
Learn Compiler Design: From B. K. Sharma
Errors
1) Simpler design.
4) Specialization