Grammar-driven binary operator precedence by lightmare · Pull Request #174 · engine262/engine262 · GitHub
Skip to content

Grammar-driven binary operator precedence#174

Open
lightmare wants to merge 3 commits into
engine262:mainfrom
lightmare:grammar-driven-precedence
Open

Grammar-driven binary operator precedence#174
lightmare wants to merge 3 commits into
engine262:mainfrom
lightmare:grammar-driven-precedence

Conversation

@lightmare

Copy link
Copy Markdown
Contributor

This was motivated by a desire to experiment with new operators. The very first step in doing so — adding a token type for the new operator — is tedious. You have to pick a precedence level and then bump other operators. If you want to add a right-associative operator, you also need modify parseBinaryExpression.

So the first thing I did was multiply levels by 100, so that there are gaps for new operators (something I learned from Prolog).

But then I realized ECMAScript doesn't define operator precedence with numbers. It is embedded in the grammar. And I thought it'd be nice to have this reference implementation follow the grammar more closely.

@devsnek devsnek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall seems nice, just need to work out the chaining dispatch...

Comment thread src/parser/ExpressionParser.mjs
@devsnek

devsnek commented Jul 23, 2022

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants