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

Just a Comment #15

Open
ChayimFriedman2 opened this issue Oct 9, 2020 · 0 comments
Open

Just a Comment #15

ChayimFriedman2 opened this issue Oct 9, 2020 · 0 comments

Comments

@ChayimFriedman2
Copy link

ChayimFriedman2 commented Oct 9, 2020

I've read your article https://calebschoepp.com/blog/2020/adding-a-list-data-type-to-lox/. Nice 😃.

One note, however: your grammar is incorrect. Specifically, your precedence is incorrect. Subscripting should be the same precedence as call (and property access). You should replace:

call           → subscript ( "(" arguments? ")" | "." IDENTIFIER )* ;
subscript      → primary ( "[" logic_or "]" )* ;

With:

call           → subscript ( "(" arguments? ")" | "." IDENTIFIER | "[" logic_or "]" )* ;

Otherwise, an expression like f()[0] won't be valid. I would also change the thing inside the brackets to expression, like parentheses (most languages do so), but the choice is yours 😃.

Also, you duplicate the rule unnecessarily: in your assignment rule, you need just one bracket (the asterisk is redundant). Instead of:

assignment     → ( call "." )? IDENTIFIER ( "[" logic_or "]" )* "=" assignment
               | logic_or ;

Do:

assignment     → ( ( call "." )? IDENTIFIER | ( "[" logic_or "]" ) ) "=" assignment
               | logic_or ;

Because an expression like a[0][0] = 0 can emit normally for the a[0], just the [0] = 0 at the end needs special handling.

Yeah, designing a language is hard 😄. This is the reason I always look for "what other languages do", preferably their EBNF, when writing my own EBNF.

Disclaimer: I haven't read your code, just your EBNF syntax.

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

No branches or pull requests

1 participant