[antlr-interest] antlr-interest Digest, Vol 55, Issue 20

John D. Mitchell jdmitchell at gmail.com
Sat Jun 20 12:39:46 PDT 2009


For what it's worth, Ter's AnsiC grammar written in Antlrv3 is cool  
but really more of a example than a production bit of code.  If you're  
just wanting to learn, it's cool.  If you need more of a production  
approach, you might want to look at the GNU C package which has a StdC  
lexer and parser as its basis but, for good and bad, it's still  
written in Antlr v2.

Have a great weekend,
John

On Jun 20, 2009, at 12:00 , antlr-interest-request at antlr.org wrote:
> From: Mark Wright <markwright at internode.on.net>
> Subject: Re: [antlr-interest] Question about example Ansi C grammar
> 	for antlr v3
> To: Fredrik Ohrstrom <oehrstroem at gmail.com>
> Cc: antlr-interest at antlr.org
> Message-ID: <20090620113314.00004a38 at goanna>
> Content-Type: text/plain; charset=US-ASCII
>
> Hi Fredrik,
>
> I think the correct approach (for parsing an ambiguous language
> which requires symbol table knowledge to parse) is while
> parsing the code in the first parse, to:
>
> * insert each symbol into the symbol table, which needs to know
> all the scoping rules.
>
> * in each situation where the language is ambiguous, to use a
> dis-ambiguating semantic predicate to lookup the symbol in the
> symbol table, and based on the answer from the dis-ambiguating
> semantic predicates, the correct rule is selected.
>
> Thanks, Mark
>
> On Wed, 17 Jun 2009 16:19:28 +0200
> Fredrik Ohrstrom <oehrstroem at gmail.com> wrote:
>
>> Sadly enough ;-) , the following c-code compiles both using gcc and
>> cl.exe
>>
>> ---------------
>> typedef int alfa;
>> typedef int beta;
>>
>> struct { struct { int z; } alfa; } c;
>>
>> int main(int alfa)
>> {
>>   beta beta;
>> }
>> ---------------
>>
>> The example antlv3 c-parser found on the antlr homepage will wrongly
>> parse the alfa inside the struct as a type_id and not a
>> direct_declarator. In the same way it wrongly parses the argument
>> alfa and the function local beta.
>>
>> I have tried to extend the grammar to fix this, unfortunately I have
>> not been able to solve all the cases in the example, only the arg and
>> local var case.
>>
>> What is the correct way of solving this?
>>
>> //Fredrik



More information about the antlr-interest mailing list