Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove grammar hacks by replacing the parser generator. #347

Merged
merged 91 commits into from Mar 6, 2020

Conversation

@nbp
Copy link
Collaborator

nbp commented Mar 4, 2020

This pull request replaces the previous parser generator by a new one. (Fix #54 )

The previous parser generator was based on an LALR(1) parser generator, whereas the new one is based on an LR(0) parser generator in addition to algorithms inspired by the Lane-Table algorithm and Edge-pushing algorithm.

One of the major difference over the literature on parser generators, is that Reduce is no longer considered an exit edge for a node, but as an epsilon edge on which we attach a reduce Action.

In this new model, all epsilon edges are carrying code to be executed at runtime, or to be removed during the parse table fixing phase. The parse table is inconsistent if the code to be executed at runtime is non-deterministic, which is equivalent to shift-reduce and reduce-reduce conflicts.

However, instead of raising errors on inconsistencies, a variant of lane-table algorithm is used to remove these inconsistencies. This is a variant, we have more than one kind of actions, and not only Reduce actions.

For examples:

  • [lookahead != 'let'] are implemented as a Lookahead action, which is always inconsistent, until the parse table is fixed by shifting additional terms, which removes these actions by rewriting the parse table.
    [no LineTerminator here] is implemented as CheckNotOnNewLine, which is inconsistent as long as the token is not shifted to the stack.

This new parser generator should help us implement:

  • [+Yield] as a FilterFlag action by having an additional flag-stack at runtime. (which is the context-dependent part of the JavaScript grammar)
  • [lookahead != 'let' '[' ] as a Lookahead action with more than one token.
nbp added 30 commits Jan 10, 2020
…ctions,

StateAndTransitions and LR0Generator to be used when generating the ParseTable.
…roach, which does not involve splitting as much.
@nbp nbp requested a review from jorendorff Mar 4, 2020
@nbp nbp self-assigned this Mar 4, 2020
@nbp nbp changed the title Fix #54 - Remove grammar hacks by replacing the parser generator. Remove grammar hacks by replacing the parser generator. Mar 4, 2020
@nbp nbp added MVP P1 labels Mar 4, 2020
@nbp nbp added this to the 2 - Setup milestone Mar 4, 2020
jsparagus/emit/python.py Outdated Show resolved Hide resolved
jsparagus/emit/python.py Outdated Show resolved Hide resolved
jsparagus/gen.py Show resolved Hide resolved
@nbp nbp merged commit 385b7a0 into mozilla-spidermonkey:master Mar 6, 2020
1 check passed
1 check passed
build
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.