Example #1
0
 public override void Parse(Context context)
 {
     if (context.Consume(Tokenizer.TokenKind.MINUS))
     {
         var subZero = new AdditionNode();
         var zero    = new NumericLiteralNode();
         zero.Number      = 0;
         subZero.LeftSide = zero;
         var right = new PrimaryNode();
         right.Parse(context);
         subZero.RightSides.Add(
             new Tuple <Tokenizer.TokenKind, Node>(Tokenizer.TokenKind.MINUS, right)
             );
         this.Node = subZero;
         return;
     }
     context.Consume(Tokenizer.TokenKind.PLUS);
     this.Node = new PrimaryNode();
     this.Node.Parse(context);
 }
Example #2
0
        public override void Visit(AdditionNode node)
        {
            node.LeftSide.Accept(this);

            foreach (var pair in node.RightSides)
            {
                pair.Item2.Accept(this);

                this.BinaryOperation(() =>
                {
                    switch (pair.Item1)
                    {
                    case Tokenizer.TokenKind.PLUS:
                        this.Add("   add rax, rdi");
                        break;

                    case Tokenizer.TokenKind.MINUS:
                        this.Add("   sub rax, rdi");
                        break;
                    }
                });
            }
        }
Example #3
0
 public abstract void Visit(AdditionNode node);