E - the type of the base expressionspublic class LogicExpression<E> extends Object implements com.google.common.base.Predicate<E>
| Modifier | Constructor and Description |
|---|---|
protected |
LogicExpression(String input,
com.google.common.base.Function<String,Expression.Arg<E>> factory) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
apply(E entity) |
Expression.Apply<E> |
compile(List<Expression<E>> rpn)
Compile a rpn list of tokens into an expression tree.
|
static <E> LogicExpression<E> |
compile(String input,
com.google.common.base.Function<String,Expression.Arg<E>> factory) |
List<String> |
getArgs()
Return a list of the arguments contained in the expression.
|
boolean |
isEmpty()
If the expression is empty, it returns true for all inputs.
|
static void |
main(String[] args)
Iteractively interpret logic statements from stdin such as "true | (true & false)".
|
List<Expression<E>> |
rpn(List<Expression<E>> tokens)
Converts an infix logic representation into a postfix logic representation.
|
List<Expression<E>> |
tokenize(String input,
com.google.common.base.Function<String,Expression.Arg<E>> factory)
Convert an infix string logic representation to an infix list of tokens.
|
String |
toString() |
protected LogicExpression(String input, com.google.common.base.Function<String,Expression.Arg<E>> factory) throws LogicException.TokenizeLogicException, LogicException.CompileLogicException
input - an infix representation of the logic expression.factory - a delegate to convert the string representation of an
expression to a token.LogicException.TokenizeLogicExceptionLogicException.CompileLogicExceptionpublic static <E> LogicExpression<E> compile(String input, com.google.common.base.Function<String,Expression.Arg<E>> factory)
public boolean isEmpty()
public boolean apply(E entity)
apply in interface com.google.common.base.Predicate<E>public Expression.Apply<E> compile(List<Expression<E>> rpn)
rpn - a list of tokens in infix form.public List<String> getArgs()
public List<Expression<E>> tokenize(String input, com.google.common.base.Function<String,Expression.Arg<E>> factory) throws LogicException.TokenizeLogicException
input - an infix string logic representation.factory - a delegate that converts a string representation of an
argument into a token object. @returnLogicException.TokenizeLogicExceptionpublic List<Expression<E>> rpn(List<Expression<E>> tokens) throws LogicException.CompileLogicException
tokens - a list of tokens in infix form.LogicException.CompileLogicExceptionpublic static void main(String[] args)
args - Copyright © 2010-2012 University of Washington CSE. All Rights Reserved.