private ProgramObject parseLowerOrderExpression() { ProgramObject expression; ProgramObject tmp; expression = parseHigherOrderExpression(); while (currentToken.tokenType != TokenType.Then && currentToken.tokenType != TokenType.Eol && currentToken.tokenType != TokenType.Eof) { switch (currentToken.tokenType) { case TokenType.And: tmp = expression; currentToken = lexer.nextToken(); expression = new LeftAnd(tmp, parseHigherOrderExpression()); break; case TokenType.Or: tmp = expression; currentToken = lexer.nextToken(); expression = new LeftOr(tmp, parseHigherOrderExpression()); break; case TokenType.Xor: tmp = expression; currentToken = lexer.nextToken(); expression = new LeftXor(tmp, parseHigherOrderExpression()); break; case TokenType.OParenthesis: currentToken = lexer.nextToken(); expression = parseParenthesis(); break; case TokenType.CParenthesis: return(expression); default: throw new UnexpectedTokenException(currentToken.value); } } return(expression); }
private ProgramObject parseHigherOrderExpression() { ProgramObject expression = null; ProgramObject s; if (currentToken.tokenType == TokenType.Not || currentToken.tokenType == TokenType.Symbol) { s = parseSymbol(); switch (currentToken.tokenType) { case TokenType.And: currentToken = lexer.nextToken(); expression = new LeftAnd(s, parseHigherOrderExpression()); break; case TokenType.Or: case TokenType.Xor: case TokenType.Then: case TokenType.OParenthesis: case TokenType.CParenthesis: case TokenType.Eol: case TokenType.Eof: expression = s; break; } } else if (currentToken.tokenType == TokenType.OParenthesis) { currentToken = lexer.nextToken(); expression = parseParenthesis(); } else { throw new UnexpectedTokenException(currentToken.value); } return(expression); }