- Query-based compiler architecture: https://ollef.github.io/blog/posts/query-based-compilers.htm...
- Lezer [a parsing system used by CodeMirror]: https://marijnhaverbeke.nl/blog/lezer.html
- Anders Hejlsberg on Modern Compiler Construction: https://www.youtube.com/watch?v=wSdV1M7n4gQ
(a: int, b: float, c) => { ....
which is not a valid tuple expression. Just had to make my life harder haha expr ::= <all the other expressions>
| '(' [ expr { ',' expr } ] ')'
| '{' { expr } '}'
| expr '=>' expr
| identifer '(' expr { ',' expr } ')'
| literal
Tried adding it to the javascript grammar I play with and the parser generator (Coco/R) didn't complain about conflicts -- though it doesn't have tuples so YMMV.--edit--
Played with it a bit more and added tuples (as a replacement for '(' expr ')' grouping expression (exactly like the now-edited example above) and it still seems happy. If I were to add this to the grammar for real I'd have to monkey around with it some more to ensure there was an actual '(' ... ')' expression before the => but seems easily doable by transforming the grammar a bit.
I recently hand-wrote my own parser so I could achieve some these results. Having used parser generators in the past, I realize now that hand writing a parser is SO much more flexible.
Another area that should be mentioned is purposefully messy grammars. A common addition to languages these days are arrow functions:
These are really nice for defining functions, but they usually cause unbounded lookahead. For instance in JavaScript, the arguments list can also be parsed as a comma expression inside parentheses. In my language they can be parsed as a tuple expression. There might be some tricky way of doing this with an LR parser, but I can't figure it out. Therefore I needed to parse arrow functions/tuples by basically assuming they're an arrow function, then if I'm mistaken, I convert my parameters list into a tuple expression and continue parsing. For instance: When we hit the 10, my parser goes "ah shoot, this is a tuple" and converts the (a, b to be expressions in a tuple.Some may argue that grammars should just stay within LR/LALR/LL, but I do think adding a little bit of parsing complexity for ease of use is a worthy tradeoff.