Example #1
0
        private void ReductionEvent(ReduceEventArgs pValue)
        {
            switch (pValue.Token.Symbol.ToString())
            {
                case "<Value>":
                    string Value = "";//pValue.Token.Tokens[0].ToString().Trim(new char[] { '{', '}' });
                    //System.Console.Write(Value);
                    this.NodeStack.Push(new TreeNode(Value));
                    break;
                case "<Negate Exp>":
                    System.Collections.Generic.LinkedListNode<string> Node = new System.Collections.Generic.LinkedListNode<string>("-");
                    //System.Console.Write("-");
                    TreeNode NegateNode = new TreeNode("-");
                    NegateNode.Right = this.NodeStack.Pop();
                    this.NodeStack.Push(NegateNode);
                    break;
                case "<Add Exp>":
                    //System.Console.Write("+");
                    TreeNode AddExpNode = new TreeNode("+");
                    AddExpNode.Right = this.NodeStack.Pop();
                    AddExpNode.Left = this.NodeStack.Pop();
                    this.NodeStack.Push(AddExpNode);
                    break;
                case "<Assign_Statement>":
                    string Identifier = "";//args.Token.Tokens[0].ToString().Trim(new char[] { '[', ']' });
                    //System.Console.Write(Identifier);
                    //System.Console.Write("=");
                    TreeNode AssignNode = new TreeNode("=");
                    this.TreeList.GetLast().Right = AssignNode;
                    AssignNode.Right = this.NodeStack.Pop();
                    AssignNode.Left = new TreeNode(Identifier);
                    this.NodeStack.Push(AssignNode);
                    break;
                case "<Statement>":
                    TreeNode Statement = new TreeNode("statement\n");
                    Statement.Right = this.NodeStack.Pop();
                    Statement.Left = this.NodeStack.Pop();
                    this.NodeStack.Push(Statement);
                    break;

                case "<StatementList>":
                    TreeNode StatementList = new TreeNode("sl\n");
                    StatementList.Right = this.NodeStack.Pop();
                    StatementList.Left = this.NodeStack.Pop();
                    this.NodeStack.Push(StatementList);
                    break;
                case "<Program>":
                    TreeNode Program = new TreeNode("program");
                    Program.Right = this.NodeStack.Pop();
                    Program.Left = this.NodeStack.Pop();
                    this.NodeStack.Push(Program);
                    break;
                default:
                    System.Console.WriteLine(pValue.Token.Symbol.ToString());
                    break;
            }
        }
Example #2
0
 public BinaryTree()
 {
     this.root = new TreeNode("start");
 }