dcsimg
ANTLR and C#
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, January 13, 2004 05:44 PM

Messages Messages Help Reply | Forward | View Source | Unwrap Lines | Delete Message 10556 of 10556 | Previous | Next [ Up Thread ] Message Index Msg # From: "tdknghi" Date: Wed Jan 14, 2004 10:54 am Subject: ANTLR and C# parser ADVERTISEMENT 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 i   More>>

Messages Messages Help

Reply | Forward | View Source | Unwrap Lines | Delete




Message 10556 of 10556 | Previous | Next [ Up Thread ] Message Index Msg #

From: "tdknghi"
Date: Wed Jan 14, 2004 10:54 am
Subject: ANTLR and C# parser


ADVERTISEMENT

			
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
   <<Less
About | Sitemap | Contact