[antlr-interest] C grammar question

Stuart Maclean stuart at apl.washington.edu
Mon Sep 24 14:07:20 PDT 2012


Hi from a newbie.  I have been using Antlr3 for about 4 days.

First, a quick question.  is the mailing list archive searchable in any 
way??  I suspect not (those MailMan interfaces never seem to be), but 
perhaps I am just not seeing it.

My real question relates to the C grammar, bundled in 
examples-v3/java/C.  If I build it as is and run against the following 
input:

typedef void (*a2)(int i);

it will print that both 'a2' and 'i' are new types.  But only 'a2' is a 
new type here, 'i' should not be seen as a new type.  I can see that the 
way the 'isTypedef' info is being communicated from the 'declaration' 
rule to the 'direct_declarator' rule, but the logic is failing if the 
parser has to visit the

     '('  declarator ')'

branch of the direct_declarator rule. which it does for the input above. 
To suppress 'i' being seen as a new type, I added this action to the 
direct_declarator rule:

     |    '( declarator ')'
             { $declaration::isTypedef=false; }

but it seems like a hack and I am wondering if there is some cleaner way 
to do this.

A further question.  What does this mean (in the same C.g)?

type_id
     :   {isTypeName(input.LT(1).getText())}? IDENTIFIER

Is this a 'pre action'??  If so, what does the '?' mean?  I can't find 
any notes about what this construct represents?

Any help gratefully appreciated.

Stuart


More information about the antlr-interest mailing list