[antlr-interest] Problem when generating ANTLRv3.g for C Sharp target?
Sam Harwell
sharwell at pixelminegames.com
Tue Aug 9 07:18:00 PDT 2011
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;
}
Sam
-----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
target?
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
below:
"Error 1 The type or namespace name 'String' could not be
found (are you missing a using directive or an assembly reference?)
C:\VisualStudioProject\Testi\Testi\obj\Debug\ANTLRv3Parser.cs
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
T.g-----------------------------------------------------
grammar T;
options
{
language=CSharp3;
TokenLabelType=CommonToken;
output=AST;
ASTLabelType=CommonTree;
}
@lexer::namespace {ANTLRlanguage}
@parser::namespace {ANTLRlanguage}
public compileUnit
: ('x')+
;
IDENTIFIER
: ('a'..'z' | 'A'..'Z' |'_')('a'..'z' | 'A'..'Z' |'0'..'9'|'_')*
;
-----------------------------------End of
T.g--------------------------------------------------
Thanks for your help in advance,
Mari
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list