What is the fastest (smaller code) way to get grammar tree ?
I am trying to get grammar tree. I've generated C# code based on my simple grammar:
grammar MyPascal;
options
{
language=CSharp3;
output=AST;
}
operator: (block | ID);
block : BEGIN operator* END;
BEGIN :'begin';
END :'end';
ID :('a'..'z')+;
WS :( ' '
| '\t'
| '\r'
| '\n'
) {$channel=HIDDEN;};
When i'am using ANTLR works for simple input text like:
input.txt:
begin
abs
qwe
begin
begin
end
end
end
i get nice picture of grammar tree.
Now i'am wonder if there any simple way to get tree structure of my "program" from C# without writing 1000s lines of code.
Here i'am trying to get grammar tree:
class Program
{
static void Main(string[] args)
{
MyPascalLexer lex = new MyPascalLexer(new ANTLRFileStream(@"M:\input.txt"));
CommonTokenStream tokens = new CommonTokenStream(lex);
MyPascalParser g = new MyMyPascalParser(tokens);
MyPascalParser.myprogram_return X = g.myprogram();
Console.WriteLine(X.Tree); // Writes: nill
Console.WriteLine(X.Start); // Writes: [@0,0:4='begin',<4>,1:0]
Console.WriteLine(X.Stop); // Writes: [@35,57:57='end',<19>,12:2]
}
}