private void registerDefaultSymbols() { registerSymbol(SymbolFactory.createConstant("PI", Math.PI)); registerSymbol(SymbolFactory.createConstant("E", Math.E)); registerSymbol(SymbolFactory.createConstant("NaN", Double.NaN)); }
/** * Creates a new <code>boolean</code> variable. * @param name the variable's name * @param value the variable's initial value * @return the variable, never <code>null</code> */ public static Variable createVariable(final String name, final boolean value) { return new VariableB(name, value); }
/** * Creates a new <code>int</code> variable. * @param name the variable's name * @param value the variable's initial value * @return the variable, never <code>null</code> */ public static Variable createVariable(final String name, final int value) { return new VariableI(name, value); }
private void initParser() { final String sourceName = getSelectedSourceName(); final Variable sourceVariable = SymbolFactory.createVariable(sourceName, 0.0); final DefaultNamespace namespace = new DefaultNamespace(); namespace.registerSymbol(sourceVariable); setParser(new ParserImpl(namespace, true)); }
/** * Constructs a new parser instance which uses a {@link DefaultNamespace} and the given type-checking setting. * * @param typeChecking if true, the parser performs strong type-checking on expressions */ public ParserImpl(boolean typeChecking) { this(new DefaultNamespace(), typeChecking); }
/** * Determines whether the character at the given position i is * part of a name (a letter, a digit, the '_' or '.'). */ private boolean isNamePart(final int i) { return isNameStart(i) || isDigit(i) || isDot(i); }
/** * Create an external name from the given name. * If the given name contains character which are not valid in an external name * the name is escaped with single quotes. * <p>The method simply delgates to {@link Tokenizer#createExternalName(String)}. * * @param name the name * @return a valid external name */ public static String createExternalName(final String name) { return Tokenizer.createExternalName(name); }
/** * Determines whether the character at the current position * marks the beginning of a number (a digit or a '.'). */ private boolean isNumberStart() { return isDigit() || isDotAndDigit(); }
public DefaultNamespace(Namespace parent) { super(parent); registerDefaultSymbols(); registerDefaultFunctions(); }
/** * Determines whether the character at the current position is * a single quote used to mark the end of an escaped name ('). */ private boolean isEscapedNameStart() { return isChar('\''); }
/** * Creates a new <code>double</code> constant. * @param name the constant's name * @param value the constant's final value * @return a symbol representing the constant, never <code>null</code> */ public static Symbol createConstant(final String name, final double value) { return new VariableD(name, value); }
/** * Sets the maximum stack size. * @param stackSizeMax the maximum stack size in element units. */ public static void setStackSizeMax(final int stackSizeMax) { UserFunction.stackSizeMax = stackSizeMax; createStack(); }
/** * Determines whether the character at the current position is * part of a name (a letter, a digit or '_'). */ private boolean isNamePart() { return isNamePart(pos); }
/** * Returns the character at the given position i. */ private char peek(final int i) { return isEos(i) ? '\0' : source[i]; }
/** * Parses a complete expression jex.term. Simply a wrapper for * a <code>parseAssign</code> method in order to signal that the assignment * operator '=' has the highest operator precedence. * * @param required true, if the expression is required. * @return The generated term. * @throws ParseException if a parse error occurs */ private Term parseTerm(final boolean required) throws ParseException { return parseAssign(required); }
/** * Returns the character at the current position. */ private char peek() { return peek(pos); }
/** * Creates a new <code>boolean</code> constant. * @param name the constant's name * @param value the constant's final value * @return a symbol representing the constant, never <code>null</code> */ public static Symbol createConstant(final String name, final boolean value) { return new VariableB(name, value); }
/** * Creates a new <code>double</code> variable. * @param name the variable's name * @param value the variable's initial value * @return the variable, never <code>null</code> */ public static Variable createVariable(final String name, final double value) { return new VariableD(name, value); }
/** * Determines whether the character at the current position is * a quote used to mark the beginning of a string constant ("). */ private boolean isStringStart() { return isChar('"'); }