public void visitRead(ReadNode node)
 {
     foreach (INode child in node.getChildren())
     {
         child.accept(this);
     }
 }
Beispiel #2
0
 public void Visit(ReadNode n)
 {
     foreach (var node in n.GetChildren())
     {
         node.SymTable = n.SymTable;
         node.Accept(this);
     }
 }
Beispiel #3
0
 public void Visit(ReadNode n)
 {
     PrintDOTIDLabel(n);
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
Beispiel #4
0
        public override void VisitReadNode(ReadNode rd)
        {
            var readLine = new ThreeAddrLine();

            readLine.Label  = GenNewLabel();
            readLine.Accum  = rd.Id.Name;
            readLine.OpType = ThreeAddrOpType.Read;
            Data.Add(readLine);
        }
        public void Visit(ReadNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.Accept(this);
            }
        }
Beispiel #6
0
 public override void Visit(ReadNode node)
 {
     WriteIndent();
     ProgramBuilder.Append("read");
     ProgramBuilder.Append('(');
     node.Ident.Visit(this);
     ProgramBuilder.Append(')');
     NewLine();
 }
        public void visitRead(ReadNode readNode)
        {
            IdentifierNode identifier   = (IdentifierNode)readNode.getChildren()[0];
            string         variableName = identifier.getVariableName();

            if (!this.symbolTable.hasInteger(variableName) && !this.symbolTable.hasString(variableName))
            {
                throw new SemanticException("Wrong type in read statement. Trying to read input to variable " + variableName + ". Read statement can read only integers and strings.");
            }
        }
        public void visitRead(ReadNode node)
        {
            IdentifierNode identifier   = (IdentifierNode)node.getChildren()[0];
            string         variableName = identifier.getVariableName();

            if (this.symbolTable.hasInteger(variableName))
            {
                this.symbolTable.updateVariable(variableName, readInteger());
            }
            else if (this.symbolTable.hasString(variableName))
            {
                this.symbolTable.updateVariable(variableName, readString());
            }
        }
        public void Visit(ReadNode n)
        {
            var table    = (FunctionSymbolTableEntry)n.SymTable;
            var children = n.GetChildren();

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

            var valueVarVar    = children[0].TemporaryVariableName;
            var valueVarOffset = table.MemoryLayout.GetOffset(valueVarVar);

            // NOTE(AFL): Code adapted from the util.m file. Maybe make it into a function.
            var getint1   = $"getint1_{_readLabelCounter}";
            var getint2   = $"getint2_{_readLabelCounter}";
            var getint3   = $"getint3_{_readLabelCounter}";
            var getint4   = $"getint4_{_readLabelCounter}";
            var getint5   = $"getint5_{_readLabelCounter}";
            var getint6   = $"getint6_{_readLabelCounter}";
            var getint9   = $"getint9_{_readLabelCounter}";
            var getintEnd = $"getint_end_{_readLabelCounter}";

            ++_readLabelCounter;

            _writer.WriteComment("Read Op");

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

            // getint
            _writer.WriteTag(getint1);
            _writer.WriteInstruction(Instructions.Getc, r1);
            _writer.WriteInstruction(Instructions.Ceqi, r3, r1, "43");
            _writer.WriteInstruction(Instructions.Bnz, r3, getint1);
            _writer.WriteInstruction(Instructions.Ceqi, r3, r1, "45");
            _writer.WriteInstruction(Instructions.Bz, r3, getint2);
            _writer.WriteInstruction(Instructions.Addi, r4, r0, "1");
            _writer.WriteInstruction(Instructions.J, getint1);
            _writer.WriteTag(getint2);
            _writer.WriteInstruction(Instructions.Clti, r3, r1, "48");
            _writer.WriteInstruction(Instructions.Bnz, r3, getint3);
            _writer.WriteInstruction(Instructions.Cgti, r3, r1, "57");
            _writer.WriteInstruction(Instructions.Bnz, r3, getint3);
            _writer.WriteInstruction(Instructions.Sb, $"{getint9}({r2})", r1);
            _writer.WriteInstruction(Instructions.Addi, r2, r2, "1");
            _writer.WriteInstruction(Instructions.J, getint1);
            _writer.WriteTag(getint3);
            _writer.WriteInstruction(Instructions.Sb, $"{getint9}({r2})", r0);
            _writer.WriteInstruction(Instructions.Add, r1, r0, r0);
            _writer.WriteInstruction(Instructions.Add, r2, r0, r0);
            _writer.WriteInstruction(Instructions.Add, r3, r0, r0);
            _writer.WriteTag(getint4);
            _writer.WriteInstruction(Instructions.Lb, r3, $"{getint9}({r2})");
            _writer.WriteInstruction(Instructions.Bz, r3, getint5);
            _writer.WriteInstruction(Instructions.Subi, r3, r3, "48");
            _writer.WriteInstruction(Instructions.Muli, r1, r1, "10");
            _writer.WriteInstruction(Instructions.Add, r1, r1, r3);
            _writer.WriteInstruction(Instructions.Addi, r2, r2, "1");
            _writer.WriteInstruction(Instructions.J, getint4);
            _writer.WriteTag(getint5);
            _writer.WriteInstruction(Instructions.Bz, r4, getint6);
            _writer.WriteInstruction(Instructions.Sub, r1, r0, r1);
            _writer.WriteTag(getint6);
            _writer.WriteInstruction(Instructions.J, getintEnd);
            _writer.WriteTag(getint9);
            _writer.WriteInstruction(Instructions.Res, "12");
            _writer.WriteInstruction(Instructions.Align);
            _writer.WriteTag(getintEnd);

            // Store value we got
            var addrReg = PopRegister();

            _writer.WriteInstruction(Instructions.Lw, addrReg, $"{valueVarOffset}({FSPReg})");
            _writer.WriteInstruction(Instructions.Sw, $"0({addrReg})", r1);

            PushRegister(addrReg);


            PushRegister(r4);
            PushRegister(r3);
            PushRegister(r2);
            PushRegister(r1);
        }
