Compiler Construction CS-4207: Instructor Name: Atif Ishaq
Compiler Construction CS-4207: Instructor Name: Atif Ishaq
CS-4207
Recognition of Token
2
Recognition of Token : Transition Diagram
3
Recognition of Token : Transition Diagram
A string belongs to the language if, while reading the string, the automaton
4
Recognition of Token : Transition Diagram
Following diagram is an NFA which recognizes the language of all string over ∑ :
5
Recognition of Token : Transition Diagram
6
Recognition of Token : Transition Diagram
7
Recognition of Token : Transition Diagram
8
Recognition of Token : Transition Diagram
9
Recognition of Tokens : Transition Diagram
10
Recognition of Tokens : Transition Diagram
11
What else a Lexical Analyze Do?
if 15
then 16
begin 17
... ...
12
Transition Diagram : Code
token nexttoken()
{ while (1) {
switch (state) {
case 0: c = nextchar();
if (c==blank || c==tab || c==newline) { Decides the
state = 0;
lexeme_beginning++; next start state
}
else if (c==‘<’) state = 1; to check
else if (c==‘=’) state = 5;
else if (c==‘>’) state = 6;
else state = fail();
break; int fail()
case 1: { forward = token_beginning;
… swith (start) {
case 9: c = nextchar(); case 0: start = 9; break;
if (isletter(c)) state = 10; case 9: start = 12; break;
else state = fail(); case 12: start = 20; break;
break; case 20: start = 25; break;
case 10: c = nextchar(); case 25: recover(); break;
if (isletter(c)) state = 10; default: /* error */
else if (isdigit(c)) state = 10; }
else state = 11; return start;
break; }
13
…
Transition Diagram : Code
14
Lecture Outcome
15
Lecture Outcome
Token Recognition
16
17