I'm working on a JS Analizer, but I found a library called Esprima.NET and I started to analize the code but there is lot of code to read and It will take me months to get its algorithm. Well, I have finished the Lexical Analyzer but right now I am struggling on the Syntax Analyzer and I noticed that the parse method returns a node of nodes forming an abstract tree. I don't know how to print the nodes like a tree.
This is my code:
main.cs
static StreamReader file = new StreamReader(@"prueba.js");
static void Main(string[] args)
{
var esprima = new Esprima.NET.Esprima();
var code = file.ReadToEnd();
//var tokenize = esprima.tokenize(code, new Options());
var node = esprima.parse(code, new Options());
Console.WriteLine(node);
Console.ReadLine();
}
Esprima.cs (I will just show the parser method and its references)
public Node parse(string code, Options options)
{
//Here goes the logic of parsing options, but I deleted it
//just for simplify large code
var program = parseProgram();
return program;
}
//here goes the node
public Node parseProgram()
{
List<Node> body;
Node node;
peek();
node = new Node();
body = parseScriptBody();
return node.finishProgram(body, state.sourceType);
}