public RValue bind(Expression expression, boolean isLValue) throws ParserException { final RValue variable = expression.getVariable(name, isLValue); if (variable == null) { throw new ParserException(getPosition(), "Variable '" + name + "' not found"); } return variable; }
@Override public LValue bindVariables(Expression expression, boolean preferLValue) throws ParserException { final RValue variable = expression.getVariable(name, preferLValue); if (variable == null) { throw new ParserException(getPosition(), "Variable '" + name + "' not found"); } return (LValue) variable; }
do { if (input.isEmpty()) { throw new ParserException(-1, "Expression missing."); throw new ParserException(center.getPosition(), "Expected expression, found " + center); continue; } catch (NoSuchMethodException e) { throw new ParserException(lastPosition, "No such prefix operator: " + operator); throw new ParserException(lastPosition, "Extra token found in expression: " + last); } else if (last instanceof RValue) { throw new ParserException(lastPosition, "Extra expression found: " + last); } else { throw new ParserException(lastPosition, "Extra element found: " + last);
private RValue parse() throws ParserException { final RValue ret = parseStatements(false); if (position < tokens.size()) { final Token token = peek(); throw new ParserException(token.getPosition(), "Extra token at the end of the input: " + token); } ret.bindVariables(expression, false); return ret; }
private void assertKeyword(String keyword) throws ParserException { if (!hasKeyword(keyword)) { throw new ParserException(peek().getPosition(), "Expected '" + keyword + "'"); } }
private void assertCharacter(char character) throws ParserException { final Token next = peek(); if (next.id() != character) { throw new ParserException(next.getPosition(), "Expected '" + character + "'"); } }
} catch (NoSuchMethodException e) { final Token operatorToken = (Token) input.get(lhs.size()); throw new ParserException(operatorToken.getPosition(), "Couldn't find operator '" + operator + "'");
} catch (NoSuchMethodException e) { final Token operatorToken = (Token) input.get(lhs.size()); throw new ParserException(operatorToken.getPosition(), "Couldn't find operator '" + operator + "'");
throw new ParserException(identifiable.getPosition(), "Unexpected ':'");
private Function parseFunctionCall(IdentifierToken identifierToken) throws ParserException { consumeCharacter('('); try { if (peek().id() == ')') { ++position; return Functions.getFunction(identifierToken.getPosition(), identifierToken.value); } List<RValue> args = new ArrayList<>(); loop: while (true) { args.add(parseExpression(false)); final Token current = peek(); ++position; switch (current.id()) { case ',': continue; case ')': break loop; default: throw new ParserException(current.getPosition(), "Unmatched opening bracket"); } } return Functions.getFunction(identifierToken.getPosition(), identifierToken.value, args.toArray(new RValue[args.size()])); } catch (NoSuchMethodException e) { throw new ParserException(identifierToken.getPosition(), "Function '" + identifierToken.value + "' not found", e); } }
throw new ParserException(variableToken.getPosition(), "Expected identifier"); throw new ParserException(variableToken.getPosition(), "Expected variable"); throw new ParserException(variableToken.getPosition(), "Expected '=' or a term and ';'"); while (peek().id() != '}') { if (position >= tokens.size()) { throw new ParserException(current.getPosition(), "Expected '}' instead of EOF"); throw new ParserException(current.getPosition(), "Expected '}' instead of " + peek()); throw new ParserException(current.getPosition(), "Expected number instead of " + peek()); defaultCase = parseStatements(false); } else { throw new ParserException(current.getPosition(), "Expected 'case' or 'default' instead of " + peek()); throw new ParserException(current.getPosition(), "Unexpected keyword '" + keyword + "'"); case 0: if (singleStatement) { throw new ParserException(peek().getPosition(), "Statement expected.");