[antlr-interest] Bug in cgrammar

daniel_raichle daniel.raichle at etas.de
Wed Feb 4 02:58:37 PST 2004


I thing I found a bug in cgrammar.
I use GnuCParser.g to lex and parse the input file and GnuCEmitter.g
to print it out.

If I have the following input:

typedef struct { 
	unsigned char var1 ; 
} name1 ;
typedef struct { 
	unsigned char var2 ; 
} name2 ;

I get the following output:
typedef struct 0 
	unsigned char var1 ; 
} name1 ;
typedef struct 1 
	unsigned char var2 ; 
} name2 ;

Increasing numbers will be printed instead of "{".

I think the bug is in GnuCGrammar.g (and also in StdCGrammar.g) in the
rule "structOrUnionSpecifier". This rule should be changed like this
(two statements were outcommented):

structOrUnionSpecifier
  { String scopeName; }
  : sou:structOrUnion!
    ( ( ID LCURLY )=> i:ID l:LCURLY
      {
       scopeName = #sou.getText() + " " + #i.getText();
//     #l.setText(scopeName);
       pushScope(scopeName);
      }
      ( structDeclarationList )?
      { popScope();}
      RCURLY
     |   l1:LCURLY
       {
        scopeName = getAScopeName();
//      #l1.setText(scopeName);
        pushScope(scopeName);
       }
       ( structDeclarationList )?
        { popScope(); }
       RCURLY
     | ID
     )
     { ## = #( #sou, ## );}
     ;

In GnuCEmitter.g the rule "structOrUnionBody" should be changed like
this (I changed: 'print("{");' to: 'print(lc1);'):

structOrUnionBody
 : ( (ID LCURLY) => i1:ID lc1:LCURLY
     { print( i1 ); print ( lc1 ); tabs++; }
   ( structDeclarationList )?
     rc1:RCURLY { tabs--; print( rc1 ); }
   | lc2:LCURLY { print( lc2 ); tabs++; }
     ( structDeclarationList )?
     rc2:RCURLY { tabs--; print( rc2 ); }
   | i2:ID { print( i2 ); }
   );

It seems that it works correct now but it would be better if someone
other could check the changes, too.


 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/antlr-interest/

To unsubscribe from this group, send an email to:
 antlr-interest-unsubscribe at yahoogroups.com

Your use of Yahoo! Groups is subject to:
 http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list