[antlr-interest] ANTLR and C# parser
tdknghi
nk.truong at student.qut.edu.au
Tue Jan 13 15:54:48 PST 2004
Hi,
I have to build a C# parser based on ANTLR as part of my project. I
succeeded to run nant to build the release version of ANTLR for C#
(based on the ANTLR Documentation section). My questions are:
1. With the csharp grammar provided by Rajendra Kumar Komandur (from
the ANTLR website), parser that is generated from that grammar is in
Java or C#?
_ I ran java antlr.Tool csharp.g and the following Java classes
are generated:
* GeneratedCSharpRecognizer.java
* GeneratedCSharpLexer.java
* GeneratedCSharpTokenTypes.java
* GeneratedCSharpTokenTypes.txt
_ Is it the correct behaviour that it's suppose to be?
2. I wrote a Main.java class (which listed below) to call those
generated classes that I mentioned in question 1. Here my Main class
import java.io.*;
import antlr.collections.AST;
import antlr.collections.impl.*;
import antlr.debug.misc.*;
import antlr.*;
import java.awt.event.*;
public class Main
{
public static void main(String[] args)
{
try
{
File f = new File(args[0]);
Reader r = new BufferedReader(new FileReader
(f));
// Create a scanner that reads from the
// input stream passed to us
GeneratedCSharpLexer lexer = new
GeneratedCSharpLexer(r);
lexer.setFilename(f.getName());
// Create a parser that reads from the
// scanner
GeneratedCSharpRecognizer parser = new
GeneratedCSharpRecognizer(lexer);
parser.setFilename(f.getName());
// start parsing at the compilationUnit rule
parser.compilationUnit();
}
catch(FileNotFoundException fnfe)
{
fnfe.printStackTrace();
}
catch(RecognitionException re)
{
re.printStackTrace();
}
catch(TokenStreamException tse)
{
tse.printStackTrace();
}
}
}
However i got the following error message:
"expected token: class"
when I attempt to parse a C# program using java Main mycsharp.cs
Do any of you have any idea what's wrong here? and how do I fix
it?
3. Is there anyway to make the provided csharp grammar to generated
C# parser class instead of Java class? I attempted to specify the
language option in the grammar file. However, I got error too.
Thanks a lot for your help.
MiMi
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list