function ParseToken (Token)
returns Parse-Result-Token
if an Action for Token
exists in the Current-LALR-State
case type of Action is
Accept:
Set Result = Accept.
Shift:
Set the State property of Token to the Current-LALR-State.
Push Token onto the LALR-Token-Stack.
Set Current-LALR-State = target state of Action.
Set Result = Shift.
Reduce:
Set Reduce-Rule = rule to be reduced which is
specified in Action.
If Trim-Reductions is active and Reduce-Rule contains one nonterminal
Set Item = Pop the top token off the LALR-Token-Stack.
Create a new token Head.
Set Parent-Symbol property of Head to the rule being reduced by Action.
Set the Data propety of Head
to the Data property of Item.
Set Result = Reduce-Trimmed.
else
Create a new Reduction.
Set the Parent-Rule property of Reduction to the rule reduced by Action.
loop for each symbol in the handle of the Reduce-Rule
Pop a token Item from the stack.
Add Item to Reduction.
next loop
Create a new token Head.
Set Parent-Symbol property of Head to the rule being reduced by Action.
Set the Data property of Head
to the Reduction.
Set Result = Reduce.
end if
Set Lookup-State = State
property of the token on the top of the LALR-Token-Stack.
Set Current-LALR-State = State
specified by the goto for Head in Lookup-State.
Set the State property of Head to the Current-LALR-State.
Push Head onto the LALR-Token-Stack.
end case
else
Set Result = Syntax-Error.
end if
Return the Result.
end function |