[antlr-interest] RE: ANTLR Optional statements

David Wigg wiggjd at sbu.ac.uk
Mon Apr 8 08:42:23 PDT 2002


Many thanks to Monty and Ric for your responses to previous messages on
this subject.

We are trying to convert a C++ parser from PCCTS to ANTLR (2.7.2a2) (to
generate C++ code) but finding frustrating differences between the two
systems. I presume no one has listed these differences.

The lack of hoisting seems to me to create more problems than it solves.
I echo John Mitchell's cry "When will ANTLR support hoisting?"

To remind you of our current problem, in cplusplus.g we have,

external_declaration
    :
    |  ( {TYPEDEF | template_head } class_head LCURLY )?
       ...
    |
    ;

class_head
    :  ( STRUCT
       | UNION
       | CLASS
       )
       {ID {base_clause} }
    ;

which works fine in PCCTS because the optional statements at the end
produce a genuine conditional statement using "if (condition) etc."

For ANTLR we have converted this to,

class-head
    :  ( STRUCT
       | UNION
       | CLASS
       )
       (ID (base_clause)? )?
    ;

However, the optional statements shown at the end of this production
no longer produce an optional construction ("if" statement) because
optional statements now need to know what could legitimately follow as
well. Unfortunately, in our case, ANTLR seems to have forgotten that
LCURLY has to follow this, and throws a NoViableAltException (because
there is no alternative to ID (other than EOF).

Is this correct? If so, we will have to recast the g file somehow.

Thanks for your help.

David,
South Bank University
London, UK.

 

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



More information about the antlr-interest mailing list