![JAR search and dependency download from the Maven repository](/logo.png)
com.g2forge.alexandria.expression.IExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-expression Show documentation
Show all versions of ax-expression Show documentation
A library for expressions and their evaluation. Includes a basic implementation for math.
package com.g2forge.alexandria.expression;
public interface IExpression, N extends IEnvironment> {
public static , V extends IVariable, N extends IEnvironment> L eval(IExpression _this, Class type) {
if (type != null) {
if (type.isInstance(_this)) return type.cast(_this);
} else {
if (_this instanceof ILiteral) {
@SuppressWarnings("unchecked")
final L cast = (L) _this;
return cast;
}
}
final IExpression reduced = _this.reduce();
if (reduced == _this) throw new ExpressionNotEvaluableException(_this, type);
return reduced.eval(type);
}
/**
* Apply the given environment to this expression. May either be eager or lazy, at the implementors discretion.
*
* @param environment The environment to apply to this expression.
* @return An expression equivalent to this one, with any variables present in the environment substituted for their values.
*/
public IExpression apply(N environment);
/**
* Evaluate this expression completely to a literal value.
*
* @param The (static) type of the literal result.
* @param type The type of the literal result to be expected (and required) from this evaluation.
* @return A literal expression resulting from the evaluation.
* @throws ExpressionNotEvaluableException if this expression cannot be completely evaluated.
*/
public default > L eval(Class type) throws ExpressionNotEvaluableException {
return eval(this, type);
}
/**
* Eagerly reduce this expression.
*
* @return A reduced version of this expression.
*/
public IExpression reduce();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy