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); }
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; } }); } }
public abstract void Visit(AdditionNode node);