[antlr-interest] Another problem in C grammar

Kamil Burzynski nopik at data.pl
Tue Apr 8 06:03:04 PDT 2008


Hi,

 I have solved the problem in quite ugly (but working :)) way: just 
introduced
global variable parameter_list_nesting_level initialized to 0 and following 
operations on it:
a) increment at start of parameter_list
b) decrement at end of parameter_list
c) in declarator, modified if( $declaration.isTypedef ) to check also 
parameter_list_nesting_level == 0.

Now it seem to be working.

"Kamil Burzynski" <nopik at data.pl> napisał(a):
> Hello,
>
>  I have just hit on the problem of example C grammar. It is using
> isTypedef
> boolean hack to build type list. While it is working quite good, it do
> define too much. Namely, I got such sample input:
>
> typedef void (*a)( int b, int c );
> typedef union _d d;
> union _d
> {
>   int b;
> };
>
> Parser fails on it. Before failing, it outputs, that type 'b' and type
> 'c'
> were defined. Which is obviously wrong (they do not define types). And
> since 'b' is type, 'int b' cannot be inside of union declaration, so
> fail.
> The isTypedef boolean is being read just after IDENTIFIER, which is
> unfortunately overkill - as in single typedef declaration there are many
>
> identifiers possible ;( I had not found solution yet, though it should be 

>
> easy to find it (and problem is definitely solvable :D).
>
> --
> Best regards from
> Kamil Burzynski




-- 
Best regards from
Kamil Burzynski



More information about the antlr-interest mailing list