CPP parser ambiguity

Robert Knight robertknight at gmail.com
Sat Apr 5 04:11:42 UTC 2008


Hello,

The CPP parser has an ExpressionOrDeclarationAST node for statements
which are valid as both expressions and declarations and there is then
some logic (IdentifierVerifier) to pick which one to use in the context
builder.

Section 6.8 of the C++ standard states:

"There is an ambiguity in the grammar involving expression-statement s
and declaration s: An expression-statement with
a function-style explicit type conversion (5.2.3) as its leftmost
subexpression can be indistinguishable from a declaration
where the first declarator starts with a (. In those cases the statement
is a declaration. "

Unless I am missing something, it seems like this AST is unnecessary.
In which case the parser could be changed to treat anything which
successfully parses as a declaration as a declaration and not anything
else.

I found this while investigating disappearing error messages from the
parser.  In Parser::parseExpressionOrDeclarationStatement() the parser
blocks all errors to prevent false errors when declarations are parsed
as exceptions or vice-versa.  Unfortunately this also leads to genuine
errors going missing.  

eg:

int foo =;

Doesn't report anything.  
 
Regards,
Robert.





More information about the KDevelop-devel mailing list