[antlr-interest] Problem when generating ANTLRv3.g for C Sharp target?

Mari Matinlassi mmatinlassi at icinetic.com
Wed Aug 10 01:17:35 PDT 2011

Thanks Sam!

After fixing the String issue I found 21 new errors.. However, after knowing
that the problem is an out-of-date grammar I managed to fix them too e.g.
"HIDDEN" -> "Hidden" and 
"(CommonTree)adaptor.create(.." -> "(CommonTree)adaptor.Create(.."

Now, going to continue with my experiments :-)



-----Original Message-----
From: Sam Harwell [mailto:sharwell at pixelminegames.com] 
Sent: Tuesday, August 09, 2011 4:18 PM
To: 'Mari Matinlassi'; antlr-interest at antlr.org
Subject: RE: [antlr-interest] Problem when generating ANTLRv3.g for C Sharp

Hi Mari,

I've never used ANTLRv3.g, so it may have errors and it's probably not
up-to-date with the latest ANTLR.g3 used in the C# port of the tool. The
CSharp3 target doesn't emit a "using System;" line, so you'll need to do one
of the following:

1. Change the definition of name in the scope{...} block of the rule 'rule'
from String to string.

2. Add the header block:

@parser::header {
using System;


-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Mari Matinlassi
Sent: Tuesday, August 09, 2011 4:31 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Problem when generating ANTLRv3.g for C Sharp

Dear fellows,


Our research project wants to create meta-language for defining domain
specific languages. And, we have chosen to take ANTLR as a tool and
ANTLRv3.g as a starting point for our meta-language.


Therefore, I want to generate ANTLRv3Parser.cs and ANTLRv3Lexer.cs and build
them in Visual Studio (using C# target). However, I have a build error as

"Error    1              The type or namespace name 'String' could not be
found (are you missing a using directive or an assembly reference?)
2151       10           Testi"


And, indeed, there is a line in ANTLRv3Parser.cs as follows:


protected sealed partial class rule_scope


              public String name;


              public rule_scope(ANTLRv3Parser grammar) { OnCreated(grammar);

              partial void OnCreated(ANTLRv3Parser grammar);



Any idea what I am doing wrong?


I have followed this document (http://www.antlr.org/download/CSharp3.pdf) to
install and configure my Visual Studio project to work with Antlr.


This works fine, thanks for excellent guide! I get a simple grammar (such as
one below) to generate lexer and parser and compile them successfully.

Example grammar:

-----------------------------------Start of

grammar T;











@lexer::namespace {ANTLRlanguage}

@parser::namespace {ANTLRlanguage}


public compileUnit 

       : ('x')+





       :      ('a'..'z' | 'A'..'Z' |'_')('a'..'z' | 'A'..'Z' |'0'..'9'|'_')*


-----------------------------------End of


Thanks for your help in advance,



List: http://www.antlr.org/mailman/listinfo/antlr-interest

More information about the antlr-interest mailing list