Professional Documents
Culture Documents
CD Lect5
CD Lect5
CD Lect5
Design
Assoc. Prof. Ahmed Moustafa Elmahalawy
Communication and Computer Engineering Department
ميثاق المحاضرة
Contents:-
1- The Role of the Lexical Analyzer
2- Lexical Analysis Versus Parsing
3- Tokens, Patterns, and Lexemes
4- Attributes for Tokens
5- Example of Lexical Analysis, Tokens, Non-Tokens
6- Lexical Errors
7- Advantages and disadvantages of Lexical
analysis
8- Summery
Compiler Design Chapter 3: Lexical Analysis
Figure 3.1: Interactions between the lexical analyzer and the parser
Compiler Design Chapter 3: Lexical Analysis
Create an abstract
Identify Tokens representation of the
code
Insert tokens into Update symbol table
Symbol Table entries
10 DO 20 I = 1.30
is more deceptive.
2- Reading Ahead
3- Constants
Examples of Nontokens
Type Examples
Macro NUMS
Whitespace /n /b /t
Compiler Design Chapter 3: Lexical Analysis
6- Lexical Errors
A character sequence which is not possible to
scan into any valid token is a lexical error. Important
facts about the lexical error:
• Lexical errors are not very common, but it should
be managed by a scanner
• Misspelling of identifiers, operators, keyword are
considered as lexical errors
• Generally, a lexical error is caused by the
appearance of some illegal character, mostly at
the beginning of a token.
Compiler Design Chapter 3: Lexical Analysis
8- Summary
• Lexical analysis is the very first phase in the
compiler designing
• Lexemes and Tokens are the sequence of
characters that are included in the source
program according to the matching pattern
of a token
• Lexical analyzer is implemented to scan the
entire source code of the program
Compiler Design Chapter 3: Lexical Analysis