private void IfStatement() { Label labelElse = new Label(this); Label labelEnd = new Label(this); Stream.Expect(TokenType.Word, "if"); Stream.Expect(TokenType.Delimiter, "("); TernaryExpression(); Stream.Expect(TokenType.Delimiter, ")"); Instructions.Add(new Instruction(Opcode.Push, new Variant(1))); Instructions.Add(new Instruction(Opcode.CompareEqual)); Instructions.Add(new Instruction(Opcode.IfFalse, new Variant(0))); labelElse.PatchHere(); BlockStatement(); Instructions.Add(new Instruction(Opcode.Jump, new Variant(0))); labelEnd.PatchHere(); labelElse.Mark(); if (Stream.Accept(TokenType.Word, "else")) BlockStatement(); labelEnd.Mark(); labelElse.Fix(); labelEnd.Fix(); }
private void TernaryExpression() { LogicalAndOr(); while (Stream.Accept(TokenType.Delimiter, "?")) { Label labelElse = new Label(this); Label labelEnd = new Label(this); Instructions.Add(new Instruction(Opcode.Push, new Variant(1))); Instructions.Add(new Instruction(Opcode.CompareEqual)); Instructions.Add(new Instruction(Opcode.IfFalse, new Variant(0))); labelElse.PatchHere(); LogicalAndOr(); Instructions.Add(new Instruction(Opcode.Jump, new Variant(0))); labelEnd.PatchHere(); Stream.Expect(TokenType.Delimiter, ":"); labelElse.Mark(); LogicalAndOr(); labelEnd.Mark(); labelElse.Fix(); labelEnd.Fix(); } }