enumerations.add(potential.getEnumeration());\r
}\r
\r
- EnumerationExpression expr = new EnumerationExpression(enumerations);\r
- \r
- // populate the created expression\r
- \r
// first check if the expression is just a (either one or two \r
// dimensional) list of values and just parse it if this is\r
// the case (should only happen if there is only one expression)\r
\r
+ // let enum x = {a,b,c}\r
+ //\r
+ // expand subscript expression over x with equations defined as\r
+ //\r
+ // foo[x] = 1,2,3\r
+ // \r
+ // into\r
+ //\r
+ // bar[a] = 1\r
+ // bar[b] = 2\r
+ // bar[c] = 3\r
+ \r
+ valuearray:\r
if (next == null) {\r
// number(,number)*\r
if (enumerations.size() == 1 && \r
Pattern.matches(MdlUtil.DBL+"(,"+MdlUtil.DBL+")*", getExpressionString())) {\r
+ EnumerationExpression expr = new EnumerationExpression(enumerations);\r
+ \r
String[] values = getExpressionString().split(",");\r
+ if (enumerations.get(0).getValues().size() != values.length) {\r
+ // could not find a value for each enumeration index, \r
+ // attempt to parse the equation normally\r
+ break valuearray;\r
+ }\r
for (int i = 0; i < values.length; i++) {\r
expr.addExpression(new NormalExpression(values[i]),\r
enumerations.get(0).getValues().get(i));\r
+ \r
}\r
+ \r
return expr;\r
}\r
// (number(,number)*;)*\r
else if (enumerations.size() == 2 && \r
- Pattern.matches("("+MdlUtil.DBL+"(,"+MdlUtil.DBL+")*;)*", getExpressionString())) {\r
+ Pattern.matches("("+MdlUtil.DBL+"(,"+MdlUtil.DBL+")*;)+", getExpressionString())) {\r
+ EnumerationExpression expr = new EnumerationExpression(enumerations);\r
+ \r
String[] rows = getExpressionString().split(";");\r
+ if (enumerations.get(0).getValues().size() != rows.length) {\r
+ // could not find a value for each enumeration index \r
+ // in the first enumeration, attempt to parse the equation \r
+ // normally\r
+ break valuearray;\r
+ }\r
for (int i = 0; i < rows.length; i++) {\r
String[] values = rows[i].split(",");\r
+ if (enumerations.get(1).getValues().size() != values.length) {\r
+ // could not find a value for each enumeration index\r
+ // in the second enumeration, attempt to parse the \r
+ // equation normally\r
+ break valuearray;\r
+ }\r
for (int j = 0; j < values.length; j++) {\r
expr.addExpression(new NormalExpression(values[j]),\r
enumerations.get(0).getValues().get(i),\r
enumerations.get(1).getValues().get(j));\r
}\r
}\r
+ \r
return expr;\r
}\r
}\r
\r
+ // expand the expressions to one expression for each combination of \r
+ // enumeration indices; this process must take into account the \r
+ // fact that some enumerations can be subsets of other enumerations \r
+ // and must be expanded accordingly\r
+ \r
+ // let enum x = {a,b,c} and enum y = {a,b}\r
+ //\r
+ // expand subscript expression over x with equations defined as\r
+ //\r
+ // foo[y] = bar[y]\r
+ // foo[c] = 10\r
+ //\r
+ // into:\r
+ //\r
+ // foo[a] = bar[a]\r
+ // foo[b] = bar[b]\r
+ // foo[c] = 10\r
+ \r
+ EnumerationExpression expr = new EnumerationExpression(enumerations);\r
+ \r
var = this;\r
while (var != null) {\r
\r
String expression = MdlUtil.finalize(we.expression, getMdl());\r
// TODO: is this check correct?\r
if (next == null) {\r
+ // Vensim allows comparison of subscript indices which\r
+ // is not a meaningful operation in sysdyn, so attempt\r
+ // to resolve and remove them here\r
expression = removeComparisons(expression, indices, we.indices);\r
}\r
expr.addExpression(parseExpression(expression), we.indices);\r