Improving Compiler Error Messages
Walter Bright
newshound1 at digitalmars.com
Mon May 3 10:43:15 PDT 2010
bearophile wrote:
> It's hard to answer similar questions in an objective way.
> In Python 2.x the line continuation is implicit if you are inside a parenthesis:
> print (x +
> 5)
The trouble with that, from a language perspective, is what does the grammar
look like? Since the newline is significant to parsing, it should be a token.
But inside ( ), there's a problem with it being a token, because now the grammar
is messed up by needing to accept an optional newline token in between any other
two tokens - but only if inside ( ).
The obvious technical solution is to turn off recognition of newline tokens
inside of ( ). This is characterized as "smart" parsing, but I have a less kind
word for it - "hack" - because it means there's not a clean way to separate the
lexer from the parser, and not a clean way to express the grammar.
From a language user's perspective this probably doesn't matter, but these
kinds of things have a way of biting back in unanticipated nasty ways in the
future. For example, C++'s use of < > for templates is a similar hack in the
grammar. The C++ committee was warned at the time it was a very bad idea that
would cause all kinds of problems, but they went ahead anyway because they
thought it wouldn't affect users.
Turns out it did affect them, and it has caused a lot of grief over the years.
There's another hack in C++0x in an attempt to paper over the problem.
More information about the Digitalmars-d
mailing list