function RetrieveToken () returns Token
if Source has no more characters
Create a new Token.
Set the Type property of Token
= End-Of-File.
else
Set State = Initial-DFA-State.
Set Done = False.
Set Length = 1.
loop until Done
if the State accepts a termimal
Set Accept-State = State.
Set Accept-Length = Length.
end if
If an Edge in State
exists that contains the character Lookahead(Length) in Source
Set State = the Target-State
property of the Edge.
Increment the Length.
else
if the Accept-State was set
Create a new Token.
Set the Parent-Symbol property of Token = symbol in Accept-State.
Set the Data property of Token
= read Length characters from Source.
else
Create a new Token.
Set the Parent-Symbol property of Token = Error.
Set the Data property of Token
= read one character from Source.
end if
Set Done = True.
end if
next loop
end if
Return the Token.
end function |