Browse Source

Added CTL operators to the parser.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@830 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 17 years ago
parent
commit
9ecd00a549
  1. 774
      prism/src/parser/PrismParser.java
  2. 46
      prism/src/parser/PrismParser.jj
  3. 158
      prism/src/parser/PrismParserConstants.java
  4. 580
      prism/src/parser/PrismParserTokenManager.java
  5. 115
      prism/src/parser/ast/ExpressionExists.java
  6. 115
      prism/src/parser/ast/ExpressionForAll.java
  7. 20
      prism/src/parser/visitor/ASTTraverse.java
  8. 20
      prism/src/parser/visitor/ASTTraverseModify.java
  9. 2
      prism/src/parser/visitor/ASTVisitor.java
  10. 14
      prism/src/parser/visitor/Rename.java
  11. 10
      prism/src/parser/visitor/TypeCheck.java

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

46
prism/src/parser/PrismParser.jj

@ -352,12 +352,14 @@ SPECIAL_TOKEN :
TOKEN :
{
// Keywords
< BOOL: "bool" >
< A: "A" >
| < BOOL: "bool" >
| < CONST: "const" >
| < CTMC: "ctmc" >
| < C: "C" >
| < DOUBLE: "double" >
| < DTMC: "dtmc" >
| < E: "E" >
| < ENDINIT: "endinit" >
| < ENDMODULE: "endmodule" >
| < ENDREWARDS: "endrewards" >
@ -1233,6 +1235,10 @@ Expression ExpressionBasic(boolean prop, boolean pathprop) :
ret = ExpressionSS(prop, pathprop)
|
ret = ExpressionReward(prop, pathprop)
|
ret = ExpressionExists(prop, pathprop)
|
ret = ExpressionForAll(prop, pathprop)
|
ret = ExpressionLabel(prop, pathprop)
)
@ -1501,6 +1507,44 @@ Expression ExpressionRewardContents(boolean prop, boolean pathprop) :
{ ret.setPosition(begin, getToken(0)); return ret; }
}
// (Property) expression: CTL existential operator E
Expression ExpressionExists(boolean prop, boolean pathprop) :
{
ExpressionExists ret = new ExpressionExists();
Expression expr;
Token begin = null;
}
{
// This production is only allowed in expressions if the "prop" parameter is true
{ if (!prop) throw generateParseException(); }
( begin = <E> <LBRACKET> expr = Expression(prop, true) <RBRACKET> )
{
ret.setExpression(expr);
ret.setPosition(begin, getToken(0));
return ret;
}
}
// (Property) expression: CTL universal operator A
Expression ExpressionForAll(boolean prop, boolean pathprop) :
{
ExpressionForAll ret = new ExpressionForAll();
Expression expr;
Token begin = null;
}
{
// This production is only allowed in expressions if the "prop" parameter is true
{ if (!prop) throw generateParseException(); }
( begin = <A> <LBRACKET> expr = Expression(prop, true) <RBRACKET> )
{
ret.setExpression(expr);
ret.setPosition(begin, getToken(0));
return ret;
}
}
// (Property) expression: label (including "init")
Expression ExpressionLabel(boolean prop, boolean pathprop) :

158
prism/src/parser/PrismParserConstants.java

