Browse Source

Time-bounded properties with equal lower/upper bounds, e.g. P=?[ F[T,T] target ], can be specified as P=?[ F=T target ], for convenience.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@4710 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 14 years ago
parent
commit
63162e41a3
  1. 677
      prism/src/parser/PrismParser.java
  2. 25
      prism/src/parser/PrismParser.jj
  3. 58
      prism/src/parser/ast/ExpressionTemporal.java

677
prism/src/parser/PrismParser.java
File diff suppressed because it is too large
View File

25
prism/src/parser/PrismParser.jj

@ -322,8 +322,6 @@ public class PrismParser
// A few classes for temporary storage of bits of the AST
//-----------------------------------------------------------------------------------
static class TimeBound { public Expression lBound = null; public Expression uBound = null; public boolean lBoundStrict = false; public boolean uBoundStrict = false; }
static class ExpressionPair { public Expression expr1 = null; public Expression expr2 = null; }
}
@ -1039,7 +1037,6 @@ Expression ExpressionTemporalBinary(boolean prop, boolean pathprop) :
{
Expression ret, expr;
ExpressionTemporal exprTemp;
TimeBound tb = null;
Token begin = null;
}
{
@ -1051,7 +1048,7 @@ Expression ExpressionTemporalBinary(boolean prop, boolean pathprop) :
( <U> { exprTemp.setOperator(ExpressionTemporal.P_U); }
| <W> { exprTemp.setOperator(ExpressionTemporal.P_W); }
| <R> { exprTemp.setOperator(ExpressionTemporal.P_R); } )
( tb = TimeBound() { exprTemp.setLowerBound(tb.lBound, tb.lBoundStrict); exprTemp.setUpperBound(tb.uBound, tb.uBoundStrict); } )?
( TimeBound(exprTemp) )?
expr = ExpressionTemporalUnary(prop, pathprop)
{ exprTemp.setOperand2(expr); exprTemp.setPosition(begin, getToken(0)); ret = exprTemp; }
]
@ -1062,7 +1059,6 @@ Expression ExpressionTemporalUnary(boolean prop, boolean pathprop) :
{
Expression ret, expr;
ExpressionTemporal exprTemp;
TimeBound tb = null;
Token begin = null;
}
{
@ -1073,7 +1069,7 @@ Expression ExpressionTemporalUnary(boolean prop, boolean pathprop) :
( <X> { exprTemp.setOperator(ExpressionTemporal.P_X); }
| <F> { exprTemp.setOperator(ExpressionTemporal.P_F); }
| <G> { exprTemp.setOperator(ExpressionTemporal.P_G); } )
( tb = TimeBound() { exprTemp.setLowerBound(tb.lBound, tb.lBoundStrict); exprTemp.setUpperBound(tb.uBound, tb.uBoundStrict); } )?
( TimeBound(exprTemp) )?
expr = ExpressionTemporalUnary(prop, pathprop)
{ exprTemp.setOperand2(expr); exprTemp.setPosition(begin, getToken(0)); ret = exprTemp; }
|
@ -1085,17 +1081,18 @@ Expression ExpressionTemporalUnary(boolean prop, boolean pathprop) :
// Time bound for temporal operators
// (see ExpressionTemporal production for lookahead explanation)
TimeBound TimeBound() :
void TimeBound(ExpressionTemporal exprTemp) :
{
TimeBound tb = new TimeBound();
Expression lBound, uBound;
}
{
( <LE> ( LOOKAHEAD(IdentifierExpression() <LPARENTH>) tb.uBound = IdentifierExpression() | tb.uBound = Expression(false, false) )
| <LT> {tb.uBoundStrict=true;} ( LOOKAHEAD(IdentifierExpression() <LPARENTH>) tb.uBound = IdentifierExpression() | tb.uBound = Expression(false, false) )
| <GE> ( LOOKAHEAD(IdentifierExpression() <LPARENTH>) tb.lBound = IdentifierExpression() | tb.lBound = Expression(false, false) )
| <GT> {tb.lBoundStrict=true;} ( LOOKAHEAD(IdentifierExpression() <LPARENTH>) tb.lBound = IdentifierExpression() | tb.lBound = Expression(false, false) )
| <LBRACKET> tb.lBound = Expression(false, false) <COMMA> tb.uBound = Expression(false, false) <RBRACKET> )
{ return tb; }
( ( <LE> ( LOOKAHEAD(IdentifierExpression() <LPARENTH>) uBound = IdentifierExpression() | uBound = Expression(false, false) ) { exprTemp.setUpperBound(uBound, false); } )
| ( <LT> ( LOOKAHEAD(IdentifierExpression() <LPARENTH>) uBound = IdentifierExpression() | uBound = Expression(false, false) ) { exprTemp.setUpperBound(uBound, true); } )
| ( <GE> ( LOOKAHEAD(IdentifierExpression() <LPARENTH>) lBound = IdentifierExpression() | lBound = Expression(false, false) ) { exprTemp.setLowerBound(lBound, false); } )
| ( <GT> ( LOOKAHEAD(IdentifierExpression() <LPARENTH>) lBound = IdentifierExpression() | lBound = Expression(false, false) ) { exprTemp.setLowerBound(lBound, true); } )
| ( <LBRACKET> lBound = Expression(false, false) <COMMA> uBound = Expression(false, false) <RBRACKET> { exprTemp.setLowerBound(lBound, false); exprTemp.setUpperBound(uBound, false); } )
| ( <EQ> lBound = Expression(false, false) { exprTemp.setEqualBounds(lBound); } )
)
}
// Expression: if-then-else, i.e. "cond ? then : else"

58
prism/src/parser/ast/ExpressionTemporal.java

@ -27,7 +27,7 @@
package parser.ast;
import parser.EvaluateContext;
import parser.visitor.*;
import parser.visitor.ASTVisitor;
import prism.PrismLangException;
public class ExpressionTemporal extends Expression
@ -57,6 +57,8 @@ public class ExpressionTemporal extends Expression
// Strictness of (time) bounds
protected boolean lBoundStrict = false; // true: >, false: >=
protected boolean uBoundStrict = false; // true: <, false: <=
// Display as =T rather than [T,T] ?
protected boolean equals = false;
// Constructors
@ -88,16 +90,8 @@ public class ExpressionTemporal extends Expression
operand2 = e2;
}
public int getNumOperands()
{
if (operand1 == null)
return 0;
else
return (operand2 == null) ? 1 : 2;
}
/**
* Set lower timer bound to be of form >= e
* Set lower time bound to be of form >= e
* (null denotes no lower bound, i.e. zero)
*/
public void setLowerBound(Expression e)
@ -106,7 +100,7 @@ public class ExpressionTemporal extends Expression
}
/**
* Set lower timer bound to be of form >= e or > e
* Set lower time bound to be of form >= e or > e
* (null denotes no lower bound, i.e. zero)
*/
public void setLowerBound(Expression e, boolean strict)
@ -116,7 +110,7 @@ public class ExpressionTemporal extends Expression
}
/**
* Set upper timer bound to be of form <= e
* Set upper time bound to be of form <= e
* (null denotes no upper bound, i.e. infinity)
*/
public void setUpperBound(Expression e)
@ -125,7 +119,7 @@ public class ExpressionTemporal extends Expression
}
/**
* Set upper timer bound to be of form <= e or < e
* Set upper time bound to be of form <= e or < e
* (null denotes no upper bound, i.e. infinity)
*/
public void setUpperBound(Expression e, boolean strict)
@ -134,6 +128,18 @@ public class ExpressionTemporal extends Expression
uBoundStrict = strict;
}
/**
* Set both lower/upper time bound to e, i.e. "=e".
*/
public void setEqualBounds(Expression e)
{
lBound = e;
lBoundStrict = false;
uBound = e;
uBoundStrict = false;
equals = true;
}
// Get methods
public int getOperator()
@ -156,6 +162,14 @@ public class ExpressionTemporal extends Expression
return operand2;
}
public int getNumOperands()
{
if (operand1 == null)
return 0;
else
return (operand2 == null) ? 1 : 2;
}
public boolean hasBounds()
{
return lBound != null || uBound != null;
@ -181,6 +195,14 @@ public class ExpressionTemporal extends Expression
return uBoundStrict;
}
/**
* Returns true if lower/upper bound are equal and should be displayed as =T
*/
public boolean getEquals()
{
return equals;
}
// Methods required for Expression:
/**
@ -236,7 +258,10 @@ public class ExpressionTemporal extends Expression
if (uBound == null) {
s += ">" + (lBoundStrict ? "" : "=") + lBound;
} else {
s += "[" + lBound + "," + uBound + "]";
if (equals)
s += "=" + lBound;
else
s += "[" + lBound + "," + uBound + "]";
}
}
if (operand2 != null)
@ -257,6 +282,7 @@ public class ExpressionTemporal extends Expression
expr.setOperand2(operand2.deepCopy());
expr.setLowerBound(lBound == null ? null : lBound.deepCopy(), lBoundStrict);
expr.setUpperBound(uBound == null ? null : uBound.deepCopy(), uBoundStrict);
expr.equals = equals;
expr.setType(type);
expr.setPosition(this);
return expr;
@ -280,6 +306,7 @@ public class ExpressionTemporal extends Expression
exprTemp = new ExpressionTemporal(P_U, op1, operand2);
exprTemp.setLowerBound(lBound, lBoundStrict);
exprTemp.setUpperBound(uBound, uBoundStrict);
exprTemp.equals = equals;
return exprTemp;
case P_G:
// G a == !(true U !a)
@ -288,6 +315,7 @@ public class ExpressionTemporal extends Expression
exprTemp = new ExpressionTemporal(P_U, op1, op2);
exprTemp.setLowerBound(lBound, lBoundStrict);
exprTemp.setUpperBound(uBound, uBoundStrict);
exprTemp.equals = equals;
return Expression.Not(exprTemp);
case P_W:
// a W b == !(a&!b U !a&!b)
@ -296,6 +324,7 @@ public class ExpressionTemporal extends Expression
exprTemp = new ExpressionTemporal(P_U, op1, op2);
exprTemp.setLowerBound(lBound, lBoundStrict);
exprTemp.setUpperBound(uBound, uBoundStrict);
exprTemp.equals = equals;
return Expression.Not(exprTemp);
case P_R:
// a R b == !(!a U !b)
@ -304,6 +333,7 @@ public class ExpressionTemporal extends Expression
exprTemp = new ExpressionTemporal(P_U, op1, op2);
exprTemp.setLowerBound(lBound, lBoundStrict);
exprTemp.setUpperBound(uBound, uBoundStrict);
exprTemp.equals = equals;
return Expression.Not(exprTemp);
}
throw new PrismLangException("Cannot convert " + getOperatorSymbol() + " to until form");

Loading…
Cancel
Save