Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Sajeel Zulfiqar
Lecture Plan
Week 6:
Tokens Recognitions,Transition Diagrams and
DFAs
token attribute-value
Architecture of a transition-diagram-based
lexical analyzer
TOKEN getRelop()
{
TOKEN retToken = new (RELOP)
while (1) { /* repeat character processing until a
return or failure occurs */
switch(state) {
case 0: c= nextchar();
if (c == ‘<‘) state = 1;
else if (c == ‘=‘) state = 5;
else if (c == ‘>’) state = 6;
else fail(); /* lexeme is not a relop */
break;
case 1: …
…
case 8: retract();
retToken.attribute = GT;
return(retToken);
}
Transition Diagrams for Identifiers and
Keywords
Accepting aa*|bb*
DFA (cont’)
For Every symbol of the alphabet, there is We do not need to specify how does the
only one state transition in DFA. NFA react according to some symbol.
DFA will reject the string if it end at other If all of the branches of NFA dies or
than accepting state. rejects the string, we can say that NFA
reject the string
((DFA Vs NFA)
DFA NFA
Backtracking is allowed in DFA. Backtracking is not always allowed in NFA
NFA can be understood as multiple little
DFA can be understood as one machine.
machines computing at the same time.
DFA is more difficult to construct NFA is easier to construct
If all of the branches of NFA dies or
DFA will reject the string if it end at other
rejects the string, we can say that NFA
than accepting or final state.
reject the string.