Beispiel #10
0
 public override void Visit(ReadNode node)
 {
     PreVisit(node);
     node.Ident.Visit(this);
     PostVisit(node);
 }
Beispiel #11
0
 public override void VisitReadNode(ReadNode rd)
 {
     rd.Id.Visit(this);
 }
Beispiel #12
0
        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
        }
Beispiel #13
0
 public override void Visit(ReadNode node)
 {
     OnEnter(node);
     base.Visit(node);
     OnExit(node);
 }
Beispiel #14
0
 public override void Visit(ReadNode node)
 {
     node.Ident.Visit(this);
 }
Beispiel #15
0
 public virtual void VisitReadNode(ReadNode rd)
 {
 }
Beispiel #16
0
        public static IEnumerable <(ulong Offset, ulong Index)> StreamSearch(ulong numItems, ushort nodeSize, Envelope rect, ReadNode readNode)
        {
            var minX        = rect.MinX;
            var minY        = rect.MinY;
            var maxX        = rect.MaxX;
            var maxY        = rect.MaxY;
            var levelBounds = GenerateLevelBounds(numItems, nodeSize);
            var numNodes    = levelBounds.First().End;
            var stack       = new Stack <(ulong NodeIndex, int Level)>();

            stack.Push((0UL, levelBounds.Count() - 1));
            while (stack.Count != 0)
            {
                var(nodeIndex, level) = stack.Pop();
                var isLeafNode = nodeIndex >= numNodes - numItems;
                // find the end index of the node
                var levelBound = levelBounds[level].End;
                var end        = Math.Min(nodeIndex + nodeSize, levelBound);
                var length     = end - nodeIndex;
                var stream     = readNode(nodeIndex * NODE_ITEM_LEN, length * NODE_ITEM_LEN);
                var start      = stream.Position;
                var reader     = new BinaryReader(stream);
                // search through child nodes
                for (var pos = nodeIndex; pos < end; pos++)
                {
                    stream.Seek(start + (long)((pos - nodeIndex) * NODE_ITEM_LEN), SeekOrigin.Begin);
                    if (maxX < reader.ReadDouble())
                    {
                        continue;                             // maxX < nodeMinX
                    }
                    if (maxY < reader.ReadDouble())
                    {
                        continue;                             // maxY < nodeMinY
                    }
                    if (minX > reader.ReadDouble())
                    {
                        continue;                             // minX > nodeMaxX
                    }
                    if (minY > reader.ReadDouble())
                    {
                        continue;                             // minY > nodeMaxY
                    }
                    var offset = reader.ReadUInt64();
                    if (isLeafNode)
                    {
                        yield return(offset, pos - 1);
                    }
                    else
                    {
                        stack.Push((offset, level - 1));
                    }
                }
                // order queue to traverse sequential
                //queue.sort((a, b) => b[0] - a[0])
            }
        }
Beispiel #17
0
 public virtual void Visit(ReadNode node)
 {
 }