[antlr-interest] More problems with ANTRL C#3 target and tools

Sam Harwell sharwell at pixelminegames.com
Fri Oct 21 12:55:12 PDT 2011


For the first problem, you probably have your grammar and helper files in
different namespaces. It looks like you're using a combined grammar, which
means you'll want this in the grammar:

@lexer::namespace{Namespace.Goes.Here}
@parser::namespace{Namespace.Goes.Here}

Then you'll use a matching namespace in your partial file.

 

For the second problem, just declare the rule public as mentioned in section
5.2 of the documentation:

http://www.antlr.org/wiki/display/ANTLR3/Antlr3CSharpReleases

 

Thanks,

Sam

 

 

From: Voelkel, Andy [mailto:andy.voelkel at plantronics.com] 
Sent: Friday, October 21, 2011 2:10 PM
To: antlr-interest at antlr.org
Cc: Sam Harwell (sharwell at pixelminegames.com)
Subject: More problems with ANTRL C#3 target and tools

 

Hi,

I got over a first round of problems and got a few trivial example working.
I then moved on to trying to convert on of the examples from "The Definitive
Guide to ANTLR" from Java-compatible to C# compatible:

http://media.pragprog.com/titles/tpantlr/code/tour/eval/Expr.g

It is a simple calculator example, before he introduces ASTs.

I have run into two problems. The first seems to be related to Sam's visual
studio integration tools, and particularly to the use of partial classes.
This seems in some cases to cause this error:

K:\Plantronics\Development
Sandbox\ANTLR\AntlrTest\AntlrTest3\Program.cs(13,30): error CS1729:
'AntlrTest3.Combined1Lexer' does not contain a constructor that takes 1
arguments

One of the partial class definitions for Combined1Lexer does not indicate
that Combined1Lexer inherits from Lexer and that presumably causes the
constructor not to be found. If I remove the file containing the partial
class definition from the project, that problem goes away. The funny thing
is that this problem seems to happen on some projects and not others, which
is weird. Another weird thing is that explicitly changing the partial class
definition to inherit from Lexer causes a different problem:

K:\Plantronics\Development
Sandbox\ANTLR\AntlrTest\AntlrTest3\Combined1.g3.lexer.cs(5,17): error
CS0534: 'AntlrTest3.Combined1Lexer' does not implement inherited abstract
member 'Antlr.Runtime.Lexer.mTokens()'

 

The second problem is that the example code in the book contains a call to
one of the rules, in my code this looks like this:

Combined1Parser parser = new Combined1Parser(tokens);

// Begin parsing at rule prog

parser.prog();

 

But the generated code for CombinedParser defines prog() as being a private
method, meaning that I can't call it. Can someone explain this?

 

Just when it looks like I'm gaining traction, I run into more weird stuff.

 

-    Andy

 

P.S. I've run this example in Antlrworks with the Java-compatible version,
and everything works fine, so these problems all seem to be related to the
C# target. 

 

 

 

  _____  


CONFIDENTIALITY NOTICE: This e-mail transmission, and any documents, files
or previous e-mail messages attached to it, may contain information that is
confidential and/or legally privileged. If you are not the intended
recipient, or a person responsible for delivering it to the intended
recipient, please DO NOT disclose the contents to another person, store or
copy the information in any medium, or use any of the information contained
in or attached to this transmission for any purpose. If you have received
this transmission in error, please immediately notify the sender by reply
email or at privacy at plantronics.com, and destroy the original transmission
and its attachments without reading or saving in any manner.

For further information about Plantronics - the Company, its products,
brands, partners, please visit our website www.plantronics.com.



More information about the antlr-interest mailing list