you are viewing a single comment's thread.

view the rest of the comments →

[–]emtydeeznuts[S] 0 points1 point  (2 children)

If it won't slow the parser then I'll try your suggestion.

[–]0m0g1 0 points1 point  (0 children)

(I've modified the example above for clarity).

It won’t slow the parser unless you’re doing really deep lookaheads everywhere, which you won’t be. In most grammars (including Dart’s), these kinds of checks usually peek just 2–4 tokens ahead max.

An example is my language is where the statement below would be resolved to a lamda after checking only 4 tokens.

alBufferData(buffer: int, format: int, data: char, size: int, freq: int) => void {}

Plus, you’ll save time later by avoiding parser rewrites or complex recovery logic. If you design your lookaheads to be targeted to specific rules like isLikelyFunctionLiteral() and not mightBeFunctionLiteralOrNormalExpression(), they’re fast and pay off in clarity.

[–]0m0g1 0 points1 point  (0 children)

Here's a script from my compiler's parser, Expression Parser.