Example #1
0
        /// <summary>
        /// Formats and prints the resulting <see cref="ChangeList{T}"/> from a <see cref="DiffTrees(JsonNode, JsonNode)"/>.
        /// </summary>
        /// <returns>
        /// A string representation of the change list.
        /// </returns>
        public static string PrintTreeChangeList(ChangeList <JsonNode> changeList)
        {
            var treeToPrint = new PrintNode();

            for (int i = 0; i < changeList.Count; ++i)
            {
                var change = changeList[i];
                var node   = change.Value;
                var path   = new LinkedList <string>();
                // Use "it.Parent != null" instead of "it != null" to
                // ignore printing the root parent node that matches the opening bracket
                // for all JSON objects
                for (var it = node; it.Parent != null; it = it.Parent)
                {
                    path.AddFirst(it.Name);
                }

                var printNode = treeToPrint;
                // Build a tree of the change list values, placing nodes based off
                // their positions in the old or new tree
                foreach (var pathAtom in path)
                {
                    if (!printNode.Children.ContainsKey(pathAtom))
                    {
                        printNode.Children.Add(pathAtom, new PrintNode());
                    }

                    printNode = printNode.Children[pathAtom];
                }

                printNode.ChangedNodes.Add(change);
            }

            return(treeToPrint.ToString());
        }
 public void visitPrint(PrintNode node)
 {
     foreach (INode child in node.getChildren())
     {
         child.accept(this);
     }
 }
 internal PrintNode(TreeNode <T> source, int index, int of, PrintNode <T> parent)
 {
     Source = source;
     Index  = index;
     Of     = of;
     Parent = parent;
 }
Example #4
0
        public void PreetyPrint()
        {
            var printList = new List<PrintNode>();
            var queue = new Queue<Node>();
            var parentNode = new PrintNode { val = Root.value, row = 1, childType = Child.NONE };
            queue.Enqueue(Root);
            printList.Add(parentNode);
            while (queue.Count > 0)
            {
                var cur = queue.Dequeue();
                if (cur.left != null)
                {
                    var leftChild = new PrintNode { val = cur.left.value, childType = Child.LEFT, parent = printList.First(x => x.val == cur.value) };
                    leftChild.row = leftChild.parent.row + 1;
                    queue.Enqueue(cur.left);
                    printList.Add(leftChild);
                }
                if (cur.right != null)
                {
                    var rightChild = new PrintNode { val = cur.right.value, childType = Child.RIGHT, parent = printList.First(x => x.val == cur.value) };
                    rightChild.row = rightChild.parent.row + 1;
                    queue.Enqueue(cur.right);
                    printList.Add(rightChild);
                }
            }
            var levelCount = printList.Max(x => x.row);
            int maxColumn = (int)Math.Pow(2, levelCount) - 1;
            int level = 1;
            int curColumn = 0;
            foreach (var node in printList)
            {
                if (node.row > level)
                {
                    Console.WriteLine();
                    ++level;
                    curColumn = 0;
                }
                if (level == 1)
                {
                    node.column = maxColumn / 2 + 1;
                }
                else
                {
                    int diff = (int)Math.Pow(2, levelCount - node.row);
                    if (node.childType == Child.LEFT)
                    {
                        diff = -diff;
                    }
                    node.column = node.parent.column + diff;
                }

                for (; curColumn < node.column-1; ++curColumn)
                {
                    Console.Write("  ");
                }
                Console.Write(string.Format("{0:00}",node.val));
                ++curColumn;
            }
            Console.WriteLine();
        }
Example #5
0
        private static void ParseNodePrint(Node root, TokenStream stream)
        {
            var node = new PrintNode("");

            root.AddChildNode(node);

            var parameter = stream.Pop();

            while (parameter.TokenType == SemanticTokenType.NodeParameter)
            {
                var argumentValue = stream.Pop();
                if (parameter.TokenValue == "text:")
                {
                    node.Text = argumentValue.TokenValue;
                }
                else
                {
                    throw new Exception("Unknown parameter:" + parameter.TokenValue);
                }

                var nexttype = stream.GetCurrent().TokenType;
                if (nexttype != SemanticTokenType.NodeParameter)
                {
                    break;
                }
                parameter = stream.Pop();
            }
        }
Example #6
0
 public override void VisitPrintNode(PrintNode p)
 {
     foreach (var x in p.ExprList.ExprChildren)
     {
         var exprTmpName = Gen(x);
         GenCommand("", "print", exprTmpName, "", "");
     }
 }
