public override void VisitWriteNode(WriteNode w)
 {
     if (depth < 0)
     {
         ++opCnt;
     }
 }
Exemple #2
0
 public override void VisitWriteNode(WriteNode w)
 {
     if (depth > 0)
     {
         Count += 1;
     }
 }
Exemple #3
0
 public void Visit(WriteNode n)
 {
     foreach (var node in n.GetChildren())
     {
         node.SymTable = n.SymTable;
         node.Accept(this);
     }
 }
Exemple #4
0
 public override void VisitWriteNode(WriteNode w)
 {
     if (w == null)
     {
         return;
     }
     w.Expr.Visit(this);
 }
Exemple #5
0
 public override void VisitWriteNode(WriteNode w)
 {
     if (NowCycle > 0)
     {
         CountOp += 1;
     }
     w.Expr.Visit(this);
 }
Exemple #6
0
 public override void VisitWriteNode(WriteNode w)
 {
     if (currCyc > 0)
     {
         opCnt++;
     }
     base.VisitWriteNode(w);
 }
        public void Visit(WriteNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.Accept(this);
            }
        }
Exemple #8
0
 public void Visit(WriteNode n)
 {
     PrintDOTIDLabel(n);
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
Exemple #9
0
 public override void Visit(WriteNode node)
 {
     WriteIndent();
     ProgramBuilder.Append(node.WriteLine ? "writeln" : "write");
     ProgramBuilder.Append('(');
     node.ExprList.Visit(this);
     ProgramBuilder.Append(')');
     NewLine();
 }
Exemple #10
0
        private void ProcessQueue(Action <string> _ErrorMessageAction, ManualResetEvent ProcessQueueWait, ConcurrentQueue <Node> ProcessQueue, EDeflateCompression QueueCompressMode)
        {
            BTaskWrapper.Run(() =>
            {
                try
                {
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Start processing Queue");
                    Dictionary <ENodeType, StreamStruct> WriteStreams = CreateStreams(QueueCompressMode);

                    using (XStreamWriter Writer = new XStreamWriter(WriteStreams))
                    {
                        while (!QueueComplete || ProcessQueue.Count > 0)
                        {
                            if (ProcessQueue.TryDequeue(out Node WriteNode))
                            {
                                if (WriteNode.GetNodeType() == ENodeType.Hierarchy)
                                {
                                    HierarchyNode CurrentHierarchyNode = (HierarchyNode)WriteNode;

                                    //Need to check that lists are not null
                                    CheckHierarchyNode(CurrentHierarchyNode);

                                    Writer.Write(CurrentHierarchyNode);
                                }

                                if (WriteNode.GetNodeType() == ENodeType.Geometry)
                                {
                                    GeometryNode CurrentGeometry = (GeometryNode)WriteNode;
                                    CheckGeometry(CurrentGeometry);

                                    Writer.Write((GeometryNode)WriteNode);
                                }

                                if (WriteNode.GetNodeType() == ENodeType.Metadata)
                                {
                                    Writer.Write((MetadataNode)WriteNode);
                                }
                            }
                            else
                            {
                                Thread.Sleep(10);
                            }
                        }
                        _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Closing Stream");
                    }
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Closed Stream");
                }
                catch (Exception ex)
                {
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] {ex.Message}\n{ex.StackTrace}");
                    State = FAILED_STATE;
                }

                ProcessQueueWait.Set();
            });
        }
Exemple #11
0
        public override void VisitWriteNode(WriteNode w)
        {
            Console.WriteLine(Tag + " VisitWriteNode");
            w.Expr.Visit(this);
            var printLine = new ThreeAddrLine();

            printLine.Label   = GenNewLabel();
            printLine.RightOp = GetLastLine().Accum;
            printLine.OpType  = ThreeAddrOpType.Write;
            Data.Add(printLine);
        }
 public override void VisitWriteNode(WriteNode w)
 {
 }
 public override void VisitWriteNode(WriteNode w)
 {
     Text += IndentStr() + "write(";
     w.Expr.Visit(this);
     Text += ")";
 }
Exemple #14
0
 public override void VisitWriteNode(WriteNode w)
 {
     ++CurrNestExprs;
     w.Expr.Visit(this);
     --CurrNestExprs;
 }
Exemple #15
0
 public override void VisitWriteNode(WriteNode w)
 {
     NestExpr++;
     w.Expr.Visit(this);
     NestExpr--;
 }
 public override void VisitWriteNode(WriteNode w)
 {
     base.VisitWriteNode(w);
 }
Exemple #17
0
 public override void VisitWriteNode(WriteNode w)
 {
     Text.Append(IndentStr() + "Console.WriteLine(");
     w.Expr.Visit(this);
     Text.Append(");");
 }
 public override void VisitWriteNode(WriteNode w)
 {
     w.Expr.Visit(this);
     genc.EmitWriteLine();
 }
