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);
                }
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     if (depth == 0)
     {
         compList.Add(sum);
     }
 }
Exemplo 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();
 }
Exemplo n.º 7
0
 public void Visit(IntNumNode n)
 {
     foreach (var node in n.GetChildren())
     {
         node.SymTable = n.SymTable;
         node.Accept(this);
     }
 }
Exemplo 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);
        }
Exemplo n.º 9
0
 public void Visit(IntNumNode n)
 {
     PrintDOTIDLabel(n, n.Value.ToString());
     PrintDOTParentChild(n);
     foreach (var child in n.GetChildren())
     {
         child.Accept(this);
     }
 }
Exemplo n.º 10
0
        public void Visit(IntNumNode n)
        {
            var children = n.GetChildren();

            foreach (var child in children)
            {
                child.SymTable = n.SymTable;
                child.Accept(this);
            }
        }
Exemplo n.º 11
0
 public override void VisitIntNumNode(IntNumNode id)
 {
     if (CurrNestExprs > 0)
     {
         if (CurrNest == 0)
         {
             list.Add(0);
         }
     }
 }
Exemplo 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);
        }
Exemplo n.º 13
0
 public override void VisitIntNumNode(IntNumNode num) => Text += num.Num.ToString(CultureInfo.CurrentCulture);
Exemplo n.º 14
0
 public virtual void VisitIntNumNode(IntNumNode num)
 {
 }
Exemplo 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();
 }
Exemplo 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);
Exemplo 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();
        }
Exemplo n.º 22
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     throw new Exception("Logic error");
 }
Exemplo n.º 23
0
 public virtual void Visit(IntNumNode node)
 {
 }
Exemplo n.º 24
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     Text.Append(num.Num.ToString());
 }
Exemplo n.º 25
0
 public override void VisitIntNumNode(IntNumNode num)
 {
     Text += num.Num.ToString();
 }
Exemplo n.º 26
0
 public override void Visit(IntNumNode node)
 {
     ProgramBuilder.Append(node.Num);
 }