public override void VisitBinOpNode(BinOpNode binop)
        {
            base.VisitBinOpNode(binop);
            if (binop.Left is IntNumNode left && binop.Right is IntNumNode right)
            {
                var num = 0;

                switch (binop.Op)
                {
                case "+":
                    num = left.Num + right.Num;
                    break;

                case "-":
                    num = left.Num - right.Num;
                    break;

                case "*":
                    num = left.Num * right.Num;
                    break;

                case "/":
                    num = left.Num / right.Num;
                    break;
                }

                var newInt = new IntNumNode(num);
                ReplaceExpr(binop, newInt);
            }
        }
        public override void PostVisit(Node n)
        {
            // Algebraic expressions of the form: 2 * 3 => 6
            if (n is BinOpNode binop && binop.Left is IntNumNode && binop.Right is IntNumNode)
            {
                if (binop.Left is IntNumNode && binop.Right is IntNumNode)
                {
                    var result = new IntNumNode(0);
                    switch (binop.Op)
                    {
                    case OpType.PLUS:
                        result.Num = (binop.Left as IntNumNode).Num + (binop.Right as IntNumNode).Num;
                        break;

                    case OpType.MINUS:
                        result.Num = (binop.Left as IntNumNode).Num - (binop.Right as IntNumNode).Num;
                        break;

                    case OpType.DIV:
                        result.Num = (binop.Left as IntNumNode).Num / (binop.Right as IntNumNode).Num;
                        break;

                    case OpType.MULT:
                        result.Num = (binop.Left as IntNumNode).Num * (binop.Right as IntNumNode).Num;
                        break;
                    }
                    ReplaceExpr(binop, result);
                }
                else
                {
                    base.VisitBinOpNode(binop);
                }
            }
        }
        public override void PostVisit(Node node)
        {
            // Algebraic expressions of the form: 2 * 3 => 6
            if (node is BinOpNode binop && binop.Left is IntNumNode intNumLeft && binop.Right is IntNumNode intNumRight)
            {
                var result = new IntNumNode(0);
                switch (binop.Op)
                {
                case OpType.PLUS:
                    result.Num = intNumLeft.Num + intNumRight.Num;
                    break;

                case OpType.MINUS:
                    result.Num = intNumLeft.Num - intNumRight.Num;
                    break;

                case OpType.DIV:
                    result.Num = intNumLeft.Num / intNumRight.Num;
                    break;

                case OpType.MULT:
                    result.Num = intNumLeft.Num * intNumRight.Num;
                    break;

                default:
                    return;
                }
                ReplaceExpr(binop, result);
            }
        }
Esempio n. 4
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     if (depth == 0)
     {
         compList.Add(sum);
     }
 }
Esempio n. 5
0
        public override void VisitIntNumNode(IntNumNode node)
        {
            var literal = LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(node.Value));

            literal = GetNodeWithAnnotation(literal, node.Location) as LiteralExpressionSyntax;
            expressions.Push(literal);
        }
 public override void VisitIntNumNode(IntNumNode num)
 {
     num.Parent = st.Peek();
     st.Push(num);
     base.VisitIntNumNode(num);
     st.Pop();
 }
Esempio n. 7
0
 public void Visit(IntNumNode n)
 {
     foreach (var node in n.GetChildren())
     {
         node.SymTable = n.SymTable;
         node.Accept(this);
     }
 }
Esempio n. 8
0
        public override void VisitIntNumNode(IntNumNode num)
        {
            var line = new ThreeAddrLine();

            line.Accum  = num.Num.ToString();
            line.Label  = GenNewLabel();
            line.OpType = ThreeAddrOpType.Nop;
            Data.Add(line);
        }
Esempio n. 9
0
 public void Visit(IntNumNode n)
 {
     PrintDOTIDLabel(n, n.Value.ToString());
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
Esempio n. 10
0
        public void Visit(IntNumNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.SymTable = n.SymTable;
                child.Accept(this);
            }
        }
Esempio n. 11
0
 public override void VisitIntNumNode(IntNumNode id)
 {
     if (CurrNestExprs > 0)
     {
         if (CurrNest == 0)
         {
             list.Add(0);
         }
     }
 }
Esempio n. 12
0
        public void Visit(IntNumNode n)
        {
            var table   = (FunctionSymbolTableEntry)n.SymTable;
            var tempVar = n.TemporaryVariableName;
            var offset  = table.MemoryLayout.GetOffset(tempVar);

            _writer.WriteComment($"Init const int value {n.Value} ({n.Token.StartLine}:{n.Token.StartColumn})");
            var reg = PopRegister();

            _writer.WriteInstruction(Instructions.Addi, reg, reg, n.Value.ToString());
            _writer.WriteInstruction(Instructions.Sw, $"{offset}({FSPReg})", reg);
            PushRegister(reg);
        }
 public override void VisitIntNumNode(IntNumNode num) => Text += num.Num.ToString(CultureInfo.CurrentCulture);
Esempio n. 14
0
 public virtual void VisitIntNumNode(IntNumNode num)
 {
 }
Esempio n. 15
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     genc.Emit(OpCodes.Ldc_I4, num.Num);
 }
 public override void VisitIntNumNode(IntNumNode num)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
        public void VisitIntNumNode(IntNumNode a)
        {
            string label = Mark(a);

            _nodes.AppendLine($"{label}  [label = \"Int: {a.Num}\"]");
        }
 /// <summary>
 /// Посещение IntNumNode
 /// </summary>
 /// <param name="num">Узел IntNumNode</param>
 public virtual void VisitIntNumNode(IntNumNode num)
 {
     Text += num.Num.ToString();
 }
 public abstract void VisitIntNumNode(IntNumNode num);
Esempio n. 20
0
 public override void Visit(IntNumNode node)
 {
     OnEnter(node);
     base.Visit(node);
     OnExit(node);
 }
        public void Visit(IntNumNode n)
        {
            var table = (FunctionSymbolTableEntry)n.SymTable;

            n.TemporaryVariableName = table.MemoryLayout.AddTemporaryVariable();
        }
Esempio n. 22
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     throw new Exception("Logic error");
 }
Esempio n. 23
0
 public virtual void Visit(IntNumNode node)
 {
 }
Esempio n. 24
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     Text.Append(num.Num.ToString());
 }
Esempio n. 25
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     Text += num.Num.ToString();
 }
Esempio n. 26
0
 public override void Visit(IntNumNode node)
 {
     ProgramBuilder.Append(node.Num);
 }