public static void Main(string[] args) { NLP_Lexer.Lexer nlpLexer = new NLP_Lexer.Lexer(ACCESS_TOKEN); // Test input string inp_a = "print add 4 and 5"; string lex_chunk_a = nlpLexer.Tokenise(inp_a); Console.WriteLine("Input = \n\t" + inp_a); Console.WriteLine(lex_chunk_a); try { CoreParser.Lexer lexer = new CoreParser.Lexer(lex_chunk_a); lexer.Tokenise(); List <Token> tokens = lexer.getTokenList(); CoreParser.Parser.Parser parser = new CoreParser.Parser.Parser(); CoreParser.Parser.AST.Node ast = parser.Parse(tokens); Engine.Engine engine = new Engine.Engine(); engine.Run(ast); } catch (Exception e) { Console.WriteLine(e.Message); } }
public ParseTreeDisplay(CoreParser.Parser.AST.Node node) : base(Gtk.WindowType.Toplevel) { this.ast = node; //Create draw area tree.ExposeEvent += OnExpose; this.Add(tree); this.Title = "Parse Tree"; //this.Build(); }
private void DisplayTree(CoreParser.Parser.AST.Node n, Cairo.Context ctx, Cairo.PointD currentPoint, int level, bool left, bool leftTree) { // Init width and height int width = 0; int height = 0; // Get window size this.GetSize(out width, out height); // Set y value double y = (level * 50) + 15; // initialise x value double x = 0; // Calculate x value if (level == 0) { x = (width) - 50; ctx.MoveTo(x, y); //ctx.ShowText(n.Token); } else { if (leftTree) { x = currentPoint.X - 50.0; } else { x = currentPoint.X + 45.0; } } if (n.HasChildren()) { // Get node's children int childrenLength = n.Children().Count; for (int i = 0; i < childrenLength; i++) { // loop over children and calc level CoreParser.Parser.AST.Node node = n.Children()[i]; y = ((level + 1) * 20) + 15; // Calculate left or right if (i % 2 == 0) { x = x - 50.0; if (node.HasChildren()) { DisplayTree(node, ctx, new Cairo.PointD { X = x + 45, Y = y, }, level + 1, true, true); } } else { x = x + 100.0; if (node.HasChildren()) { DisplayTree(node, ctx, new Cairo.PointD { X = x + 65, Y = y, }, level + 1, true, true); } } // Render the node's value to the window ctx.MoveTo(x, y); ctx.ShowText(node.Token.token); } } }