Example #7
0
        public void VisitPrintNode(PrintNode a)
        {
            string label = Mark(a);

            _nodes.AppendLine($"{label}  [label = \"Print: exprList\"]");

            a.ExprList.Visit(this);

            _edges.AppendLine($"{label} -> {Mark(a.ExprList)}");
        }
    public override void Enable()
    {
        printNode = nodeTarget as PrintNode;

        printLabel = new Label();
        controlsContainer.Add(printLabel);

        nodeTarget.onProcessed += UpdatePrintLabel;

        UpdatePrintLabel();
    }
        public void visitPrint(PrintNode printNode)
        {
            this.typeStack.Clear();
            printNode.getChildren()[0].accept(this);
            MiniPLTokenType type = this.typeStack.Pop();

            this.typeStack.Clear();
            if (type != MiniPLTokenType.TYPE_IDENTIFIER_INTEGER && type != MiniPLTokenType.TYPE_IDENTIFIER_STRING)
            {
                throw new SemanticException("Print statement can print only integers and strings.");
            }
        }
Example #10
0
        private IList <IList <int> > print(TreeNode node)
        {
            var pN = new PrintNode(node, 1);
            Queue <PrintNode> q = new Queue <PrintNode>();

            q.Enqueue(pN);

            var res      = new List <IList <int> >();
            var preLevel = -1;
            var cur      = new List <int>();

            while (q.Count != 0)
            {
                var e = q.Dequeue();
                if (preLevel != e.Level)
                {
                    cur = new List <int>();
                    res.Add(cur);
                    preLevel = e.Level;
                }
                cur.Add(e.Node.value);

                if (e.Level % 2 == 0)
                {
                    if (e.Node.left != null)
                    {
                        q.Enqueue(new PrintNode(e.Node.left, e.Level + 1));
                    }
                    if (e.Node.right != null)
                    {
                        q.Enqueue(new PrintNode(e.Node.right, e.Level + 1));
                    }
                }
                else //print from right to left.
                {
                    if (e.Node.right != null)
                    {
                        q.Enqueue(new PrintNode(e.Node.right, e.Level + 1));
                    }
                    if (e.Node.left != null)
                    {
                        q.Enqueue(new PrintNode(e.Node.left, e.Level + 1));
                    }
                }
            }

            return(res);
        }
        public void visitPrint(PrintNode printNode)
        {
            INode expression = printNode.getChildren()[0];

            expression.accept(this);
            if (this.intType)
            {
                this.inputOutput.output(popInt());
                this.intType = false;
            }
            else if (this.strType)
            {
                this.inputOutput.output(popString());
                this.strType = false;
            }
        }
Example #12
0
        public override void VisitPrintNode(PrintNode node)
        {
            node.Expression.Visit(this);

            //"print" operation in my language is System.Console.WriteLine method call
            var systemName     = IdentifierName("System");
            var consoleName    = IdentifierName("Console");
            var writeLineName  = IdentifierName("WriteLine");
            var printStatement = ExpressionStatement(
                InvocationExpression(MemberAccessExpression(
                                         SyntaxKind.SimpleMemberAccessExpression,
                                         MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, systemName, consoleName),
                                         writeLineName
                                         )).AddArgumentListArguments(Argument(expressions.Pop()))
                );

            AddStatementToCurrentBlock(printStatement);
        }
        public override void VisitPrintNode(PrintNode pr)
        {
            TACNodes.Print print = null;
            foreach (var expr in pr.ExprList.ExprList)
            {
                print = new TACNodes.Print
                {
                    Data = RecAssign(expr),
                    Sep  = " "
                };
                code.AddNode(print);
            }

            if (print != null)
            {
                print.Sep = Environment.NewLine;
            }
        }
Example #14
0
        private void Parsing(PrintNode node, StringBuilder sb, ref int lineNum)
        {
            Parsing(node.GetChild(0) as dynamic, sb, ref lineNum);

            PrintCommand(sb, $"call void [mscorlib]System.Console::Write({typeVar})", ref lineNum);
        }
 public override void VisitPrintNode(PrintNode p)
 {
     PreVisit(p);
     p.ExprList.Visit(this);
     PostVisit(p);
 }
 public void Visit(PrintNode node)
 {
     node.Children[0].Accept(this);
     switch (node.Children[0].NodeType())
     {
         case VariableType.INTEGER:
             Emit(Bytecode.PRINT_INT);
             break;
         case VariableType.STRING:
             Emit(Bytecode.PRINT_STRING);
             break;
         default:
             throw new InternalCompilerError("Invalid type for print statement");
     }
 }
 /// <summary>
 /// Посещение узла с оператором печати
 /// </summary>
 /// <param name="p">Узел PrintNode</param>
 public virtual void VisitPrintNode(PrintNode p)
 {
     Text += IndentStr() + "print(";
     p.ExprList.Visit(this);
     Text += ")";
 }
Example #18
0
 private void Parsing(PrintNode node, string methodName)
 {
     Parsing(node.GetChild(0) as dynamic, methodName);
     //AddID((IDNode)node.GetChild(0), methodName);
 }
 public virtual void VisitPrintNode(PrintNode pr)
 {
     pr.ExprList.Visit(this);
 }
