[antlr-interest] C# Parser : problem with identifying a class declaration

Andreas Bartho andreas.bartho at inf.tu-dresden.de
Mon Jan 14 04:06:28 PST 2008


Hi,

I used to have that problem too. The reason was that somewhere in the 
class declaration (of the parsed C#-file) was a syntax error. ANTLR 
tried backtracking and finally, with delegate_declaration as its last 
alternative, produced the error message.

Try a syntactic predicate.

typedeclaration
     :   (attributes? classmodifiers? 'partial'? 'class')
         => classdeclaration
     |   (attributes? structmodifiers? 'partial'? 'struct')
         => structdeclaration
     |   (attributes? interfacemodifiers? 'partial'? 'interface')
         => interfacedeclaration
     |   (attributes? enummodifiers? 'enum')
         => enumdeclaration
     |   (attributes? delegatemodifiers? 'delegate')
         => delegatedeclaration
     ;


Hopefully the error reported will now be reported inside the class 
declaration.

Be warned, though, that there is still a lot of trouble waiting for you.
You might want to have a look at my grammar (which I'm still not sure 
does everything as it should, but currently it works for me.)
http://deftproject.svn.sourceforge.net/viewvc/*checkout*/deftproject/depth/com.comarch.depth.antlrcsharp/CSharp.g?revision=41

It is published under the Eclipse Public License.

Hope that helps
Andreas


More information about the antlr-interest mailing list