Exemple #19
0
 public override void Visit(WriteNode node)
 {
     PreVisit(node);
     node.ExprList.Visit(this);
     PostVisit(node);
 }
Exemple #20
0
 public override void Visit(WriteNode node)
 {
     node.ExprList.Visit(this);
 }
Exemple #21
0
 public override void Visit(WriteNode node)
 {
     OnEnter(node);
     base.Visit(node);
     OnExit(node);
 }
        protected override void DoAction(int action)
        {
#pragma warning disable 162, 1522
            switch (action)
            {
            case 2: // start -> Program, block, EOF
#line 22 "D:\MINICompiler\kompilator.y"
            {
                if (syntaxErrorLines.Count != 0)
                {
                    YYAbort();
                }
                ProgramTree.block = ValueStack[ValueStack.Depth - 2] as BlockNode;
                ProgramTree.Line  = ValueStack[ValueStack.Depth - 3].Line;
            }
#line default
                break;

            case 3: // block -> OpenBracket, lines, CloseBracket
#line 34 "D:\MINICompiler\kompilator.y"
            {
                BlockNode node;
                if (ValueStack[ValueStack.Depth - 2] is null)
                {
                    node = new BlockNode();
                }
                else
                {
                    node = new BlockNode(ValueStack[ValueStack.Depth - 2] as BlockNode);
                }
                node.Line            = ValueStack[ValueStack.Depth - 3].Line;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 5: // lines -> lines, instruction
#line 44 "D:\MINICompiler\kompilator.y"
            {
                BlockNode node;
                if (ValueStack[ValueStack.Depth - 2] is null)
                {
                    node = new BlockNode();
                }
                else
                {
                    node = new BlockNode(ValueStack[ValueStack.Depth - 2] as BlockNode);
                }
                node.instructions.Add(ValueStack[ValueStack.Depth - 1]);
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 6: // lines -> EOF
#line 52 "D:\MINICompiler\kompilator.y"
            {
                syntaxErrorLines.Add(ProgramTree.LineCount);
                YYAbort();
            }
#line default
                break;

            case 11: // instruction -> exp, Semicolon
#line 62 "D:\MINICompiler\kompilator.y"
            {
                ExpressionNode node = ValueStack[ValueStack.Depth - 2] as ExpressionNode;
                node.ShouldReturnValue = false;
            }
#line default
                break;

            case 15: // instruction -> Semicolon
#line 70 "D:\MINICompiler\kompilator.y"
            {
                syntaxErrorLines.Add(ValueStack[ValueStack.Depth - 1].Line);
            }
#line default
                break;

            case 16: // instruction -> error
#line 74 "D:\MINICompiler\kompilator.y"
            {
                syntaxErrorLines.Add(ValueStack[ValueStack.Depth - 1].Line);
            }
#line default
                break;

            case 17: // write -> Write, String
#line 80 "D:\MINICompiler\kompilator.y"
            {
                WriteNode node = new WriteNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1];
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 18: // write -> Write, exp
#line 86 "D:\MINICompiler\kompilator.y"
            {
                WriteNode node = new WriteNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 19: // read -> Read, Variable
#line 93 "D:\MINICompiler\kompilator.y"
            {
                ReadNode node = new ReadNode(ValueStack[ValueStack.Depth - 2].Line);
                node.target          = ValueStack[ValueStack.Depth - 1] as VariableNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 20: // init -> Int, Variable
#line 100 "D:\MINICompiler\kompilator.y"
            {
                InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line);
                node.variable         = ValueStack[ValueStack.Depth - 1] as VariableNode;
                node.variable.ValType = ValType.Int;
                CurrentSemanticValue  = node;
            }
#line default
                break;

            case 21: // init -> Double, Variable
#line 108 "D:\MINICompiler\kompilator.y"
            {
                InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line);
                node.variable         = ValueStack[ValueStack.Depth - 1] as VariableNode;
                node.variable.ValType = ValType.Double;
                CurrentSemanticValue  = node;
            }
#line default
                break;

            case 22: // init -> Bool, Variable
#line 115 "D:\MINICompiler\kompilator.y"
            {
                InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line);
                node.variable         = ValueStack[ValueStack.Depth - 1] as VariableNode;
                node.variable.ValType = ValType.Bool;
                CurrentSemanticValue  = node;
            }
#line default
                break;

            case 23: // assign -> Variable, Assign, exp
#line 123 "D:\MINICompiler\kompilator.y"
            {
                AssignNode node = new AssignNode(ValueStack[ValueStack.Depth - 3].Line);
                node.left              = ValueStack[ValueStack.Depth - 3] as VariableNode;
                node.right             = ValueStack[ValueStack.Depth - 1];
                node.ShouldReturnValue = true;
                CurrentSemanticValue   = node;
            }
#line default
                break;

            case 24: // exp -> OpenPar, exp, ClosePar
#line 133 "D:\MINICompiler\kompilator.y"
            {
                ParenthesisNode node = new ParenthesisNode(ValueStack[ValueStack.Depth - 3].Line);
                node.content         = ValueStack[ValueStack.Depth - 2] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 25: // exp -> exp, Add, exp
#line 139 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 26: // exp -> exp, Sub, exp
#line 144 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 27: // exp -> exp, Mult, exp
#line 149 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 28: // exp -> exp, Div, exp
#line 154 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 29: // exp -> exp, BitAnd, exp
#line 159 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 30: // exp -> exp, BitOr, exp
#line 164 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 32: // exp -> IntCast, exp
#line 170 "D:\MINICompiler\kompilator.y"
            {
                IntCastNode node = new IntCastNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 33: // exp -> DoubleCast, exp
#line 176 "D:\MINICompiler\kompilator.y"
            {
                DoubleCastNode node = new DoubleCastNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 37: // exp -> Not, exp
#line 185 "D:\MINICompiler\kompilator.y"
            {
                NotNode node = new NotNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 38: // exp -> Tilde, exp
#line 191 "D:\MINICompiler\kompilator.y"
            {
                NegNode node = new NegNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 39: // exp -> Sub, exp
#line 197 "D:\MINICompiler\kompilator.y"
            {
                MinusNode node = new MinusNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 40: // exp -> exp, And, exp
#line 203 "D:\MINICompiler\kompilator.y"
            {
                LogicOpNode node = ValueStack[ValueStack.Depth - 2] as LogicOpNode;
                node.left            = ValueStack[ValueStack.Depth - 3] as ExpressionNode;
                node.right           = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 41: // exp -> exp, Or, exp
#line 210 "D:\MINICompiler\kompilator.y"
            {
                LogicOpNode node = ValueStack[ValueStack.Depth - 2] as LogicOpNode;
                node.left            = ValueStack[ValueStack.Depth - 3] as ExpressionNode;
                node.right           = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 42: // exp -> exp, Comparison, exp
#line 217 "D:\MINICompiler\kompilator.y"
            {
                ComparisonNode node = ValueStack[ValueStack.Depth - 2] as ComparisonNode;
                CurrentSemanticValue = AssignToComparisonOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 44: // if -> If, OpenPar, exp, ClosePar, instruction
#line 225 "D:\MINICompiler\kompilator.y"
            {
                IfNode node = new IfNode(ValueStack[ValueStack.Depth - 5].Line);
                node.check           = ValueStack[ValueStack.Depth - 3] as ExpressionNode;
                node.ifBlock         = ValueStack[ValueStack.Depth - 1];
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 45: // if -> If, OpenPar, exp, ClosePar, instruction, Else, instruction
#line 232 "D:\MINICompiler\kompilator.y"
            {
                IfNode node = new IfNode(ValueStack[ValueStack.Depth - 7].Line);
                node.check           = ValueStack[ValueStack.Depth - 5] as ExpressionNode;
                node.elseBlock       = ValueStack[ValueStack.Depth - 1];
                node.ifBlock         = ValueStack[ValueStack.Depth - 3];
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 46: // while -> While, OpenPar, exp, ClosePar, instruction
#line 241 "D:\MINICompiler\kompilator.y"
            {
                WhileNode node = new WhileNode(ValueStack[ValueStack.Depth - 5].Line);
                node.check           = ValueStack[ValueStack.Depth - 3] as ExpressionNode;
                node.block           = ValueStack[ValueStack.Depth - 1];
                CurrentSemanticValue = node;
            }
#line default
                break;
            }
#pragma warning restore 162, 1522
        }
Exemple #23
0
 public virtual void Visit(WriteNode node)
 {
 }
Exemple #24
0
    private AstNode Statement(LexemeSet stopSet)
    {
        AstNode res = null;

        logger.LogDebug($"Statement: {currentLexeme} [{stopSet}]");
        if (CheckOrSkip(stopSet + startBlock, stopSet))
        {
            switch (currentLexeme.Type)
            {
            case LexemeType.Identifier:
                string identifier = currentLexeme.Value.ToString();
                // check id exists in the symbol table in the semantic analysis pass
                NextLexeme();

                if (CheckOrSkip(LexemeType.Assign, stopSet + startExpression))
                {
                    NextLexeme();
                    res = new AssignmentNode()
                    {
                        Identifier = new IdentifierNode(identifier),
                        Expression = Expression(stopSet),
                    };
                }
                break;

            case LexemeType.If:
                NextLexeme();

                IfNode ifNode = new IfNode();

                ifNode.Comparison = Comparison(stopSet + LexemeType.Then + startBlock - LexemeType.Identifier);
                if (CheckOrSkip(LexemeType.Then, stopSet + startBlock))
                {
                    NextLexeme();
                }
                Block(stopSet, ifNode.Statements);
                res = ifNode;
                break;

            case LexemeType.While:
                NextLexeme();

                WhileNode whileNode = new WhileNode();
                whileNode.Comparison = Comparison(stopSet + LexemeType.Do + startBlock - LexemeType.Identifier);
                if (CheckOrSkip(LexemeType.Do, stopSet + startBlock))
                {
                    NextLexeme();
                }
                Block(stopSet, whileNode.Statements);
                res = whileNode;
                break;

            case LexemeType.Write:
                NextLexeme();
                if (CheckOrSkip(LexemeType.LBracket, stopSet + LexemeType.RBracket + startExpression))
                {
                    NextLexeme();
                }

                WriteNode writeNode = new WriteNode();
                writeNode.Expression = Expression(stopSet + LexemeType.RBracket);
                if (CheckOrSkip(LexemeType.RBracket, stopSet))
                {
                    NextLexeme();
                }

                res = writeNode;
                break;
            }
        }

        return(res);
    }
 public override void VisitWriteNode(WriteNode w)
 {
     CurrentComplexity = 0;
     w.Expr.Visit(this);
     Complexities.Add(CurrentComplexity);
 }
Exemple #26
0
 public override void VisitWriteNode(WriteNode w)
 {
     w.Expr.Visit(this);
 }
        public void Visit(WriteNode n)
        {
            var table    = (FunctionSymbolTableEntry)n.SymTable;
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.Accept(this);
            }

            var valueVar    = children[0].TemporaryVariableName;
            var valueOffset = table.MemoryLayout.GetOffset(valueVar);

            // NOTE(AFL): Code adapted from the util.m file. Maybe make it into a function.
            var putint1   = $"putint1_{_writeLabelCounter}";
            var putint2   = $"putint2_{_writeLabelCounter}";
            var putint9   = $"putint9_{_writeLabelCounter}";
            var putintEnd = $"putint_end_{_writeLabelCounter}";

            ++_writeLabelCounter;

            _writer.WriteComment("Write Op");

            var r0 = Registers.R0;
            var r1 = PopRegister();
            var r2 = PopRegister();
            var r3 = PopRegister();
            var r4 = PopRegister();

            // Load value to write
            _writer.WriteInstruction(Instructions.Lw, r1, $"{valueOffset}({FSPReg})");

            // putint
            _writer.WriteInstruction(Instructions.Cge, r3, r1, r0);
            _writer.WriteInstruction(Instructions.Bnz, r3, putint1);
            _writer.WriteInstruction(Instructions.Sub, r1, r0, r1);
            _writer.WriteTag(putint1);
            _writer.WriteInstruction(Instructions.Modi, r4, r1, "10");
            _writer.WriteInstruction(Instructions.Addi, r4, r4, "48");
            _writer.WriteInstruction(Instructions.Divi, r1, r1, "10");
            _writer.WriteInstruction(Instructions.Sb, $"{putint9}({r2})", r4);
            _writer.WriteInstruction(Instructions.Addi, r2, r2, "1");
            _writer.WriteInstruction(Instructions.Bnz, r1, putint1);
            _writer.WriteInstruction(Instructions.Bnz, r3, putint2);
            _writer.WriteInstruction(Instructions.Addi, r3, r0, "45");
            _writer.WriteInstruction(Instructions.Sb, $"{putint9}({r2})", r3);
            _writer.WriteInstruction(Instructions.Addi, r2, r2, "1");
            _writer.WriteInstruction(Instructions.Add, r1, r0, r0);
            _writer.WriteTag(putint2);
            _writer.WriteInstruction(Instructions.Subi, r2, r2, "1");
            _writer.WriteInstruction(Instructions.Lb, r1, $"{putint9}({r2})");
            _writer.WriteInstruction(Instructions.Putc, r1);
            _writer.WriteInstruction(Instructions.Bnz, r2, putint2);
            _writer.WriteInstruction(Instructions.J, putintEnd);
            _writer.WriteTag(putint9);
            _writer.WriteInstruction(Instructions.Res, "12");
            _writer.WriteInstruction(Instructions.Align);
            _writer.WriteTag(putintEnd);
            _writer.WriteInstruction(Instructions.Sub, r1, r1, r1);
            _writer.WriteInstruction(Instructions.Addi, r1, r1, "10");
            _writer.WriteInstruction(Instructions.Putc, r1);

            PushRegister(r4);
            PushRegister(r3);
            PushRegister(r2);
            PushRegister(r1);
        }
Exemple #28
0
 public virtual void VisitWriteNode(WriteNode w)
 {
 }
Exemple #29
0
 public override void VisitWriteNode(WriteNode w)
 {
     Complexity.Add(0);
     w.Expr.Visit(this);
 }