private void reportTypeErrorB2(final String operator) throws ParseException { reportError("Boolean operands expected for binary " + operator + " operator."); }
private void reportTypeErrorN1(final String operator) throws ParseException { reportError("Numeric operand expected for unary " + operator + " operator."); }
private void reportTypeErrorI1(final String operator) throws ParseException { reportError("Integer operand expected for unary " + operator + " operator."); }
private void reportTypeErrorB1(final String operator) throws ParseException { reportError("Boolean operand expected for unary " + operator + " operator."); }
private void reportTypeErrorI2(final String operator) throws ParseException { reportError("Integer operands expected for binary " + operator + " operator."); }
private void reportTypeErrorN2(final String operator) throws ParseException { reportError("Numeric operands expected for binary " + operator + " operator."); }
private int convertIntToken() throws ParseException { String token = tokenizer.getToken(); try { long l = Long.parseLong(token); if (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE) { return (int) l; } else { reportError("Integer constant '" + token + "' is out of range."); /*I18N*/ } } catch (NumberFormatException e) { reportError("Token '" + token + "' is not a valid integer constant."); /*I18N*/ } return 0; }
private int convertHexIntToken() throws ParseException { final String token = tokenizer.getToken(); try { String hexPart = token.substring(2); // skip '0x' prefix long l = Long.parseLong(hexPart, 16); if (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE) { return (int) l; } else { reportError("Hexadecimal constant '" + token + "' is out of range."); /*I18N*/ } } catch (NumberFormatException e) { reportError("Token '" + token + "' is not a valid hexadecimal constant."); /*I18N*/ } return 0; }
private int convertOctIntToken() throws ParseException { final String token = tokenizer.getToken(); try { String octPart = token.substring(1); // skip '0' prefix long l = Long.parseLong(octPart, 8); if (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE) { return (int) l; } else { reportError("Octal constant '" + token + "' is out of range."); /*I18N*/ } } catch (NumberFormatException e) { reportError("Token '" + token + "' is not a valid octal constant."); /*I18N*/ } return 0; }
private double convertDoubleToken() throws ParseException { final String token = tokenizer.getToken(); try { return Double.parseDouble(token); } catch (NumberFormatException e) { reportError("Token '" + token + "' is not a valid numeric constant."); /*I18N*/ } return 0.0; }
/** * Implements the <code>parse</code> method. Calls <code>parseTerm(false)</code> * and throws an exception if the next token is not the end-of-string. * * @return The generated term. * @throws ParseException if a parse error occurs */ private Term parseImpl() throws ParseException { final Term expr = parseTerm(false); final int tt = tokenizer.next(); if (tt != Tokenizer.TT_EOS) { reportError("Incomplete expression."); /*I18N*/ } return expr; }
/** * Parses a function argument list <i>'(' arg1 ',' arg2 ',' arg3 ',' ... ')'</i> * * @return The generated term. * @throws ParseException if a parse error occurs */ private Term[] parseArgumentList() throws ParseException { final Term[] args = parseTermList(); final int tt = tokenizer.next(); if (tt != ')') { tokenizer.pushBack(); reportError("Missing ')' or ','."); /*I18N*/ } return args; }
private Term parseCallOrRef(final String name) throws ParseException { final int tt; Term t1 = null; tt = tokenizer.next(); if (tt == '(') { Term[] args = parseArgumentList(); Function function = defaultNamespace.resolveFunction(name, args); if (function != null) { t1 = new Term.Call(function, args); } else { reportError("Undefined function '" + getFunctionCallString(name, args) + "'."); /*I18N*/ } } else { tokenizer.pushBack(); Symbol symbol = defaultNamespace.resolveSymbol(name); if (symbol != null) { t1 = new Term.Ref(symbol); } else { reportError("Undefined symbol '" + name + "'."); /*I18N*/ } } return t1; }
/** * Parses an assignment expression <i>x '=' y</i>. * * @param required true, if the expression is required. * @return The generated term. * @throws ParseException if a parse error occurs */ private Term parseAssign(final boolean required) throws ParseException { Term t1 = parseConditional(required); while (t1 != null) { int tt = tokenizer.next(); if (tt == '=') { Term t2 = parseAssign(true); if (t1 instanceof Term.Ref && ((Term.Ref) t1).getVariable() != null) { t1 = new Term.Assign(t1, t2); } else { reportError("Variable expected on the left side of assignment '='."); } } else { tokenizer.pushBack(); break; } } return t1; }
if (isKeyword("else")) { if (isTypeChecking() && !t1.isB()) { reportError("Boolean operand expected after 'if' in conditional term."); } else { tokenizer.pushBack(); reportError("Missing 'else' in a conditional 'if' term."); reportError("Missing 'then' in a conditional 'if' term."); if (tt == ':') { if (isTypeChecking() && !t1.isB()) { reportError("Boolean operand expected before '?' in conditional term."); } else { tokenizer.pushBack(); reportError("Missing ':' part of conditional '?:' term.");
t1 = new Term.ConstB(false); } else { reportError("Unexpected keyword '" + keyword + "'."); if (tt != ')') { tokenizer.pushBack(); reportError("Missing ')'."); /*I18N*/ reportError("Term expected."); /*I18N*/
private Term createConditionTerm(Term t1, Term t2, Term t3) throws ParseException { if (t2.isB() && t3.isB()) { return new Term.Cond(Term.TYPE_B, t1, t2, t3); } else if ((t2.isD() && t3.isN() || t2.isN() && t3.isD())) { return new Term.Cond(Term.TYPE_D, t1, t2, t3); } else if ((t2.isI() && t3.isI())) { return new Term.Cond(Term.TYPE_I, t1, t2, t3); } else if (!isTypeChecking()) { return new Term.Cond(Term.TYPE_D, t1, t2, t3); } else { reportError("Boolean or numeric operands expected in conditional term."); return null; } }