Browse Source

Allow computeProbNesting to follow property references.

accumulation-v4.7
Dave Parker 7 years ago
parent
commit
be8a812143
  1. 11
      prism/src/parser/ast/ASTElement.java
  2. 23
      prism/src/parser/visitor/ComputeProbNesting.java

11
prism/src/parser/ast/ASTElement.java

@ -496,6 +496,17 @@ public abstract class ASTElement
return visitor.getMaxNesting();
}
/**
* Compute (maximum) number of nested probabilistic operators (P, S, R).
* Optionally, pass a properties file for looking up property references.
*/
public int computeProbNesting(PropertiesFile propertiesFile) throws PrismLangException
{
ComputeProbNesting visitor = new ComputeProbNesting(propertiesFile);
accept(visitor);
return visitor.getMaxNesting();
}
/**
* Convert to string showing tree representation.
*/

23
prism/src/parser/visitor/ComputeProbNesting.java

@ -34,11 +34,20 @@ import prism.PrismLangException;
*/
public class ComputeProbNesting extends ASTTraverse
{
// Optional properties file to look up property references;
PropertiesFile propertiesFile = null;
private int currentNesting;
private int maxNesting;
public ComputeProbNesting()
{
this(null);
}
public ComputeProbNesting(PropertiesFile propertiesFile)
{
this.propertiesFile = propertiesFile;
currentNesting = 0;
maxNesting = 0;
}
@ -80,5 +89,17 @@ public class ComputeProbNesting extends ASTTraverse
{
currentNesting--;
}
public void visitPost(ExpressionProp e) throws PrismLangException
{
// If possible, look up property and recurse
if (propertiesFile != null) {
Property prop = propertiesFile.lookUpPropertyObjectByName(e.getName());
if (prop != null) {
prop.accept(this);
} else {
throw new PrismLangException("Unknown property reference " + e, e);
}
}
}
}
Loading…
Cancel
Save