Hello,
first ... sorry for my bad english! ;)
I've created an Antlr AST with Antlr v2.
Unfortunately, I had to use Antlr v2 because of the old Syntax of the Grammar I used (
CIL-Grammar from Pascal Lacroix). Now I want to read every node, because I want to convert the AST into a kind of xml-Format.
I need something like that:
Foreach (node in AST) {
String nodeStr = node.getName
....
}
That is my Code for creating the AST:
public static void Main(
string[] args)
{
string filename =
@"file.il";
if (args.Length >
0)
{
filename = args[
0];
}
if (!File.
Exists(filename))
{
Console.
WriteLine(
"Input file '{0}' doesn't exist.", filename);
return;
}
StreamReader stream =
new StreamReader(filename);
CILLexer lexer =
new CILLexer(stream);
CILParser parser =
new CILParser(lexer);
try
{
parser.
start();
Console.
WriteLine(
"Parsing: OK");
AST root = parser.
getAST();
// HERE I WANT TO READ THE AST 'root' and CONVERT HIM!
antlr.debug.misc.ASTFrame frame = new antlr.debug.misc.ASTFrame("AST", root);
frame.ShowDialog();
}
catch (Exception ex)
{
Console.
WriteLine(
"Exception during parsing: " + ex.
ToString());
}
}
Is there a method in ANTLR v2 by which I can pass through the tree?Kind Regards,
Mario