Example #20
0
        private static Node ConstuctNode(BinaryReader br, Guid id, NodeType nodeType, CommandType commandType)
        {
            //Console.WriteLine(nodeType);
            switch (nodeType)
            {
            case NodeType.Script:
            {
                var scriptNode = new ScriptNode();
                scriptNode.Id = id;
                scriptNode.readData(br);
                return(scriptNode);
            }

            case NodeType.Page:
            {
                var pageNode = new PageNode();
                pageNode.Id = id;
                pageNode.readData(br);
                return(pageNode);
            }

            case NodeType.OnceOnly:
            {
                var onceOnly = new OnceOnlyNode();
                onceOnly.Id = id;
                onceOnly.readData(br);
                return(onceOnly);
            }

            case NodeType.ConditionalTrue:
            {
                var node = new ConditionalTrueNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.ConditionalFalse:
            {
                var node = new ConditionalFalseNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.OptionsChoice:
            {
                var node = new ShowOptionsNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.Option:
            {
                var node = new OptionNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.ParallelNode:
            {
                var node = new ParallelNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.BlockNode:
            {
                var node = new BlockNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.Command:
            {
                switch (commandType)
                {
                case CommandType.Say:
                {
                    var command = new SayNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.CallPage:
                {
                    var command = new CallPageNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Return:
                {
                    var command = new ReturnNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Wait:
                {
                    var command = new WaitNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Print:
                {
                    var command = new PrintNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                default:
                    throw new Exception("Unhandled Node Type:" + nodeType + ":" + commandType);
                }
            }

            // case NodeType.Say
            default:
                throw new Exception("Unhandled Node Type:" + nodeType);
            }
            return(null);
        }
Example #21
0
 public IEnumerable <StatementNode> Visit(PrintNode node)
 => Flatten(node.Value)
 .Append(node);
Example #22
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public RecursionState(PrintNode printNode, int level, string name)
 {
     PrintNode = printNode;
     Level     = level;
     Name      = name;
 }
        public void Visit(PrintNode node)
        {
            if (node.Children.Count != 1)
            {
                throw new InternalCompilerError("Invalid child count for print node");
            }

            HandleExpression(node.Children[0], new List<VariableType> { VariableType.INTEGER, VariableType.STRING });
        }
Example #24
0
        public void PreetyPrint()
        {
            var printList  = new List <PrintNode>();
            var queue      = new Queue <Node>();
            var parentNode = new PrintNode {
                val = Root.value, row = 1, childType = Child.NONE
            };

            queue.Enqueue(Root);
            printList.Add(parentNode);
            while (queue.Count > 0)
            {
                var cur = queue.Dequeue();
                if (cur.left != null)
                {
                    var leftChild = new PrintNode {
                        val = cur.left.value, childType = Child.LEFT, parent = printList.First(x => x.val == cur.value)
                    };
                    leftChild.row = leftChild.parent.row + 1;
                    queue.Enqueue(cur.left);
                    printList.Add(leftChild);
                }
                if (cur.right != null)
                {
                    var rightChild = new PrintNode {
                        val = cur.right.value, childType = Child.RIGHT, parent = printList.First(x => x.val == cur.value)
                    };
                    rightChild.row = rightChild.parent.row + 1;
                    queue.Enqueue(cur.right);
                    printList.Add(rightChild);
                }
            }
            var levelCount = printList.Max(x => x.row);
            int maxColumn  = (int)Math.Pow(2, levelCount) - 1;
            int level      = 1;
            int curColumn  = 0;

            foreach (var node in printList)
            {
                if (node.row > level)
                {
                    Console.WriteLine();
                    ++level;
                    curColumn = 0;
                }
                if (level == 1)
                {
                    node.column = maxColumn / 2 + 1;
                }
                else
                {
                    int diff = (int)Math.Pow(2, levelCount - node.row);
                    if (node.childType == Child.LEFT)
                    {
                        diff = -diff;
                    }
                    node.column = node.parent.column + diff;
                }

                for (; curColumn < node.column - 1; ++curColumn)
                {
                    Console.Write("  ");
                }
                Console.Write(string.Format("{0:00}", node.val));
                ++curColumn;
            }
            Console.WriteLine();
        }
 public override void VisitPrintNode(PrintNode p)
 {
     Text += IndentStr() + "print(";
     p.ExprList.Visit(this);
     Text += ");";
 }
Example #26
0
 public virtual void VisitPrintNode(PrintNode p)
 {
 }
Example #27
0
 public virtual void VisitPrintNode(PrintNode node)
 {
     node.Expression.Visit(this);
 }
Example #28
0
 public override void VisitPrintNode(PrintNode p) => Text += p.ToString();
        public ITreeNode Program()
        {
            ITreeNode programNode = new ErrorNode();

            switch (curTokenType)
            {
                case TokenType.BEGINBL:
                    Match(ref matchToken, TokenType.BEGINBL);
                    ITreeNode someStatement = Program();
                    BlockNode block = new BlockNode();
                    block.addStatement(someStatement);
                    while (curTokenType != TokenType.ENDBL)
                    {
                        someStatement = Program();
                        block.addStatement(someStatement);
                    }
                    Match(ref matchToken, TokenType.ENDBL);
                    programNode = block;
                    break;
                case TokenType.LABEL:
                    Match(ref matchToken, TokenType.LABEL);
                    LabelNode labeledBlock = new LabelNode(matchToken.getValue());
                    ITreeNode labeledStatement;
                    do
                    {
                        labeledStatement = Program();
                        labeledBlock.addStatement(labeledStatement);
                    }
                    while (curTokenType != TokenType.EOF);
                    programNode = labeledBlock;
                    break;
                case TokenType.INTDEC:
                    Match(ref matchToken, TokenType.INTDEC);
                    Match(ref matchToken, TokenType.ID);
                    programNode = new IdentifierDeclarationNode(IdentifierType.INT, matchToken.getValue());
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.BOOLDEC:
                    Match(ref matchToken, TokenType.BOOLDEC);
                    Match(ref matchToken, TokenType.ID);
                    programNode = new IdentifierDeclarationNode(IdentifierType.BOOL, matchToken.getValue());
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.FOR:
                    Match(ref matchToken, TokenType.FOR);
                    Match(ref matchToken, TokenType.LPAREN);
                    AssignmentNode init = (AssignmentNode)Program();
                    AssignmentNode step = (AssignmentNode)Program();
                    BooleanExpressionNode condition = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    BlockNode forBody = (BlockNode)Program();
                    programNode = new ForNode(init, step, condition, forBody);
                    break;
                /*case TokenType.FUN:
                    Match(ref matchToken, TokenType.FUN);
                    IdentifierNode id = (IdentifierNode)Factor();
                    programNode = new FunctionNode(id);
                    Match(ref matchToken, TokenType.EOS);
                    break;*/
                case TokenType.GOTO:
                    Match(ref matchToken, TokenType.GOTO);
                    Match(ref matchToken, TokenType.ID);
                    IdentifierNode gotoLabel = new IdentifierNode(matchToken.getValue(), IdentifierType.LABEL);
                    programNode = new GotoNode(gotoLabel);
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.ID:
                    Match(ref matchToken, TokenType.ID);
                    IdentifierNode assignId = new IdentifierNode(matchToken.getValue(), IdentifierType.UNKNOWN);
                    Match(ref matchToken, TokenType.ASSIGN);
                    BooleanExpressionNode assignValue = (BooleanExpressionNode)BooleanExpression();
                    programNode = new AssignmentNode(assignId, assignValue);
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.IF:
                    Match(ref matchToken, TokenType.IF);
                    ITreeNode thenBranch;
                    ITreeNode elseBranch;

                    Match(ref matchToken, TokenType.LPAREN);
                    BooleanExpressionNode ifCondition = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    Match(ref matchToken, TokenType.THEN);
                    thenBranch = (BlockNode)Program();
                    if (curTokenType == TokenType.ELSE)
                    {
                        Match(ref matchToken, TokenType.ELSE);
                        elseBranch = (BlockNode)Program();
                    }
                    else
                    {
                        elseBranch = new BlankNode();
                    }
                    programNode = new IfNode(ifCondition, thenBranch, elseBranch);
                    break;
                /*case TokenType.LET:
                    Match(ref matchToken, TokenType.LET);
                    IdentifierNode shortId = (IdentifierNode)Factor();
                    Match(ref matchToken, TokenType.ASSIGN);
                    BooleanExpressionNode subst = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.IN);
                    BooleanExpressionNode target = (BooleanExpressionNode)BooleanExpression();
                    programNode = new LetNode(shortId, subst, target);
                    Match(ref matchToken, TokenType.EOS);
                    break;*/
                case TokenType.PRINT:
                    Match(ref matchToken, TokenType.PRINT);
                    Match(ref matchToken, TokenType.LPAREN);
                    BooleanExpressionNode printArgument = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    programNode = new PrintNode(printArgument);
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.WHILE:
                    Match(ref matchToken, TokenType.WHILE);
                    Match(ref matchToken, TokenType.LPAREN);
                    BooleanExpressionNode whileCondition = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    BlockNode whileBody = (BlockNode)Program();
                    programNode = new WhileNode(whileCondition, whileBody);
                    break;
                case TokenType.EOF:
                    programNode = new BlankNode();
                    break;
                default:
                    Expect(TokenType.UNKNOWN, lookAheadToken);
                    break;
            }
            return programNode;
        }