[antlr-interest] antlr-interest Digest, Vol 94, Issue 25
John D. Mitchell
jdmitchell at gmail.com
Tue Sep 25 12:40:21 PDT 2012
On Sep 25, 2012, at 12:00 , antlr-interest-request at antlr.org wrote:
> From: Stuart Maclean <stuart at apl.washington.edu>
> Subject: [antlr-interest] C grammar question
> To: antlr-interest at antlr.org
> Message-ID: <5060CB88.9040406 at apl.washington.edu>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> 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.
http://antlr.markmail.org/
> 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.
At the top of that grammar is a note from Ter about the simplified use of a symbol table for dealing with types so it's not too much of a surprise that it's over permissive in this case.
> 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?
That's a "semantic predicate". Check out the antlr docs for more info.
Cheers,
John
More information about the antlr-interest
mailing list