function Parse() returns Message-Constant
If the parse tables were not loaded
Set Result = Not-Loaded-Error
else
Set Done = False.
Loop until Done
If the Input-Stack is empty
Set Token = LexerGetToken().
Push the Token onto the Input-Stack.
If the Comment-Stack is empty and the Token is a normal terminal
Set Result = Token-Read.
Set Done = True.
end if
else if Comment-Level > 0
Pop a Token from the front of the Input-Stack.
case the Kind of Token
is
Comment-Start:
Increment the Comment-Level.
Comment-End:
Decrement the Comment-Level.
End-Of-File:
Set Result = Message-Comment-Error.
Set Result = True.
otherwise:
end case
else
Set Token = the token on the front of the Input-Stack.
case the Kind of Token
is
Whitespace:
Discard the token from the front of the Input-Stack.
Comment-Start:
Set Comment-Level = 1.
Discard the token from the front of the Token-Queue.
Comment-Line:
Discard the rest of the current line in Source.
Discard the token from the front of the Input-Stack.
Error:
Set Result = Message-Lexical-Error.
Set Done = True.
otherwise:
Set Parse-Result = ParseToken
( Token ).
case the Parse-Result is
Accept:
Set Result = Accept.
Set Done = True.
Internal-Error:
Set Result = Internal-Error.
Set Done = True.
Reduce:
Set Result = Reduction.
Set Done = True.
Shift:
Discard the token from the front of the Input-Stack.
Syntax-Error:
Set Result = Message-Syntax-Error.
Set Done = True.
otherwise:
end case
end case
end if
next loop
end if
Return the Result.
end function |