public static IfBlock Parse(TokenList _tokens) { IfBlock ret = null; Symbol op = 0; if (_tokens.PeekToken().TokenName == Lexer.Tokens.LeftParan) { _tokens.Pos++; } Expr lexpr = Expr.Parse(_tokens); if (_tokens.PeekToken().TokenName == Lexer.Tokens.DoubleEqual) { op = Symbol.doubleEqual; _tokens.Pos++; } else if (_tokens.PeekToken().TokenName == Lexer.Tokens.NotEqual) { op = Symbol.notEqual; _tokens.Pos++; } Expr rexpr = Expr.Parse(_tokens); if (_tokens.PeekToken().TokenName == Lexer.Tokens.RightParan) { _tokens.Pos++; } ret = new IfBlock(lexpr, op, rexpr); return(ret); }
private void CompileIf(IfBlock data) { CompileExpr(data.LeftExpr); CompileExpr(data.RightExpr); if (data.Op == Symbol.doubleEqual) { Write("ife"); } else if (data.Op == Symbol.notEqual) { Write("ifn"); } CompileStmtList(data.Statements); }