@ -6,83 +6,85 @@ public interface PrismParserConstants {
int EOF = 0;
int WHITESPACE = 1;
int COMMENT = 2;
int BOOL = 3;
int CONST = 4;
int CTMC = 5;
int C = 6;
int DOUBLE = 7;
int DTMC = 8;
int ENDINIT = 9;
int ENDMODULE = 10;
int ENDREWARDS = 11;
int ENDSYSTEM = 12;
int FALSE = 13;
int FORMULA = 14;
int FUNC = 15;
int F = 16;
int GLOBAL = 17;
int G = 18;
int INIT = 19;
int I = 20;
int INT = 21;
int LABEL = 22;
int MAX = 23;
int MDP = 24;
int MIN = 25;
int MODULE = 26;
int X = 27;
int NONDETERMINISTIC = 28;
int PMAX = 29;
int PMIN = 30;
int P = 31;
int PROBABILISTIC = 32;
int PROB = 33;
int RATE = 34;
int REWARDS = 35;
int RMAX = 36;
int RMIN = 37;
int R = 38;
int S = 39;
int STOCHASTIC = 40;
int SYSTEM = 41;
int TRUE = 42;
int U = 43;
int W = 44;
int NOT = 45;
int AND = 46;
int OR = 47;
int IMPLIES = 48;
int RARROW = 49;
int COLON = 50;
int SEMICOLON = 51;
int COMMA = 52;
int DOTS = 53;
int LPARENTH = 54;
int RPARENTH = 55;
int LBRACKET = 56;
int RBRACKET = 57;
int LBRACE = 58;
int RBRACE = 59;
int EQ = 60;
int NE = 61;
int LT = 62;
int GT = 63;
int LE = 64;
int GE = 65;
int PLUS = 66;
int MINUS = 67;
int TIMES = 68;
int DIVIDE = 69;
int PRIME = 70;
int RENAME = 71;
int QMARK = 72;
int DQUOTE = 73;
int REG_INT = 74;
int REG_DOUBLE = 75;
int REG_IDENTPRIME = 76;
int REG_IDENT = 77;
int PREPROC = 78;
int LEXICAL_ERROR = 79;
int A = 3;
int BOOL = 4;
int CONST = 5;
int CTMC = 6;
int C = 7;
int DOUBLE = 8;
int DTMC = 9;
int E = 10;
int ENDINIT = 11;
int ENDMODULE = 12;
int ENDREWARDS = 13;
int ENDSYSTEM = 14;
int FALSE = 15;
int FORMULA = 16;
int FUNC = 17;
int F = 18;
int GLOBAL = 19;
int G = 20;
int INIT = 21;
int I = 22;
int INT = 23;
int LABEL = 24;
int MAX = 25;
int MDP = 26;
int MIN = 27;
int MODULE = 28;
int X = 29;
int NONDETERMINISTIC = 30;
int PMAX = 31;
int PMIN = 32;
int P = 33;
int PROBABILISTIC = 34;
int PROB = 35;
int RATE = 36;
int REWARDS = 37;
int RMAX = 38;
int RMIN = 39;
int R = 40;
int S = 41;
int STOCHASTIC = 42;
int SYSTEM = 43;
int TRUE = 44;
int U = 45;
int W = 46;
int NOT = 47;
int AND = 48;
int OR = 49;
int IMPLIES = 50;
int RARROW = 51;
int COLON = 52;
int SEMICOLON = 53;
int COMMA = 54;
int DOTS = 55;
int LPARENTH = 56;
int RPARENTH = 57;
int LBRACKET = 58;
int RBRACKET = 59;
int LBRACE = 60;
int RBRACE = 61;
int EQ = 62;
int NE = 63;
int LT = 64;
int GT = 65;
int LE = 66;
int GE = 67;
int PLUS = 68;
int MINUS = 69;
int TIMES = 70;
int DIVIDE = 71;
int PRIME = 72;
int RENAME = 73;
int QMARK = 74;
int DQUOTE = 75;
int REG_INT = 76;
int REG_DOUBLE = 77;
int REG_IDENTPRIME = 78;
int REG_IDENT = 79;
int PREPROC = 80;
int LEXICAL_ERROR = 81;
int DEFAULT = 0;
@ -90,12 +92,14 @@ public interface PrismParserConstants {
"<EOF>",
"<WHITESPACE>",
"<COMMENT>",
"\"A\"",
"\"bool\"",
"\"const\"",
"\"ctmc\"",
"\"C\"",
"\"double\"",
"\"dtmc\"",
"\"E\"",
"\"endinit\"",
"\"endmodule\"",
"\"endrewards\"",

580
prism/src/parser/PrismParserTokenManager.java
File diff suppressed because it is too large
View File

115
prism/src/parser/ast/ExpressionExists.java

@ -0,0 +1,115 @@
//==============================================================================
//
// Copyright (c) 2002-
// Authors:
// * Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford, formerly University of Birmingham)
//
//------------------------------------------------------------------------------
//
// This file is part of PRISM.
//
// PRISM is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PRISM is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with PRISM; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//==============================================================================
package parser.ast;
import parser.*;
import parser.visitor.*;
import prism.PrismLangException;
public class ExpressionExists extends Expression
{
Expression expression = null;
// Constructors
public ExpressionExists()
{
}
public ExpressionExists(Expression e)
{
expression = e;
}
// Set methods
public void setExpression(Expression e)
{
expression = e;
}
// Get methods
public Expression getExpression()
{
return expression;
}
// Methods required for Expression:
/**
* Is this expression constant?
*/
public boolean isConstant()
{
return false;
}
/**
* Evaluate this expression, return result.
* Note: assumes that type checking has been done already.
*/
public Object evaluate(Values constantValues, Values varValues) throws PrismLangException
{
throw new PrismLangException("Cannot evaluate an E operator without a model");
}
// Methods required for ASTElement:
/**
* Visitor method.
*/
public Object accept(ASTVisitor v) throws PrismLangException
{
return v.visit(this);
}
/**
* Convert to string.
*/
public String toString()
{
String s = "";
s += "E [ " + expression + " ]";
return s;
}
/**
* Perform a deep copy.
*/
public Expression deepCopy()
{
ExpressionExists expr = new ExpressionExists(expression.deepCopy());
expr.setType(type);
expr.setPosition(this);
return expr;
}
}
//------------------------------------------------------------------------------

115
prism/src/parser/ast/ExpressionForAll.java

@ -0,0 +1,115 @@
//==============================================================================
//
// Copyright (c) 2002-
// Authors:
// * Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford, formerly University of Birmingham)
//
//------------------------------------------------------------------------------
//
// This file is part of PRISM.
//
// PRISM is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PRISM is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with PRISM; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//==============================================================================
package parser.ast;
import parser.*;
import parser.visitor.*;
import prism.PrismLangException;
public class ExpressionForAll extends Expression
{
Expression expression = null;
// Constructors
public ExpressionForAll()
{
}
public ExpressionForAll(Expression e)
{
expression = e;
}
// Set methods
public void setExpression(Expression e)
{
expression = e;
}
// Get methods
public Expression getExpression()
{
return expression;
}
// Methods required for Expression:
/**
* Is this expression constant?
*/
public boolean isConstant()
{
return false;
}
/**
* Evaluate this expression, return result.
* Note: assumes that type checking has been done already.
*/
public Object evaluate(Values constantValues, Values varValues) throws PrismLangException
{
throw new PrismLangException("Cannot evaluate an E operator without a model");
}
// Methods required for ASTElement:
/**
* Visitor method.
*/
public Object accept(ASTVisitor v) throws PrismLangException
{
return v.visit(this);
}
/**
* Convert to string.
*/
public String toString()
{
String s = "";
s += "A [ " + expression + " ]";
return s;
}
/**
* Perform a deep copy.
*/
public Expression deepCopy()
{
ExpressionForAll expr = new ExpressionForAll(expression.deepCopy());
expr.setType(type);
expr.setPosition(this);
return expr;
}
}
//------------------------------------------------------------------------------

20
prism/src/parser/visitor/ASTTraverse.java

@ -446,6 +446,26 @@ public class ASTTraverse implements ASTVisitor
}
public void visitPost(ExpressionSS e) throws PrismLangException { defaultVisitPost(e); }
// -----------------------------------------------------------------------------------
public void visitPre(ExpressionExists e) throws PrismLangException { defaultVisitPre(e); }
public Object visit(ExpressionExists e) throws PrismLangException
{
visitPre(e);
if (e.getExpression() != null) e.getExpression().accept(this);
visitPost(e);
return null;
}
public void visitPost(ExpressionExists e) throws PrismLangException { defaultVisitPost(e); }
// -----------------------------------------------------------------------------------
public void visitPre(ExpressionForAll e) throws PrismLangException { defaultVisitPre(e); }
public Object visit(ExpressionForAll e) throws PrismLangException
{
visitPre(e);
if (e.getExpression() != null) e.getExpression().accept(this);
visitPost(e);
return null;
}
public void visitPost(ExpressionForAll e) throws PrismLangException { defaultVisitPost(e); }
// -----------------------------------------------------------------------------------
public void visitPre(ExpressionLabel e) throws PrismLangException { defaultVisitPre(e); }
public Object visit(ExpressionLabel e) throws PrismLangException
{

20
prism/src/parser/visitor/ASTTraverseModify.java

@ -448,6 +448,26 @@ public class ASTTraverseModify implements ASTVisitor
}
public void visitPost(ExpressionSS e) throws PrismLangException { defaultVisitPost(e); }
// -----------------------------------------------------------------------------------
public void visitPre(ExpressionExists e) throws PrismLangException { defaultVisitPre(e); }
public Object visit(ExpressionExists e) throws PrismLangException
{
visitPre(e);
if (e.getExpression() != null) e.setExpression((Expression)(e.getExpression().accept(this)));
visitPost(e);
return e;
}
public void visitPost(ExpressionExists e) throws PrismLangException { defaultVisitPost(e); }
// -----------------------------------------------------------------------------------
public void visitPre(ExpressionForAll e) throws PrismLangException { defaultVisitPre(e); }
public Object visit(ExpressionForAll e) throws PrismLangException
{
visitPre(e);
if (e.getExpression() != null) e.setExpression((Expression)(e.getExpression().accept(this)));
visitPost(e);
return e;
}
public void visitPost(ExpressionForAll e) throws PrismLangException { defaultVisitPost(e); }
// -----------------------------------------------------------------------------------
public void visitPre(ExpressionLabel e) throws PrismLangException { defaultVisitPre(e); }
public Object visit(ExpressionLabel e) throws PrismLangException
{

2
prism/src/parser/visitor/ASTVisitor.java

@ -67,6 +67,8 @@ public interface ASTVisitor
public Object visit(ExpressionProb e) throws PrismLangException;
public Object visit(ExpressionReward e) throws PrismLangException;
public Object visit(ExpressionSS e) throws PrismLangException;
public Object visit(ExpressionExists e) throws PrismLangException;
public Object visit(ExpressionForAll e) throws PrismLangException;
public Object visit(ExpressionLabel e) throws PrismLangException;
// ASTElement classes (misc.)
public Object visit(Filter e) throws PrismLangException;

14
prism/src/parser/visitor/Rename.java

@ -133,5 +133,19 @@ public class Rename extends ASTTraverseModify
// at the level of an individual module (and below)
throw new PrismLangException("S operator should never be renamed");
}
public void visitPost(ExpressionExists e) throws PrismLangException
{
// This renaming is only designed to be applied
// at the level of an individual module (and below)
throw new PrismLangException("E operator should never be renamed");
}
public void visitPost(ExpressionForAll e) throws PrismLangException
{
// This renaming is only designed to be applied
// at the level of an individual module (and below)
throw new PrismLangException("A operator should never be renamed");
}
}

10
prism/src/parser/visitor/TypeCheck.java

@ -443,6 +443,16 @@ public class TypeCheck extends ASTTraverse
e.setType(e.getProb() == null ? Expression.DOUBLE : Expression.BOOLEAN);
}
public void visitPost(ExpressionExists e) throws PrismLangException
{
e.setType(Expression.BOOLEAN);
}
public void visitPost(ExpressionForAll e) throws PrismLangException
{
e.setType(Expression.BOOLEAN);
}
public void visitPost(ExpressionLabel e) throws PrismLangException
{
e.setType(Expression.BOOLEAN);

Loading…
Cancel
Save