I know, this is the well-known lexer hack. I still don't see how the syntax I've proposed is supposed to be any more problematic than conventional C syntax.
Posted Jul 2, 2012 20:36 UTC (Mon) by tjc (subscriber, #137)
[Link]
The type specifier in a C declaration acts as a surrogate for the missing 'var' or 'func' keyword, which makes it possible for the parser to recognize the declaration without requesting a lot of extra tokens from the lexer.
Why learn C? (O'Reilly Radar)
Posted Jul 2, 2012 21:23 UTC (Mon) by HelloWorld (guest, #56129)
[Link]
I think that this is only a problem when using top-down parsers. A bottom-up parser should handle this situation easily.
Why learn C? (O'Reilly Radar)
Posted Jul 3, 2012 15:46 UTC (Tue) by tjc (subscriber, #137)
[Link]
Yes, it could be made to work, but it would have to be a backtracking parser, and it would probably be slow. Most bottom-up parsers (such as those produced by bison) are LALR(1), which only has one token look-ahead.