private void ProcessIfStatement(NodeBase statement) { Queue <NodeBase> children = GetChildren(statement); Expect(children.Dequeue(), NodeType.Keyword, "if"); Expect(children.Dequeue(), NodeType.Symbol, "("); ProcessExpression(children.Dequeue()); int ifStatementNumber = vmWriter.GetIfStatementNumber(); vmWriter.IfStart(ifStatementNumber); Expect(children.Dequeue(), NodeType.Symbol, ")"); Expect(children.Dequeue(), NodeType.Symbol, "{"); ProcessStatements(children.Dequeue()); Expect(children.Dequeue(), NodeType.Symbol, "}"); if (PeekType(children) == NodeType.Keyword && PeekValue(children) == "else") { vmWriter.IfElse(ifStatementNumber); Expect(children.Dequeue(), NodeType.Keyword, "else"); Expect(children.Dequeue(), NodeType.Symbol, "{"); ProcessStatements(children.Dequeue()); Expect(children.Dequeue(), NodeType.Symbol, "}"); vmWriter.IfElseEnd(ifStatementNumber); } else { vmWriter.IfEnd(ifStatementNumber); } }