-
Notifications
You must be signed in to change notification settings - Fork 1
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
How are you handling the division and regExp literal ambiguity? #29
Comments
Jison provides status stack in the lexing phase which can be used to solve this problem. In the lexing phase, you can return different token for the bnf rules or update status stack based on the current context (the status stack, the token matched and the token looking ahead). Here is the code: Each lexical rule has a 'conditions' property and the handler will be triggered only when the top of the status stack matched. In this way, you can handle the symbol ambiguity if you enumerate all the possible status. All the things is done in lexing phase and I just use different alias of the same '/' in the bnf rules. And here is my test cases, To be honest I spent me a lot time to solve the ambiguity: |
This example explains how the status stack work:
|
Thank you. I understand that you are using the lexer previous context to figure out if the "/" is a division or regExp start. This approach may be complicated to support in the long term as the ecma grammar See: acornjs/acorn#589 I have created an ECMA5 parser example using a parser library I've authored: The increasing complexity of the scanner logic means that if and when I I will want to implement the scanner myself, |
I am also trying to figure out a better way to organize the code of the lexical part. When I try to extend the parser(like jsx support), the bnf parts is easy but the lexical part need to add some status and fix ambiguity. |
https://stackoverflow.com/questions/5519596/when-parsing-javascript-what-determines-the-meaning-of-a-slash
https://github.com/sweet-js/sweet-core/wiki/design
Is there a separate Lexing phase or is lexing done on demand and provided context by the parser?
The text was updated successfully, but these errors were encountered: