[cfe-dev] Writing a tentative parser for C++0x attributes

Argyrios Kyrtzidis kyrtzidis at apple.com
Sat Aug 15 23:06:57 PDT 2009


On Aug 14, 2009, at 3:00 AM, Sean Hunt wrote:

>
>> About the patch, since attributes appear before statements &
>> declarations, I suggest parsing them at
>> Parser::ParseStatementOrDeclaration() before going into the "stmt or
>> decl" parsing part. That way you will parse them once
>> and then pass the AttributeList* to the statement parsing methods,
>> instead of parsing them at each one.
>>
>> Then for the decl/stmt ambiguity part, you only need to check for
>> attributes in Parser::TryParseDeclarator().
>
> The problem with this approach is that parsing them in
> ParseStatementOrDeclaration() requires me to pass the attributes to
> ParseDeclaration(), and then move the attribute check out of
> ParseDeclaration() into its other two callers, when that check clearly
> belongs in that function (it's called by
> Parser::ParseStatementOrDeclaration(),
> Parser::ParseCompoundStatementBody(), and
> Parser::ParseExternalDeclaration(), and the latter calls
> Parser::ParseDeclarationOrFunctionDefinition(), which currently does  
> the
> attribute check and itself has 2 other callers).

How about doing attribute checking in ParseDeclaration() unless the  
AttributeList* parameter is not null
which means that the caller already did attribute parsing (e.g the  
ParseStatementOrDeclaration() caller).

The main reason for doing attribute checking in  
ParseStatementOrDeclaration() is that it's much preferable to
avoid tentative parsing if possible. If we push attribute checking  
into the tentative parser then we will
start tentative parsing every time an attribute is encountered, and  
not just when there is an actual decl/stmt
ambiguity.

-Argiris



More information about the cfe-dev mailing list