CPP parser ambiguity
Robert Knight
robertknight at gmail.com
Tue Apr 8 05:02:15 UTC 2008
Hi,
Sorry for the spam - I realised my misunderstanding here. I fixed the
missing errors by holding them in a buffer until after trying to parse
the statement as a declaration or expression and then only reporting
them to KDevelop if the attempt succeeds.
Regards,
Robert.
On Sat, 2008-04-05 at 05:11 +0100, Robert Knight wrote:
> 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