mozilla-spidermonkey / jsparagus

Experimental JS parser-generator project.
Other
447 stars 20 forks source link

Add replay action #576

Closed nbp closed 4 years ago

nbp commented 4 years ago

Previously APS.shift_next was maintaining the invariant that the state was always the state of the last edge in the shift list, which is emulating the Parser stack.

Now, as we want to remove unnecessary iteration of the shift function of the parser, we want to be able to express transitions which are in the parse table by using Actions when possible. As a consequence, the state of the parser might momentarily no longer correspond to the last shifted state of the Parser.

This case can happen, when executing an Unwind action which is not wrapped with a Reduce action, when executing a Replay action, when evaluating an action where the state does not already match such as FilterState.

However, an assertion is raised if a terminal or non-terminal is shifted while the state does not match the parse table state. This assertion ensures that whatever is being executed with actions converge back to what is represented by the parse table.

Note: The Unwind and Replay states are modifying the stack, but still are following the edges (Action.follow_edge). reduce_path (in aps.py) attempts to reconstruct any potential Parser stacks. As Unwind and Replay are ignored from this process as they are redundant with the rest of the ParseTable.

This work is part of #430 and #429 goals, as a way to fold reduce actions, and automatically remove most of the replay actions.