Methods Summary |
---|
public static void | doit(java.lang.String str)
System.out.println(str);
System.out.println();
Expression expr = ExpressionParser.parseExpression(str);
BeanshellGenerator gen = new BeanshellGenerator(expr);
System.out.println(gen.createBeanshellCode());
System.out.println("-----------------------");
|
public static void | main(java.lang.String[] args)
doit("a == b");
doit("a == b implies b == a");
doit("forall IEmployee e in getEmployees() | getRooms().contains(e.getOffice());");
doit("exists IEmployee e in getEmployees() | !getRooms().contains(e.getOffice())");
doit("forall IEmployee e1 in getEmployees() | forall IEmployee e2 in getEmployees() | (e1 != e2) implies e1.getOffice() != e2.getOffice()");
doit("java: for (int i = 0){i > 0;}");
|
private static Expression | parse(java.lang.String expr)
expr = expr.trim();
if (expr.startsWith(FORALL))
{
return parseForAll(expr);
}
else if (expr.startsWith(EXISTS))
{
return parseExists(expr);
}
else if (expr.indexOf(IMPLIES) > 0)
{
return parseImplies(expr);
}
else if (expr.startsWith(JAVA))
{
return parseJava(expr);
}
else
{
return parseBoolean(expr);
}
|
private static Expression | parseBoolean(java.lang.String expr)
if (expr.endsWith(";"))
{
expr = expr.substring(0, expr.length() - 1);
}
return new BooleanExpression(expr);
|
private static Expression | parseExists(java.lang.String expr)
int in = expr.indexOf(IN);
if (in < 0) throw new RuntimeException("exists expressions must have an 'in' clause: " + expr);
String declaration = expr.substring(EXISTS.length(), in);
int sep = expr.indexOf(SEPARATOR);
if (sep < 0) throw new RuntimeException("exists expressions must have a '|': " + expr);
String collection = expr.substring(in + IN.length(), sep);
String body = expr.substring(sep + SEPARATOR.length());
Expression sub = parse(body);
ExistsExpression exists = new ExistsExpression(declaration, collection, sub);
return exists;
|
public static Expression | parseExpression(java.lang.String expr)
return parse(expr);
|
private static Expression | parseForAll(java.lang.String expr)
int in = expr.indexOf(IN);
if (in < 0) throw new RuntimeException("forall expressions must have an 'in' clause: " + expr);
String declaration = expr.substring(FORALL.length(), in);
int sep = expr.indexOf(SEPARATOR);
if (sep < 0) throw new RuntimeException("forall expressions must have a '|': " + expr);
String collection = expr.substring(in + IN.length(), sep);
String body = expr.substring(sep + SEPARATOR.length());
Expression sub = parse(body);
ForAllExpression forAll = new ForAllExpression(declaration, collection, sub);
return forAll;
|
private static Expression | parseImplies(java.lang.String expr)
int impl = expr.indexOf(IMPLIES);
String exprA = expr.substring(0, impl);
String exprB = expr.substring(impl + IMPLIES.length());
if (exprA.trim().length() == 0 || exprB.trim().length() == 0)
{
throw new RuntimeException("implies expressions must take two simple boolean expressions: " + expr);
}
if (exprA.endsWith(";"))
{
exprA = expr.substring(0, expr.length() - 1);
}
try
{
Expression condA = parse(exprA);
Expression condB = parse(exprB);
ImpliesExpression implies = new ImpliesExpression((BooleanExpression)condA, (BooleanExpression)condB);
return implies;
}
catch (ClassCastException e)
{
throw new RuntimeException("implies expressions must take two simple boolean expressions: " + expr);
}
|
private static Expression | parseJava(java.lang.String expr)
expr = expr.substring(JAVA.length());
return new JavaExpression(expr);
|