\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class Addition implements IExpression {\r
\r
public IExpression exp1;\r
if(o1 instanceof Array && o2 instanceof Array) {\r
Array la = (Array)o1;\r
Array ra = (Array)o2;\r
- return la.add(ra);\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)+((Double)o2);\r
+ throw new IllegalStateException("Tried to add a non-numerical array");\r
+ }\r
+ });\r
}\r
throw new IllegalStateException();\r
}\r
import java.util.List;\r
import java.util.Map;\r
\r
+/*\r
+ * For matrices first dimension is rows and second is columns i.e. top level elements are rows\r
+ */\r
public class Array implements IExpression {\r
\r
public static final Array FULL = new Array();\r
\r
final private ArrayList<Object> elements;\r
+ \r
+ boolean isVector = true;\r
\r
public Array() {\r
elements = new ArrayList<Object>();\r
\r
public Array addElement(Object element) {\r
if(element instanceof Constant) addElement(((Constant)element).value);\r
- else elements.add(element);\r
+ else {\r
+ \r
+// if(element instanceof Double)\r
+// if(Double.isNaN((Double)element))\r
+// throw new IllegalStateException();\r
+\r
+ if(element instanceof Array) isVector = false;\r
+ elements.add(element);\r
+ }\r
return this;\r
}\r
\r
}\r
\r
public int size(int col) {\r
- return elements.size();\r
+ \r
+ if(col == 1) return elements.size();\r
+\r
+ if(elements.isEmpty()) throw new IllegalStateException();\r
+ Object elem = element(0);\r
+ if(!(elem instanceof Array)) throw new IllegalStateException();\r
+ \r
+ return ((Array)elem).size(col-1);\r
+ \r
}\r
\r
public Object element(int index) {\r
throw new IllegalStateException();\r
\r
}\r
- \r
- public Array add(Array other) {\r
- Array result = new Array();\r
+\r
+ /*\r
+ * Both arrays are vectors \r
+ */\r
+ public double inner(Array other) {\r
+ double result = 0;\r
Collection<Object> lae = elements();\r
Collection<Object> rae = other.elements();\r
- if(lae.size() != rae.size()) throw new IllegalStateException();\r
+ if(lae.size() != rae.size()) throw new IllegalStateException("inner product: vector sizes do not match: " + this + " vs. " + other);\r
Iterator<Object> li = lae.iterator();\r
Iterator<Object> ri = rae.iterator();\r
for(int i=0;i<lae.size();i++) {\r
Object l = li.next();\r
Object r = ri.next();\r
if(l instanceof Double && r instanceof Double) {\r
- result.addElement(((Double)l)+((Double)r));\r
- } else if (l instanceof Array && r instanceof Array) {\r
- Array arr = (Array)l;\r
- Array otherArr = (Array)r;\r
- result.addElement(arr.add(otherArr));\r
+ result += ((Double)l)*((Double)r);\r
} else {\r
throw new IllegalStateException();\r
}\r
return result;\r
}\r
\r
- public Array mul(Array other) {\r
+ /*\r
+ * Other array is vector (this is matrix)\r
+ */\r
+ public Array matrixMulVector(Array other) {\r
Array result = new Array();\r
- Collection<Object> lae = elements();\r
- Collection<Object> rae = other.elements();\r
- if(lae.size() != rae.size()) throw new IllegalStateException();\r
- Iterator<Object> li = lae.iterator();\r
- Iterator<Object> ri = rae.iterator();\r
- for(int i=0;i<lae.size();i++) {\r
- Object l = li.next();\r
- Object r = ri.next();\r
- if(l instanceof Double && r instanceof Double) {\r
- result.addElement(((Double)l)*((Double)r));\r
- } else if (l instanceof Array && r instanceof Array) {\r
- Array arr = (Array)l;\r
- Array otherArr = (Array)r;\r
- result.addElement(arr.mul(otherArr));\r
- } else {\r
- throw new IllegalStateException();\r
- }\r
+ for(Object o : elements) {\r
+ // Objects are rows\r
+ Array a = (Array)o;\r
+ result.addElement(a.inner(other));\r
}\r
return result;\r
}\r
\r
+ /*\r
+ * Other array is matrix (this is matrix)\r
+ */\r
+ public Array matrixMulMatrix(Array other) {\r
+ Array result = new Array();\r
+ Array transposed = other.transposed();\r
+ for(Object rightColumn_ : transposed.elements()) {\r
+ Array rightColumn = (Array)rightColumn_;\r
+ Array resultColumn = new Array();\r
+ for(Object leftRow_ : elements) {\r
+ Array leftRow = (Array)leftRow_;\r
+ resultColumn.addElement(leftRow.inner(rightColumn));\r
+ }\r
+ result.addElement(resultColumn);\r
+ }\r
+ return result.transposed();\r
+ }\r
+\r
public Array pow(Array other) {\r
Array result = new Array();\r
Collection<Object> lae = elements();\r
}\r
return result;\r
}\r
+ \r
+ interface Modifier {\r
+ Object modify(Object o);\r
+ }\r
+ \r
+ interface Modifier2 {\r
+ Object modify(Object o1, Object o2);\r
+ }\r
+\r
+ public Array copy(Modifier modifier) {\r
+ Array result = new Array();\r
+ for(Object element : elements) {\r
+ if(element instanceof Array) {\r
+ Array sub = (Array)element;\r
+ result.addElement(sub.copy(modifier));\r
+ } else {\r
+ result.addElement(modifier.modify(element));\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ public Array copy2(Array other, Modifier2 modifier) {\r
+ Array result = new Array();\r
+ Collection<Object> es = elements();\r
+ Collection<Object> oes = other.elements();\r
+ if(es.size() != oes.size()) throw new IllegalStateException("Array dimensions do not match");\r
+ Iterator<Object> e = es.iterator();\r
+ Iterator<Object> oe = oes.iterator();\r
+ for(int i=0;i<es.size();i++) {\r
+ Object element = e.next();\r
+ Object otherElement = oe.next();\r
+ if(element instanceof Array) {\r
+ if(otherElement instanceof Array) {\r
+ result.addElement(((Array)element).copy2((Array)otherElement, modifier));\r
+ } else {\r
+ throw new IllegalStateException("Array dimensions do not match");\r
+ }\r
+ } else {\r
+ if(otherElement instanceof Array) {\r
+ throw new IllegalStateException("Array dimensions do not match");\r
+ } else {\r
+ result.addElement(modifier.modify(element, otherElement));\r
+ }\r
+ } \r
+ }\r
+ return result;\r
+ }\r
+\r
+ public boolean isVector() {\r
+ return isVector;\r
+ }\r
+\r
+ private Object subscript(IEnvironment environment, IExpression[] subscripts, int position) {\r
+ \r
+ IExpression e = subscripts[position];\r
+ Object indexObject = e.evaluate(environment);\r
+ int index = Utils.getIndex(indexObject);\r
+ if(index == -2) {\r
+ Array ret = new Array();\r
+ for(Object element : elements) {\r
+ // Last position should not be array\r
+ if(position == subscripts.length-1) {\r
+ if(element instanceof Array) throw new IllegalStateException();\r
+ if(element instanceof IExpression) {\r
+ IExpression exp = (IExpression)element;\r
+ ret.addElement(exp.evaluate(environment));\r
+ } else {\r
+ ret.addElement(element);\r
+ }\r
+ } else {\r
+ if(element instanceof Array) {\r
+ ret.addElement(((Array)element).subscript(environment, subscripts, position+1));\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ }\r
+ return ret;\r
+ } else if (index == -3) {\r
+ \r
+ Array arr = (Array)indexObject;\r
+ Array ret = new Array();\r
+ for(Object indexO : arr.elements()) {\r
+ index = ((Double)indexO).intValue()-1;\r
+ Object element = element(index);\r
+ // Last position should not be array\r
+ if(position == subscripts.length-1) {\r
+ if(element instanceof Array) throw new IllegalStateException();\r
+ if(element instanceof IExpression) {\r
+ IExpression exp = (IExpression)element;\r
+ ret.addElement(exp.evaluate(environment));\r
+ } else {\r
+ ret.addElement(element);\r
+ }\r
+ } else {\r
+ if(element instanceof Array) {\r
+ ret.addElement(((Array)element).subscript(environment, subscripts, position+1));\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ }\r
+ return ret;\r
+ \r
+ } else {\r
+ Object element = element(index);\r
+ // Last position should not be array\r
+ if(position == subscripts.length-1) {\r
+ if(element instanceof Array) throw new ExecutionException("Array size does not match subscripts.");\r
+ if(element instanceof IExpression) {\r
+ IExpression exp = (IExpression)element;\r
+ return exp.evaluate(environment);\r
+ } else {\r
+ return element;\r
+ }\r
+ } else {\r
+ if(element instanceof Array) {\r
+ return ((Array)element).subscript(environment, subscripts, position+1);\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ }\r
+ \r
+ }\r
+ \r
+ public Object subscript(IEnvironment environment, IExpression[] subscripts) {\r
+ return subscript(environment, subscripts, 0);\r
+ }\r
+\r
+ public void applyPartial(Array[] indices, Array value, int pos) {\r
+ Array arr = indices[pos];\r
+ if(Array.FULL == arr) {\r
+ for(int i=0;i<elements.size();i++) {\r
+ if(pos < (indices.length-1)) {\r
+ ((Array)elements.get(i)).applyPartial(indices, (Array)value.element(i), pos+1);\r
+ } else {\r
+ elements.set(i, value.element(i));\r
+ }\r
+ }\r
+ } else if(arr.dimension() == 1) {\r
+ int index = ((Double)arr.element(0)).intValue();\r
+ if(pos < (indices.length-1)) {\r
+ ((Array)elements.get(index)).applyPartial(indices, value, pos+1);\r
+ } else {\r
+ elements.set(index, (Array)value.element(index));\r
+ }\r
+ } else {\r
+ for(Object element : arr.elements) {\r
+ int i = ((Double)element).intValue();\r
+ if(pos < (indices.length-1)) {\r
+ ((Array)elements.get(i)).applyPartial(indices, (Array)value.element(i), pos+1);\r
+ } else {\r
+ elements.set(i, value.element(i));\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ public void applyPartial(Array[] indices, Array value) {\r
+ applyPartial(indices, value, 0);\r
+ }\r
+ \r
+ public Array transposed() {\r
+ \r
+ List<Object> elements = elements();\r
+ if(elements.isEmpty()) return this;\r
+ \r
+ Array first = (Array)elements.get(0);\r
+ \r
+ Array[] arrs = new Array[first.elements().size()];\r
+ for(int i=0;i<arrs.length;i++) arrs[i] = new Array();\r
+ \r
+ for(int i=0;i<elements.size();i++) {\r
+ Array a = (Array)elements.get(i);\r
+ for(int j=0;j<a.elements().size();j++) {\r
+ Object o = a.element(j);\r
+ arrs[j].addElement(o);\r
+ }\r
+ }\r
+\r
+ Array result = new Array();\r
+ for(Array a : arrs) result.addElement(a);\r
+\r
+ return result;\r
+ \r
+ }\r
\r
}\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
-\r
public class Assignment {\r
- \r
+\r
+ private static final boolean VALIDATE = true; \r
+\r
+ public IFrame model;\r
public Variable target;\r
public IExpression[] subscripts;\r
public IExpression expression;\r
public boolean assigned = false;\r
public boolean isConstant = false;\r
\r
- public Assignment(Variable target, IExpression[] subscripts, IExpression expression) {\r
+ public Assignment(IFrame model, Variable target, IExpression[] subscripts, IExpression expression) {\r
+ this.model = model;\r
this.target = target;\r
this.subscripts = subscripts;\r
this.expression = expression;\r
IExpression[] subscripts2 = new IExpression[subscripts.length];\r
for(int i=0;i<subscripts.length;i++)\r
subscripts2[i] = subscripts[i].withBase(frame, prefix);\r
- return new Assignment(target.withBase(frame, prefix), subscripts2, expression.withBase(frame, prefix));\r
+ return new Assignment(frame, target.withBase(frame, prefix), subscripts2, expression.withBase(frame, prefix));\r
} else {\r
- return new Assignment(target.withBase(frame, prefix), null, expression.withBase(frame, prefix));\r
+ return new Assignment(frame, target.withBase(frame, prefix), null, expression.withBase(frame, prefix));\r
+ }\r
+ }\r
+ \r
+ public void assign(IEnvironment env) {\r
+ try {\r
+ Object value = expression.evaluate(env);\r
+ if(value != null) {\r
+ validate(target, value);\r
+ target.assign(env, subscripts, value);\r
+ assigned = true;\r
+ }\r
+ } catch (ExecutionException e) {\r
+ if(model instanceof Model) {\r
+ throw new ExecutionException("Line " + (target.line-((Model)model).line) + ": while evaluating " + target.base.name + ": " + e.getMessage());\r
+ } else {\r
+ throw new ExecutionException("While evaluating " + target.base.name + ": " + e.getMessage());\r
+ }\r
}\r
}\r
\r
+ \r
+ private void validate(Variable var, Object value) {\r
+ if(VALIDATE) {\r
+ if(value instanceof Double) {\r
+ if(Double.isNaN((Double)value)) {\r
+ System.err.println("value is invalid (NaN): " + var.base.name);\r
+ throw new IllegalStateException("value is invalid (NaN)");\r
+ }\r
+ if(Double.isInfinite((Double)value)) {\r
+ System.err.println("value is invalid (Infinite): " + var.base.name);\r
+ throw new IllegalStateException("value is invalid (Infinite)");\r
+ }\r
+ }\r
+ if(value instanceof Array) {\r
+ for(Object o : ((Array)value).elements()) validate(var, o);\r
+ }\r
+ }\r
+ }\r
+ \r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Semantum Oy.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package fi.semantum.sysdyn.solver;\r
+\r
+\r
+public class Break implements IStatement {\r
+ \r
+ public Break() {\r
+ }\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return "break";\r
+ }\r
+ \r
+ @Override\r
+ public ReturnValue evaluate(IEnvironment environment) {\r
+ return ReturnValue.BREAK;\r
+ }\r
+ \r
+}\r
\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class Derivate implements IExpression {\r
\r
private Variable variable;\r
\r
@Override\r
public Object evaluate(IEnvironment _environment) {\r
- Environment environment = (Environment)_environment;\r
-// Double old = (Double)environment.getValue(variable.name + variable.subscriptKey());\r
- Double old = (Double)environment.getValue(variable.base.index(_environment, subscripts));\r
+ final Environment environment = (Environment)_environment;\r
+ Object old = variable.evaluate(environment);\r
+ \r
// FIXME: should not be fixed like this\r
if(old == null) old = 0.0;\r
- return old+environment.step*(Double)e.evaluate(environment);\r
+ Object eval = e.evaluate(environment);\r
+ if(eval instanceof Double) {\r
+ return ((Double)old)+environment.step*(Double)eval;\r
+ } else if (eval instanceof Array) {\r
+ Array arr = (Array)eval;\r
+ Array oldArray = (Array)old;\r
+ \r
+ return oldArray.copy2(arr, new Modifier2() {\r
+\r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ Double oldValue = (Double)o1;\r
+ Double der = (Double)o2;\r
+ return oldValue + environment.step*der;\r
+ }\r
+ \r
+ });\r
+ \r
+ } else {\r
+ throw new UnsupportedOperationException();\r
+ }\r
}\r
\r
@Override\r
\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+\r
public class Division implements IExpression {\r
\r
public IExpression exp1;\r
return exp1 + " / " + exp2;\r
}\r
\r
- private Array arrayDiv(Array a, Double d) {\r
- Array result = new Array();\r
- for(Object o : a.elements()) {\r
- if(o instanceof Double) {\r
- result.addElement((Double)o/d);\r
- } else {\r
- throw new IllegalStateException();\r
- }\r
- }\r
- return result;\r
+ private Array arrayDiv(Array a, final Double d) {\r
+ return a.copy(new Modifier() {\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ return ((Double)o)/d;\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ });\r
}\r
\r
@Override\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Semantum Oy.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package fi.semantum.sysdyn.solver;\r
+\r
+import java.util.Map;\r
+\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
+public class ElementwiseAddition implements IExpression {\r
+ \r
+ public IExpression exp1;\r
+ public IExpression exp2;\r
+ \r
+ public ElementwiseAddition(IExpression exp1, IExpression exp2) {\r
+ this.exp1 = exp1;\r
+ this.exp2 = exp2;\r
+ }\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return exp1 + " + " + exp2;\r
+ }\r
+ \r
+ @Override\r
+ public Object evaluate(IEnvironment environment) {\r
+ Object o1 = exp1.evaluate(environment);\r
+ Object o2 = exp2.evaluate(environment);\r
+ if(o1 == null || o2 == null) return null; \r
+ if(o1 instanceof Double && o2 instanceof Double) {\r
+ return (Double)o1 + (Double)o2;\r
+ }\r
+ if(o1 instanceof Array && o2 instanceof Array) {\r
+ Array la = (Array)o1;\r
+ Array ra = (Array)o2;\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)+((Double)o2);\r
+ throw new IllegalStateException("Tried to add a non-numerical array");\r
+ }\r
+ });\r
+ }\r
+ throw new IllegalStateException();\r
+ }\r
+ \r
+ @Override\r
+ public IExpression withBase(IFrame frame, String prefix) {\r
+ return new ElementwiseAddition(exp1.withBase(frame, prefix), exp2.withBase(frame, prefix));\r
+ }\r
+ \r
+ @Override\r
+ public Object getPossibleConstant() {\r
+ return null;\r
+ }\r
+ \r
+ @Override\r
+ public IExpression rewrite(IFrame frame, Map<String, VariableBase> copies) {\r
+ exp1 = exp1.rewrite(frame, copies);\r
+ exp2 = exp2.rewrite(frame, copies);\r
+ return this;\r
+ }\r
+ \r
+ @Override\r
+ public void accept(ExpressionVisitor visitor) {\r
+ visitor.visit(this);\r
+ exp1.accept(visitor);\r
+ exp2.accept(visitor);\r
+ }\r
+ \r
+}\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class ElementwiseDivision implements IExpression {\r
\r
public IExpression exp1;\r
if(left instanceof Array && right instanceof Array) {\r
Array la = (Array)left;\r
Array ra = (Array)right;\r
- Collection<Object> lae = la.elements();\r
- Collection<Object> rae = ra.elements();\r
- if(lae.size() != rae.size()) throw new UnsupportedOperationException();\r
- Iterator<Object> li = lae.iterator();\r
- Iterator<Object> ri = rae.iterator();\r
- Array result = new Array();\r
- for(int i=0;i<lae.size();i++) {\r
- double ld = (Double)li.next();\r
- double rd = (Double)ri.next();\r
- result.addElement(ld/rd);\r
- }\r
- return result;\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)/((Double)o2);\r
+ throw new IllegalStateException("Tried to divide a non-numerical array");\r
+ }\r
+ \r
+ });\r
} else if(left instanceof Array && right instanceof Double) {\r
Array la = (Array)left;\r
- double rd = (Double)right;\r
- Collection<Object> lae = la.elements();\r
- Iterator<Object> li = lae.iterator();\r
- Array result = new Array();\r
- for(int i=0;i<lae.size();i++) {\r
- double ld = (Double)li.next();\r
- result.addElement(ld/rd);\r
- }\r
- return result;\r
+ final double rd = (Double)right;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return ((Double)o)/rd;\r
+ else throw new IllegalStateException("Tried to divide a non-numerical array");\r
+ }\r
+ \r
+ });\r
+ } else if(left instanceof Double && right instanceof Array) {\r
+ Array la = (Array)right;\r
+ final double rd = (Double)left;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return rd / ((Double)o);\r
+ else throw new IllegalStateException("Tried to divide a non-numerical array");\r
+ }\r
+ \r
+ });\r
+ } else if(left instanceof Double && right instanceof Double) {\r
+ return ((Double)left)/((Double)right);\r
} else {\r
throw new UnsupportedOperationException();\r
}\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class ElementwisePower implements IExpression {\r
\r
public IExpression exp1;\r
if(left instanceof Array && right instanceof Array) {\r
Array la = (Array)left;\r
Array ra = (Array)right;\r
- Collection<Object> lae = la.elements();\r
- Collection<Object> rae = ra.elements();\r
- if(lae.size() != rae.size()) throw new UnsupportedOperationException();\r
- Iterator<Object> li = lae.iterator();\r
- Iterator<Object> ri = rae.iterator();\r
- Array result = new Array();\r
- for(int i=0;i<lae.size();i++) {\r
- double ld = (Double)li.next();\r
- double rd = (Double)ri.next();\r
- result.addElement(Math.pow(ld,rd));\r
- }\r
- return result;\r
- } else throw new UnsupportedOperationException();\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return Math.pow((Double)o1,(Double)o2);\r
+ throw new IllegalStateException("Tried to pow a non-numerical array");\r
+ }\r
+ });\r
+ } else if (left instanceof Array && right instanceof Double) {\r
+ Array la = (Array)left;\r
+ final double rd = (Double)right;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return Math.pow((Double)o,rd);\r
+ else throw new IllegalStateException("Tried to pow a non-numerical array");\r
+ }\r
+ \r
+ });\r
+ } else if (left instanceof Double && right instanceof Array) {\r
+ Array la = (Array)right;\r
+ final double rd = (Double)left;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return Math.pow(rd,(Double)o);\r
+ else throw new IllegalStateException("Tried to pow a non-numerical array");\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new UnsupportedOperationException();\r
+ }\r
}\r
\r
@Override\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-import java.util.List;\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class ElementwiseProduct implements IExpression {\r
\r
public IExpression exp1;\r
if(left instanceof Array && right instanceof Array) {\r
Array la = (Array)left;\r
Array ra = (Array)right;\r
- List<Object> lae = la.elements();\r
- List<Object> rae = ra.elements();\r
- if(lae.size() != rae.size()) throw new UnsupportedOperationException();\r
- Array result = new Array(lae.size());\r
- int index = 0;\r
- for(Object o : lae) {\r
- Double ld = (Double)o;\r
- Double rd = (Double)rae.get(index++);\r
- result.addElement(ld*rd);\r
- }\r
- return result;\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)*((Double)o2);\r
+ throw new IllegalStateException("Tried to multiply a non-numerical array");\r
+ }\r
+ });\r
} else if (left instanceof Array && right instanceof Double) {\r
Array la = (Array)left;\r
- Double rd = (Double)right;\r
- List<Object> lae = la.elements();\r
- Array result = new Array(lae.size());\r
- for(Object o : lae) {\r
- Double ld = (Double)o;\r
- result.addElement(ld*rd);\r
- }\r
- return result;\r
+ final double rd = (Double)right;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return ((Double)o)*rd;\r
+ else throw new IllegalStateException("Tried to multiply a non-numerical array");\r
+ }\r
+ \r
+ });\r
+ } else if (left instanceof Double && right instanceof Array) {\r
+ Array la = (Array)right;\r
+ final double rd = (Double)left;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return ((Double)o)*rd;\r
+ else throw new IllegalStateException("Tried to multiply a non-numerical array");\r
+ }\r
+ \r
+ });\r
} else {\r
throw new UnsupportedOperationException();\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Semantum Oy.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package fi.semantum.sysdyn.solver;\r
+\r
+import java.util.Map;\r
+\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
+public class ElementwiseSubtraction implements IExpression {\r
+ \r
+ public IExpression exp1;\r
+ public IExpression exp2;\r
+ \r
+ public ElementwiseSubtraction(IExpression exp1, IExpression exp2) {\r
+ if(exp1 == null) exp1 = new Constant("0");\r
+ this.exp1 = exp1;\r
+ this.exp2 = exp2;\r
+ }\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return exp1 + " - " + exp2;\r
+ }\r
+ \r
+ @Override\r
+ public Object evaluate(IEnvironment environment) {\r
+ Object o1 = exp1.evaluate(environment);\r
+ Object o2 = exp2.evaluate(environment);\r
+ if(o1 == null || o2 == null) return null; \r
+ if(o1 instanceof Double && o2 instanceof Double) {\r
+ return (Double)o1 - (Double)o2;\r
+ }\r
+ if(o1 instanceof Array && o2 instanceof Array) {\r
+ Array la = (Array)o1;\r
+ Array ra = (Array)o2;\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)-((Double)o2);\r
+ throw new IllegalStateException("Tried to subtract a non-numerical array");\r
+ }\r
+ });\r
+ }\r
+ throw new IllegalStateException();\r
+ }\r
+ \r
+ @Override\r
+ public IExpression withBase(IFrame frame, String prefix) {\r
+ return new ElementwiseSubtraction(exp1.withBase(frame, prefix), exp2.withBase(frame, prefix));\r
+ }\r
+ \r
+ @Override\r
+ public Object getPossibleConstant() {\r
+ return null;\r
+ }\r
+ \r
+ @Override\r
+ public IExpression rewrite(IFrame frame, Map<String, VariableBase> copies) {\r
+ exp1 = exp1.rewrite(frame, copies);\r
+ exp2 = exp2.rewrite(frame, copies);\r
+ return this;\r
+ }\r
+ \r
+ @Override\r
+ public void accept(ExpressionVisitor visitor) {\r
+ visitor.visit(this);\r
+ exp1.accept(visitor);\r
+ exp2.accept(visitor);\r
+ }\r
+ \r
+}\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
import gnu.trove.list.array.TIntArrayList;\r
import gnu.trove.map.hash.TObjectIntHashMap;\r
\r
public Object evaluateInput(IEnvironment environment, int argPosition);\r
public void setLocals(IEnvironment environment);\r
public int offset();\r
- public Variable[] parameters();\r
+ public Variable[] parameters(int args);\r
}\r
\r
abstract class Fn1 implements Fn {\r
Variable[] parameters;\r
\r
public Fn1(int pCount) {\r
- parameters = new Variable[pCount];\r
- for(int i=0;i<pCount;i++)\r
- parameters[i] = new Variable(new VariableBase("", i));\r
+ if(pCount > 0) {\r
+ parameters = new Variable[pCount];\r
+ for(int i=0;i<pCount;i++)\r
+ parameters[i] = new Variable(new VariableBase("", i));\r
+ }\r
}\r
\r
public int offset() {\r
return 0;\r
}\r
\r
- public Variable[] parameters() {\r
- return parameters;\r
+ public Variable[] parameters(int argc) {\r
+ if(parameters != null) return parameters;\r
+ else {\r
+ Variable[] ret = new Variable[argc];\r
+ for(int i=0;i<argc;i++)\r
+ ret[i] = new Variable(new VariableBase("", i));\r
+ return ret;\r
+ }\r
}\r
\r
@Override\r
@Override\r
public Object evaluate(IEnvironment environment, int argc) {\r
Object value = environment.getValue(0);\r
- Double result = (Double)value;\r
- double res = result.intValue(); \r
- return res;\r
+ if(value instanceof Double) {\r
+ double d = ((Double)value).intValue(); \r
+ return d;\r
+ } else if(value instanceof Array) {\r
+ return ((Array)value).copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ double d = ((Double)o).intValue(); \r
+ return d;\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
}\r
\r
});\r
- model.functions.put("sum", new Fn1(1) {\r
+ model.functions.put("ceil", new Fn1(1) {\r
\r
@Override\r
public Object evaluate(IEnvironment environment, int argc) {\r
Object value = environment.getValue(0);\r
- Array arr = (Array)value;\r
+ if(value instanceof Double) {\r
+ return Math.ceil((Double)value);\r
+ } else if(value instanceof Array) {\r
+ return ((Array)value).copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ return Math.ceil((Double)o);\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ model.functions.put("floor", new Fn1(1) {\r
+\r
+ @Override\r
+ public Object evaluate(IEnvironment environment, int argc) {\r
+ Object value = environment.getValue(0);\r
+ if(value instanceof Double) {\r
+ return Math.floor((Double)value);\r
+ } else if(value instanceof Array) {\r
+ return ((Array)value).copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ return Math.floor((Double)o);\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ model.functions.put("sum", new Fn1(1) {\r
+\r
+ public double sum(Array a) {\r
double res = 0;\r
- for(Object o : arr.elements())\r
- res += (Double)o;\r
+ for(Object element : a.elements()) {\r
+ if(element instanceof Array) {\r
+ res += sum((Array)element);\r
+ } else if(element instanceof Double) {\r
+ res += (Double)element;\r
+ } else {\r
+ throw new IllegalStateException("Tried to sum a non-numerical array");\r
+ }\r
+ }\r
return res;\r
}\r
\r
+ @Override\r
+ public Object evaluate(IEnvironment environment, int argc) {\r
+ Object value = environment.getValue(0);\r
+ if(value instanceof Double) return (Double)value;\r
+ Array arr = (Array)value;\r
+ return sum(arr);\r
+ }\r
+ \r
+ });\r
+ model.functions.put("ones", new Fn1(-1) {\r
+\r
+ private Array make(int[] dims, int pos) {\r
+ Array result = new Array();\r
+ int d = dims[pos];\r
+ if(pos == dims.length - 1) {\r
+ for(int i=0;i<d;i++) result.addElement(1.0);\r
+ } else {\r
+ for(int i=0;i<d;i++) result.addElement(make(dims, pos+1));\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ @Override\r
+ public Object evaluate(IEnvironment environment, int argc) {\r
+ int[] dims = new int[argc];\r
+ for(int i=0;i<argc;i++) {\r
+ Double d = (Double)environment.getValue(i);\r
+ dims[i] = d.intValue();\r
+ }\r
+ return make(dims, 0);\r
+ }\r
+ \r
+ });\r
+ model.functions.put("zeros", new Fn1(-1) {\r
+\r
+ private Array make(int[] dims, int pos) {\r
+ Array result = new Array();\r
+ int d = dims[pos];\r
+ if(pos == dims.length - 1) {\r
+ for(int i=0;i<d;i++) result.addElement(0.0);\r
+ } else {\r
+ for(int i=0;i<d;i++) result.addElement(make(dims, pos+1));\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ @Override\r
+ public Object evaluate(IEnvironment environment, int argc) {\r
+ int[] dims = new int[argc];\r
+ for(int i=0;i<argc;i++) {\r
+ Double d = (Double)environment.getValue(i);\r
+ dims[i] = d.intValue();\r
+ }\r
+ return make(dims, 0);\r
+ }\r
+ \r
+ });\r
+ model.functions.put("transpose", new Fn1(1) {\r
+\r
+ @Override\r
+ public Object evaluate(IEnvironment environment, int argc) {\r
+ \r
+ Array array = (Array)environment.getValue(0);\r
+ return array.transposed();\r
+ \r
+ }\r
+ \r
});\r
model.functions.put("delay", new Fn1(4) {\r
\r
--- /dev/null
+package fi.semantum.sysdyn.solver;\r
+\r
+public class ExecutionException extends RuntimeException {\r
+\r
+ private static final long serialVersionUID = 8394963990462508948L;\r
+ \r
+ public int line = -1;\r
+ \r
+ public ExecutionException(String message) {\r
+ super(message);\r
+ }\r
+\r
+ public ExecutionException(String message, int line) {\r
+ super(message);\r
+ this.line = line;\r
+ }\r
+\r
+}\r
return "for " + indices + " loop "+ statement + " end for";\r
}\r
\r
- private void loop(IEnvironment environment, int i) {\r
+ private ReturnValue loop(IEnvironment environment, int i) {\r
if(i == indices.size()) {\r
- statement.evaluate(environment);\r
- return;\r
+ ReturnValue ret = statement.evaluate(environment);\r
+ if(ReturnValue.BREAK.equals(ret)) return ReturnValue.CONTINUE;\r
+ else if(ReturnValue.RETURN.equals(ret)) return ReturnValue.RETURN;\r
+ else return ReturnValue.CONTINUE;\r
} else {\r
ForIndex index = indices.get(i);\r
Array array = (Array)index.expression.evaluate(environment);\r
for(Object element : array.elements()) {\r
environment.put(index.base.index, element);\r
- loop(environment, i+1);\r
+ ReturnValue ret = loop(environment, i+1);\r
+ if(ReturnValue.BREAK.equals(ret)) return ReturnValue.CONTINUE;\r
+ else if(ReturnValue.RETURN.equals(ret)) return ReturnValue.RETURN;\r
}\r
+ return ReturnValue.CONTINUE;\r
}\r
}\r
\r
@Override\r
- public void evaluate(IEnvironment environment) {\r
- loop(environment, 0);\r
+ public ReturnValue evaluate(IEnvironment environment) {\r
+ return loop(environment, 0);\r
}\r
\r
}\r
public Variable[] parameters;\r
\r
public ArrayList<ForIndex> indices = new ArrayList<ForIndex>();\r
+ \r
+ public int line;\r
\r
- public Function(String name, IStatement statement) {\r
+ public Function(String name, IStatement statement, int line) {\r
this.name = name;\r
this.statement = statement;\r
+ this.line = line;\r
}\r
\r
public Object evaluate(IEnvironment environment, int argc) {\r
}\r
for(int i=0;i<internals.size();i++) {\r
VariableDeclaration decl = internals.get(i);\r
- decl.variable.assignPlain(environment, null);\r
+ if(decl.modification.args.length == 1) {\r
+ Object o = decl.modification.args[0].modification.evaluate(environment);\r
+ decl.variable.assignPlain(environment, o);\r
+ } else {\r
+ decl.variable.assignPlain(environment, null);\r
+ }\r
}\r
}\r
\r
}\r
\r
@Override\r
- public Variable[] parameters() {\r
+ public Variable[] parameters(int argc) {\r
return parameters;\r
}\r
\r
\r
@Override\r
public Object evaluate(IEnvironment environment) {\r
- return ((Double)exp1.evaluate(environment)) > ((Double)exp2.evaluate(environment));\r
+ Object left = exp1.evaluate(environment);\r
+ Object right = exp2.evaluate(environment);\r
+ return ((Double)left) > ((Double)right);\r
}\r
\r
@Override\r
\r
public interface IStatement {\r
\r
- public void evaluate(IEnvironment environment);\r
+ public enum ReturnValue {\r
+ CONTINUE,BREAK,RETURN;\r
+ }\r
+ \r
+ public ReturnValue evaluate(IEnvironment environment);\r
\r
}\r
}\r
\r
@Override\r
- public void evaluate(IEnvironment environment) {\r
+ public ReturnValue evaluate(IEnvironment environment) {\r
if((Boolean)exp.evaluate(environment)) {\r
- t.evaluate(environment);\r
+ return t.evaluate(environment);\r
} else {\r
- e.evaluate(environment);\r
+ return e.evaluate(environment);\r
}\r
}\r
\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.HashMap;\r
+import java.util.List;\r
import java.util.Map;\r
import java.util.TreeMap;\r
\r
\r
public final Globals globals;\r
\r
+ public int line = -1;\r
public String name;\r
public boolean isEnumClass;\r
\r
return base;\r
}\r
\r
+ private void reportException(Fn fn, ExecutionException e) throws ExecutionException {\r
+ \r
+ if(fn instanceof Function) {\r
+ throw new ExecutionException("function " + name + ": " + (e.line - ((Function)fn).line) + ": " + e.getMessage());\r
+ } else {\r
+ throw new ExecutionException("function " + name + ": " + (e.line - ((Function)fn).line) + ": " + e.getMessage());\r
+ }\r
+ \r
+ }\r
+ \r
public Object evaluateFunction(IEnvironment environment, String name, ArgumentList args) {\r
Fn fn = getFunction(name);\r
if(fn == null) {\r
argh.add(args.args[i].modification.evaluate(environment));\r
}\r
\r
- Variable[] parameters = fn.parameters();\r
+ Variable[] parameters = fn.parameters(argh.size());\r
\r
for(int i=0;i<args.args.length+1;i++) {\r
Variable var = parameters[i];\r
\r
fn.setLocals(frame);\r
\r
- return fn.evaluate(frame, args.args.length+1);\r
+ try {\r
+ \r
+ return fn.evaluate(frame, args.args.length+1);\r
+ \r
+ } catch (ExecutionException e) {\r
+ \r
+ reportException(fn, e);\r
+ \r
+ }\r
\r
} else {\r
\r
argh.add(arg);\r
}\r
\r
- Variable[] parameters = fn.parameters();\r
+ Variable[] parameters = fn.parameters(args.args.length);\r
+ Object[] ps = new Object[parameters.length];\r
+ boolean vector[] = new boolean[parameters.length];\r
\r
+ int vectorDimension = 0;\r
+ ArrayList<Array> arrs = new ArrayList<Array>();\r
for(int i=0;i<parameters.length;i++) {\r
Variable var = parameters[i];\r
if(i < argh.size()) {\r
- Object value = argh.get(i);\r
- var.assignPlain(frame, value);\r
+ ps[i] = argh.get(i);\r
} else {\r
- Object value = fn.evaluateInput(environment, i);\r
- var.assignPlain(frame, value);\r
+ ps[i] = fn.evaluateInput(environment, i);\r
+ }\r
+ if(var.base.dimensions == null && ps[i] instanceof Array) {\r
+ int dim = ((Array)ps[i]).dimension();\r
+ if(vectorDimension > 0 && dim != vectorDimension) throw new IllegalStateException("Array dimensions do not agree");\r
+ vectorDimension = dim;\r
+ vector[i] = true;\r
+ arrs.add((Array)ps[i]);\r
+ } else {\r
+ vector[i] = false;\r
}\r
}\r
\r
- fn.setLocals(frame);\r
- return fn.evaluate(frame, args.args.length);\r
+ if(vectorDimension > 0) {\r
+ \r
+ return arrayEvaluate(frame, fn, parameters, ps, vector, arrs);\r
+ \r
+ } else {\r
+ \r
+ for(int i=0;i<parameters.length;i++) {\r
+ parameters[i].assignPlain(frame, ps[i]);\r
+ }\r
+ \r
+ fn.setLocals(frame);\r
+ \r
+ try {\r
+\r
+ return fn.evaluate(frame, args.args.length); \r
+\r
+ } catch (ExecutionException e) {\r
+\r
+ reportException(fn, e);\r
+\r
+ }\r
+ \r
+ }\r
\r
}\r
\r
+ // This cannot happen - reportException always throws\r
+ throw new IllegalStateException();\r
+ \r
+ }\r
+ \r
+ private Array arrayEvaluate(Frame frame, Fn fn, Variable[] parameters, Object[] ps, boolean[] vector, List<Array> arrs) {\r
+ \r
+ Array result = new Array();\r
+\r
+ Array first = arrs.get(0);\r
+ \r
+ int d = first.elements().size();\r
+ if(d == 0) return result;\r
+\r
+ Object firstElement = first.element(0);\r
+ boolean subArray = firstElement instanceof Array;\r
+ \r
+ for(int i=0;i<d;i++) {\r
+\r
+ int vectorIndex = 0;\r
+\r
+ if(subArray) {\r
+\r
+ ArrayList<Array> subArrs = new ArrayList<Array>();\r
+ for(int j=0;j<parameters.length;j++) {\r
+ if(vector[j]) {\r
+ Array a = arrs.get(vectorIndex++);\r
+ Array sub = (Array)a.element(i);\r
+ subArrs.add(sub);\r
+ }\r
+ }\r
+ \r
+ result.addElement(arrayEvaluate(frame, fn, parameters, ps, vector, subArrs));\r
+\r
+ } else {\r
+\r
+ for(int j=0;j<parameters.length;j++) {\r
+ if(vector[j]) {\r
+ Array a = arrs.get(vectorIndex++);\r
+ Object sub = a.element(i);\r
+ parameters[j].assignPlain(frame, sub);\r
+ } else {\r
+ parameters[j].assignPlain(frame, ps[j]);\r
+ }\r
+ }\r
+\r
+ fn.setLocals(frame);\r
+ Object ret = fn.evaluate(frame, parameters.length);\r
+ result.addElement(ret);\r
+ \r
+ }\r
+ \r
+ } \r
+ \r
+ return result;\r
+\r
}\r
\r
private VariableBase resolveCopy(Map<String,VariableBase> work, VariableBase target) {\r
}\r
\r
@Override\r
- public void evaluate(IEnvironment environment) {\r
+ public ReturnValue evaluate(IEnvironment environment) {\r
@SuppressWarnings("unchecked")\r
ArrayList<Object> values = (ArrayList<Object>)environment.getSystem().evaluateFunction(environment, fn.base.name, args);\r
for(int i=0;i<targets.size();i++) {\r
targets.get(i).assignPlain(environment, values.get(i));\r
}\r
+ return ReturnValue.CONTINUE;\r
}\r
\r
}\r
else if(left instanceof Array && right instanceof Array) {\r
Array la = (Array)left;\r
Array ra = (Array)right;\r
- return la.mul(ra);\r
+ if(la.isVector && ra.isVector) {\r
+ return la.inner(ra);\r
+ } else if(ra.isVector) {\r
+ return la.matrixMulVector(ra);\r
+ } else {\r
+ return la.matrixMulMatrix(ra);\r
+ }\r
}\r
else if (left instanceof Array && right instanceof Double) return ((Array)left).mul((Double)right);\r
else if (left instanceof Double && right instanceof Array) return ((Array)right).mul((Double)left);\r
\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+\r
public class Negation implements IExpression {\r
\r
public IExpression exp;\r
\r
@Override\r
public Object evaluate(IEnvironment environment) {\r
- Double d = (Double)exp.evaluate(environment);\r
- if(d == null) return null;\r
- return -d;\r
+ Object value = exp.evaluate(environment);\r
+ if(value == null) return null;\r
+ if(value instanceof Double) {\r
+ return -((Double)value); \r
+ } else if(value instanceof Array) {\r
+ return ((Array)value).copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ return -((Double)o); \r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
}\r
\r
@Override\r
IExpression exp = (IExpression)walk((SimpleNode)n.jjtGetChild(1), indent+2, frame);\r
if(v instanceof Derivative) {\r
Derivative der = (Derivative)v;\r
- Assignment eq = new Assignment(der.variable, der.variable.subscripts, new Derivate(der.variable, der.variable.subscripts, exp));\r
+ Assignment eq = new Assignment(model, der.variable, der.variable.subscripts, new Derivate(der.variable, der.variable.subscripts, exp));\r
model.derivatives.add(eq);\r
return eq;\r
} else {\r
Variable var = (Variable)v;\r
- Assignment eq = new Assignment(var, var.subscripts, exp);\r
+ Assignment eq = new Assignment(model, var, var.subscripts, exp);\r
if(model.initial)\r
model.initials.add(eq);\r
else\r
// | when_statement() )\r
// comment() \r
\r
- if(n.jjtGetNumChildren() == 1) {\r
+ if(n.jjtGetNumChildren() == 0) {\r
+ if("break".equals(n.op)) {\r
+ return new Break();\r
+ } else if ("return".equals(n.op)) {\r
+ return new Return();\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ } else if(n.jjtGetNumChildren() == 1) {\r
return (IStatement)walk((SimpleNode)n.jjtGetChild(0), indent+2, frame);\r
} else if (n.jjtGetNumChildren() == 2) {\r
SimpleNode n0 = (SimpleNode)n.jjtGetChild(1);\r
return subs;\r
case declaration:\r
if(n.jjtGetNumChildren() == 0) {\r
- return new Declaration(new Variable(frame, n.op, null), null);\r
+ return new Declaration(new Variable(frame, n.op, null, n.line), null);\r
} else if(n.jjtGetNumChildren() == 1) {\r
Object o = walk((SimpleNode)n.jjtGetChild(0), indent+2, frame);\r
if(o instanceof IExpression[]) {\r
- return new Declaration(new Variable(frame, n.op, (IExpression[])o), null);\r
+ return new Declaration(new Variable(frame, n.op, (IExpression[])o, n.line), null);\r
} else {\r
- return new Declaration(new Variable(frame, n.op, null), o);\r
+ return new Declaration(new Variable(frame, n.op, null, n.line), o);\r
}\r
} else if(n.jjtGetNumChildren() == 2) {\r
IExpression[] subscripts2 = (IExpression[])walk((SimpleNode)n.jjtGetChild(0), indent+2, frame);\r
Object modification = walk((SimpleNode)n.jjtGetChild(1), indent+2, frame);\r
- return new Declaration(new Variable(frame, n.op,subscripts2), modification);\r
+ return new Declaration(new Variable(frame, n.op,subscripts2, n.line), modification);\r
} else {\r
StringBuilder b = new StringBuilder();\r
b.append("declaration: ");\r
SimpleNode child = (SimpleNode)n.jjtGetChild(0);\r
String packagePath = getPackagePath(child);\r
String functionName = packagePath + child.op;\r
+ System.err.println("function " + functionName + " at line " + child.line);\r
ArrayList<IStatement> stms2 = new ArrayList<IStatement>();\r
- Function function = new Function(functionName, new StatementList(stms2));\r
+ Function function = new Function(functionName, new StatementList(stms2), child.line);\r
ArrayList<Object> composition = (ArrayList<Object>)walk(child, indent+2, function);\r
for(int i=1;i<composition.size();i++) {\r
Object comp = composition.get(i);\r
ArrayList<Object> os = (ArrayList<Object>)os_;\r
for(Object o : os) {\r
VariableDeclaration decl = (VariableDeclaration)o;\r
- function.internals.add(decl);\r
+ if("input".equals(decl.direction)) function.inputs.add(decl);\r
+ else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
+ else function.internals.add(decl);\r
}\r
}\r
}\r
}\r
}\r
- ArrayList<Object> declarations = (ArrayList<Object>)composition.get(0);\r
- for(Object os_ : declarations) {\r
- if(os_ instanceof VariableDeclaration) {\r
- VariableDeclaration decl = (VariableDeclaration)os_;\r
- if("input".equals(decl.direction)) function.inputs.add(decl);\r
- else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
- else throw new IllegalStateException();\r
- } else {\r
- ArrayList<Object> os = (ArrayList<Object>)os_;\r
- for(Object o : os) {\r
- VariableDeclaration decl = (VariableDeclaration)o;\r
+ if(!composition.isEmpty()) {\r
+ ArrayList<Object> declarations = (ArrayList<Object>)composition.get(0);\r
+ for(Object os_ : declarations) {\r
+ if(os_ instanceof VariableDeclaration) {\r
+ VariableDeclaration decl = (VariableDeclaration)os_;\r
if("input".equals(decl.direction)) function.inputs.add(decl);\r
else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
- else throw new IllegalStateException();\r
+ else function.internals.add(decl);\r
+ } else {\r
+ ArrayList<Object> os = (ArrayList<Object>)os_;\r
+ for(Object o : os) {\r
+ VariableDeclaration decl = (VariableDeclaration)o;\r
+ if("input".equals(decl.direction)) function.inputs.add(decl);\r
+ else if ("output".equals(decl.direction)) function.outputs.add(decl);\r
+ else function.internals.add(decl);\r
+ }\r
}\r
}\r
}\r
+ \r
model.functions.put(functionName, function);\r
return function;\r
\r
} else if("model".equals(n.op)) {\r
\r
+ model.line = n.line;\r
+ \r
if(n.jjtGetNumChildren() == 1) {\r
return walk((SimpleNode)n.jjtGetChild(0), indent+2, frame);\r
} else {\r
walk(specifier, indent+2, clazz);\r
\r
if(clazz.isEnumClass) {\r
- Variable sizeVariable = new Variable(clazz, "size", null);\r
- Variable elementsVariable = new Variable(clazz, "elements", new IExpression[] { new Constant(""+clazz.variables.size()) });\r
+ Variable sizeVariable = new Variable(clazz, "size", null, n.line);\r
+ Variable elementsVariable = new Variable(clazz, "elements", new IExpression[] { new Constant(""+clazz.variables.size()) }, n.line);\r
clazz.parameters.add(new ParameterDeclaration(sizeVariable, sizeVariable.getPossibleConstant()));\r
clazz.parameters.add(new ParameterDeclaration(elementsVariable, elementsVariable.getPossibleConstant()));\r
}\r
}\r
case component_reference:\r
if(n.jjtGetNumChildren() == 1) {\r
- return Variable.make(frame, n.op, (IExpression[])walk((SimpleNode)n.jjtGetChild(0), indent+2, frame));\r
+ return Variable.make(frame, n.op, (IExpression[])walk((SimpleNode)n.jjtGetChild(0), indent+2, frame), n.line);\r
} else {\r
if ("time".equals(n.op)) {\r
return new TimeVariable();\r
}\r
- return Variable.make(frame, n.op, null);\r
+ return Variable.make(frame, n.op, null, n.line);\r
}\r
case relation:\r
if(n.jjtGetNumChildren() == 3) {\r
String op = ((String)walk((SimpleNode)n.jjtGetChild(i), indent+2, model)).trim();\r
IExpression exp2 = (IExpression)walk((SimpleNode)n.jjtGetChild(i+1), indent+2, frame);\r
if("+".equals(op)) left = new Addition(left, exp2);\r
+ else if(".+".equals(op)) left = new ElementwiseAddition(left, exp2);\r
else if("-".equals(op)) left = new Subtraction(left, exp2);\r
+ else if(".-".equals(op)) left = new ElementwiseSubtraction(left, exp2);\r
}\r
\r
return left;\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Semantum Oy.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package fi.semantum.sysdyn.solver;\r
+\r
+\r
+public class Return implements IStatement {\r
+ \r
+ public Return() {\r
+ }\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return "return";\r
+ }\r
+ \r
+ @Override\r
+ public ReturnValue evaluate(IEnvironment environment) {\r
+ return ReturnValue.RETURN;\r
+ }\r
+ \r
+}\r
\r
public class Solver {\r
\r
+ private static final boolean VALIDATE = true; \r
private static final boolean PRINT_EXCEPTIONS = false; \r
private static final int STACK_SIZE = 1000;\r
+ private static final int MAX_LOOPS = 50;\r
\r
private Model model;\r
private Environment env;\r
\r
private Object[] newValues;\r
- private Object[] derivatives;\r
\r
private double defaultStep;\r
private double start;\r
- private NodeCache cache;\r
private boolean ready;\r
\r
private boolean dirty;\r
defaultStep = 0.1;\r
start = 0;\r
// is it okay to store the cache with the solver instance?\r
- cache = new NodeCache();\r
ready = false;\r
}\r
\r
private SimpleNode n;\r
private String codeCache = null;\r
\r
+ private void validate(Variable var, Object value) {\r
+ if(VALIDATE) {\r
+ if(value instanceof Double) {\r
+ if(Double.isNaN((Double)value)) {\r
+ System.err.println("value is invalid (NaN): " + var.base.name);\r
+ throw new IllegalStateException("value is invalid (NaN)");\r
+ }\r
+ if(Double.isInfinite((Double)value)) {\r
+ System.err.println("value is invalid (Infinite): " + var.base.name);\r
+ throw new IllegalStateException("value is invalid (Infinite)");\r
+ }\r
+ }\r
+ if(value instanceof Array) {\r
+ for(Object o : ((Array)value).elements()) validate(var, o);\r
+ }\r
+ }\r
+ }\r
+ \r
public void prepare(String input) throws Exception {\r
\r
long startNanos = System.nanoTime();\r
model.parameterArray = model.parameters.toArray(new ParameterDeclaration[model.parameters.size()]);\r
\r
newValues = new Object[Math.max(model.assignments.size(),model.derivatives.size())];\r
- derivatives = new Object[model.derivatives.size()];\r
\r
int condition = 1;\r
int loops = 0;\r
\r
- while(condition > 0 && loops++ < 50) {\r
+ StringBuilder errors = null;\r
+ \r
+ while(condition > 0 && loops++ < MAX_LOOPS) {\r
\r
+ if(loops == MAX_LOOPS) errors = new StringBuilder();\r
+ \r
if(PRINT_EXCEPTIONS) {\r
System.err.println("== LOOP " + loops + " ==");\r
}\r
for(ParameterDeclaration pd : model.parameters) {\r
try {\r
if(!pd.assigned) {\r
- pd.variable.assign(env, null, pd.modification.evaluate(env));\r
+ Object value = pd.modification.evaluate(env);\r
+ validate(pd.variable, value);\r
+ pd.variable.assign(env, null, value);\r
pd.assigned = true;\r
}\r
} catch (Exception e) {\r
+ String error = " -" + pd.variable.toString() + ": " + e.getMessage();\r
+ if(errors != null) {\r
+ errors.append(error);\r
+ errors.append("\n");\r
+ }\r
condition++;\r
if(PRINT_EXCEPTIONS) {\r
e.printStackTrace();\r
- System.err.println("failed to assign " + pd.variable.toString());\r
+ System.err.println(error);\r
}\r
}\r
}\r
if(arg.name.endsWith("start")) {\r
Object value = arg.modification.evaluate(env);\r
if(vd.variable.base.dimension() == 1) {\r
+ validate(vd.variable, value);\r
vd.variable.assign(env, null, value);\r
} else {\r
+ validate(vd.variable, value);\r
if(value instanceof Double) {\r
Array array = new Array();\r
for(int i=0;i<vd.variable.base.dimension();i++) array.addElement(value);\r
vd.variable.assign(env, null, array);\r
+ } else if (value instanceof Array) {\r
+ vd.variable.assign(env, null, value);\r
} else {\r
throw new IllegalStateException();\r
}\r
}\r
}\r
} catch (Exception e) {\r
+ String error = " -" + vd.variable.toString() + ": " + e.getMessage();\r
+ if(errors != null) {\r
+ errors.append(error);\r
+ errors.append("\n");\r
+ }\r
condition++;\r
if(PRINT_EXCEPTIONS) {\r
e.printStackTrace();\r
- System.err.println("failed to assign " + vd.variable.toString());\r
+ System.err.println(error);\r
}\r
}\r
}\r
\r
for(Assignment ass : assignments) {\r
try {\r
- if(!ass.assigned) {\r
- Object value = ass.expression.evaluate(env);\r
- if(value != null) {\r
- ass.target.assign(env, ass.subscripts, value);\r
- ass.assigned = true;\r
- }\r
- }\r
+ if(!ass.assigned)\r
+ ass.assign(env);\r
} catch (Exception e) {\r
+ String error = " -" + ass.target.toString() + ": " + e.getMessage();\r
+ if(errors != null) {\r
+ errors.append(error);\r
+ errors.append("\n");\r
+ }\r
condition++;\r
if(PRINT_EXCEPTIONS) {\r
e.printStackTrace();\r
- System.err.println("failed to assign " + ass.target.toString());\r
+ System.err.println(error);\r
}\r
}\r
}\r
}\r
\r
+ if(loops == (MAX_LOOPS+1))\r
+ throw new IllegalStateException("Did not find initial state for model:\n" + errors.toString());\r
+ \r
for(Assignment ass : model.assignments) {\r
if(ass.expression instanceof Constant)\r
ass.isConstant = true;\r
\r
if(!started && dirty) {\r
\r
- // Solve all algebraic equations\r
- Assignment[] assignments = model.assignmentArray;\r
- for(int i=0;i<assignments.length;i++) {\r
- if(assignments[i].isConstant) continue;\r
- Object value = assignments[i].expression.evaluate(env);\r
- assignments[i].target.assign(env, assignments[i].subscripts, value);\r
- }\r
- for(Assignment ass : model.initials) {\r
- if(ass.isConstant) continue;\r
- Object value = ass.expression.evaluate(env);\r
- ass.target.assign(env, ass.subscripts, value);\r
- }\r
-\r
- // Solve initial values\r
- for(VariableDeclaration vd : model.variables) {\r
- try {\r
- for(Argument arg : vd.modification.args) {\r
- if(arg.name.endsWith("start")) {\r
- Object value = arg.modification.evaluate(env);\r
- if(vd.variable.base.dimension() == 1) {\r
- vd.variable.assign(env, null, value);\r
- } else {\r
- if(value instanceof Double) {\r
- Array array = new Array();\r
- for(int i=0;i<vd.variable.base.dimension();i++) array.addElement(value);\r
- vd.variable.assign(env, null, array);\r
+ for(int loop=0;loop<3;loop++) {\r
+ \r
+ // Solve all algebraic equations\r
+ Assignment[] assignments = model.assignmentArray;\r
+ for(int i=0;i<assignments.length;i++) {\r
+ if(assignments[i].isConstant) continue;\r
+ assignments[i].assign(env);\r
+// Object value = assignments[i].expression.evaluate(env);\r
+// assignments[i].target.assign(env, assignments[i].subscripts, value);\r
+ }\r
+ for(Assignment ass : model.initials) {\r
+ if(ass.isConstant) continue;\r
+ ass.assign(env);\r
+// Object value = ass.expression.evaluate(env);\r
+// ass.target.assign(env, ass.subscripts, value);\r
+ }\r
+ \r
+ for(VariableDeclaration vd : model.variables) {\r
+ try {\r
+ for(Argument arg : vd.modification.args) {\r
+ if(arg.name.endsWith("start")) {\r
+ Object value = arg.modification.evaluate(env);\r
+ if(vd.variable.base.dimension() == 1) {\r
+ validate(vd.variable, value);\r
+ vd.variable.assign(env, null, value);\r
} else {\r
- throw new IllegalStateException();\r
+ validate(vd.variable, value);\r
+ if(value instanceof Double) {\r
+ Array array = new Array();\r
+ for(int i=0;i<vd.variable.base.dimension();i++) array.addElement(value);\r
+ vd.variable.assign(env, null, array);\r
+ } else if (value instanceof Array) {\r
+ vd.variable.assign(env, null, value);\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
}\r
}\r
}\r
- }\r
- } catch (Exception e) {\r
- if(PRINT_EXCEPTIONS) {\r
- e.printStackTrace();\r
- System.err.println("failed to assign " + vd.variable.toString());\r
+ } catch (Exception e) {\r
+ if(PRINT_EXCEPTIONS) {\r
+ e.printStackTrace();\r
+ System.err.println("failed to assign " + vd.variable.toString());\r
+ }\r
}\r
}\r
+ \r
}\r
\r
dirty = false;\r
// Next solve algebraic equations\r
for(int i=0;i<assignments.length;i++) {\r
if(assignments[i].isConstant) continue;\r
- Object value = assignments[i].expression.evaluate(env);\r
- assignments[i].target.assign(env, assignments[i].subscripts, value);\r
+ assignments[i].assign(env);\r
+// Object value = assignments[i].expression.evaluate(env);\r
+// assignments[i].target.assign(env, assignments[i].subscripts, value);\r
}\r
\r
}\r
}\r
\r
public double getTime() {\r
- return env.time;\r
+ if (env != null) {\r
+ return env.time;\r
+ } else {\r
+ return 0.0;\r
+ }\r
}\r
\r
public void setValue(String key, double value) {\r
}\r
\r
@Override\r
- public void evaluate(IEnvironment environment) {\r
+ public ReturnValue evaluate(IEnvironment environment) {\r
Object value = expression.evaluate(environment);\r
target.assign(environment, subscripts, value);\r
+ return ReturnValue.CONTINUE;\r
}\r
\r
}\r
}\r
\r
@Override\r
- public void evaluate(IEnvironment environment) {\r
- for(IStatement stm : statements) stm.evaluate(environment);\r
+ public ReturnValue evaluate(IEnvironment environment) {\r
+ for(IStatement stm : statements) {\r
+ ReturnValue ret = stm.evaluate(environment);\r
+ if(ReturnValue.RETURN.equals(ret)) return ReturnValue.RETURN;\r
+ }\r
+ return ReturnValue.CONTINUE;\r
}\r
\r
}\r
\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class Subtraction implements IExpression {\r
\r
public IExpression exp1;\r
\r
@Override\r
public Object evaluate(IEnvironment environment) {\r
- Double d1 = (Double)exp1.evaluate(environment);\r
- Double d2 = (Double)exp2.evaluate(environment);\r
- if(d1 == null || d2 == null) return null;\r
- return d1-d2;\r
+ Object o1 = exp1.evaluate(environment);\r
+ Object o2 = exp2.evaluate(environment);\r
+ if(o1 == null || o2 == null) return null; \r
+ if(o1 instanceof Double && o2 instanceof Double) {\r
+ return (Double)o1 - (Double)o2;\r
+ }\r
+ if(o1 instanceof Array && o2 instanceof Array) {\r
+ Array la = (Array)o1;\r
+ Array ra = (Array)o2;\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)-((Double)o2);\r
+ throw new IllegalStateException("Tried to subtract a non-numerical array");\r
+ }\r
+ });\r
+ }\r
+ throw new IllegalStateException();\r
}\r
\r
@Override\r
return ((Double)value).intValue()-1;\r
} else if (value instanceof Constant) {\r
return getIndex(((Constant)value).value);\r
+ } else if (value instanceof Array) {\r
+ return -3;\r
} else {\r
throw new IllegalStateException();\r
}\r
\r
public VariableBase base;\r
public IExpression[] subscripts = null;\r
+ public int line = -1;\r
\r
- public Variable(IFrame frame, String name, IExpression[] subscripts) {\r
+ public Variable(IFrame frame, String name, IExpression[] subscripts, int line) {\r
base = frame.getBase(name);\r
this.subscripts = subscripts;\r
+ this.line = line;\r
}\r
\r
- public static Object make(IFrame frame, String name, IExpression[] subscripts) {\r
+ public static Object make(IFrame frame, String name, IExpression[] subscripts, int line) {\r
// Array enumElements = enumerationElements(frame, name);\r
// if(enumElements != null) return enumElements;\r
// Constant enumSize = enumerationSize(frame, name);\r
// if(enumSize != null) return enumSize;\r
- return new Variable(frame, name, subscripts);\r
+ return new Variable(frame, name, subscripts, line);\r
}\r
\r
public Variable(VariableBase base) {\r
env.put(base.index, value);\r
}\r
\r
+ private int subscriptLength() {\r
+ if(this.subscripts == null) return 1;\r
+ return this.subscripts.length;\r
+ }\r
+ \r
private void validateSize(IEnvironment env, IExpression[] subscripts, Object value) {\r
\r
if(value == null) return;\r
\r
- if(base.isStoredAsArray()) return;\r
+ if(base.isStoredAsArray(env)) return;\r
\r
int fullDimension = base.dimension();\r
if(fullDimension == 1) {\r
if(!(value instanceof Double)) {\r
Array arr = (Array)value;\r
- if(arr.size(0) != 1)\r
- throw new IllegalStateException();\r
+ int arrSize = arr.dimension(); \r
+ if(arrSize != 1)\r
+ throw new ExecutionException("Trying to assign an array into a scalar variable");\r
}\r
} else {\r
if(subscripts == null) {\r
- if(base.dimensions.length == this.subscripts.length && value instanceof Double) \r
+ if(base.dimensions.length == subscriptLength() && value instanceof Double) \r
return;\r
if(!(value instanceof Array))\r
throw new IllegalStateException();\r
validateSize(env, subscripts, value);\r
\r
if(value instanceof Array) {\r
- if(base.isStoredAsArray()) {\r
- env.put(base.index(env, subscripts), value);\r
+ if(base.isStoredAsArray(env)) {\r
+ if(SolverUtils.isFullSubscript(subscripts)) {\r
+ env.put(base.index(env, subscripts), value);\r
+ } else {\r
+ Array[] indices = SolverUtils.parseSubscripts(env, subscripts);\r
+ Array current = (Array)env.getValue(base.index);\r
+ current.applyPartial(indices, (Array)value);\r
+ env.put(base.index, current);\r
+ }\r
} else {\r
assignArray(env, base.index(env, subscripts), (Array)value, 0);\r
}\r
} else {\r
- if(base.isStoredAsArray()) {\r
+ if(base.isStoredAsArray(env)) {\r
Object _existing = env.getValue(base.index);\r
Array existing = (Array)_existing;\r
if(existing == null) {\r
@Override\r
public Object evaluate(IEnvironment environment) {\r
\r
- if(constantIndex == -2) constantIndex = base.getConstantIndex(environment, subscripts);\r
+ try {\r
\r
- return base.evaluate(environment, subscripts, constantIndex);\r
+ if(constantIndex == -2) constantIndex = base.getConstantIndex(environment, subscripts);\r
+ \r
+ return base.evaluate(environment, subscripts, constantIndex);\r
+ \r
+ } catch (ExecutionException e) {\r
+ \r
+ throw new ExecutionException(base.name + ": " + e.getMessage(), line);\r
+ \r
+ }\r
\r
}\r
\r
for(int d : dimensions) result *= d;\r
return result;\r
}\r
- public boolean isStoredAsArray() {\r
+ public boolean isStoredAsArray(IEnvironment env) {\r
if(dimensions == null) return false;\r
for(int d : dimensions) if(d == -1) return true;\r
- return false;\r
+ return (env instanceof Frame);\r
}\r
\r
VariableBase withBase(String prefix) {\r
return result;\r
}\r
\r
- private boolean hasScalarSubscript(IExpression[] subscripts) {\r
- if(subscripts == null) return false;\r
- else return true;\r
- }\r
+// private boolean hasScalarSubscript(IExpression[] subscripts) {\r
+// if(subscripts == null) return false;\r
+// else return true;\r
+// }\r
\r
public int intoArray(IEnvironment env, int index, int d, Array target) {\r
\r
\r
public int getConstantIndex(IEnvironment environment, IExpression[] subscripts) {\r
\r
- if(isStoredAsArray()) {\r
+ if(isStoredAsArray(environment)) {\r
return -1;\r
} else {\r
\r
}\r
}\r
\r
- if(isStoredAsArray()) {\r
+ if(isStoredAsArray(environment)) {\r
\r
- Array array = (Array)environment.getValue(index);\r
- if(hasScalarSubscript(subscripts)) {\r
- Object o = getArrayIndex(environment, subscripts, array);\r
- if(o instanceof Variable) throw new IllegalStateException();\r
- if(o instanceof Array)\r
- throw new IllegalStateException();\r
- return o;\r
+ Object value = environment.getValue(index);\r
+ if(value instanceof Array) {\r
+ Array array = (Array)value;\r
+ if(subscripts != null) {\r
+ return array.subscript(environment, subscripts);\r
+ }\r
}\r
- else return array;\r
+ return value;\r
\r
} else {\r
- \r
+\r
if(dimension() > 1) {\r
+\r
+ Array array = new Array();\r
+ intoArray(environment, index, 0, array);\r
if(subscripts != null) {\r
- \r
- Array[] sub = SolverUtils.parseSubscripts(environment, subscripts);\r
- if(SolverUtils.isSlice(sub)) {\r
- Array arr = new Array();\r
- intoArray(environment, index, 0, arr);\r
- return arr.slice(sub);\r
- } else { \r
- return environment.getValue(index(environment, subscripts));\r
- }\r
- \r
- } else {\r
- Array array = new Array();\r
- intoArray(environment, index, 0, array);\r
- return array;\r
+ return array.subscript(environment, subscripts);\r
}\r
+ else return array;\r
+\r
+// if(subscripts != null) {\r
+// \r
+// Array[] sub = SolverUtils.parseSubscripts(environment, subscripts);\r
+// if(SolverUtils.isSlice(sub)) {\r
+// Array arr = new Array();\r
+// intoArray(environment, index, 0, arr);\r
+// return arr.slice(sub);\r
+// } else { \r
+// return environment.getValue(index(environment, subscripts));\r
+// }\r
+// \r
+// } else {\r
+// return array;\r
+// }\r
}\r
\r
Object result = environment.getNamedValue(name);\r
}\r
\r
@Override\r
- public void evaluate(IEnvironment environment) {\r
- while ((Boolean)expression.evaluate(environment))\r
- statement.evaluate(environment);\r
+ public ReturnValue evaluate(IEnvironment environment) {\r
+ while ((Boolean)expression.evaluate(environment)) {\r
+ ReturnValue ret = statement.evaluate(environment);\r
+ if(ReturnValue.BREAK.equals(ret)) return ReturnValue.CONTINUE;\r
+ else if(ReturnValue.RETURN.equals(ret)) return ReturnValue.RETURN;\r
+ }\r
+ return ReturnValue.CONTINUE;\r
}\r
\r
}\r
/*** Class Definition **********************************************/\r
final public void class_definition() throws ParseException {\r
/*@bgen(jjtree) class_definition */\r
- SimpleNode jjtn000 = new SimpleNode(JJTCLASS_DEFINITION);\r
- boolean jjtc000 = true;\r
- jjtree.openNodeScope(jjtn000);\r
+ SimpleNode jjtn000 = new SimpleNode(JJTCLASS_DEFINITION);\r
+ boolean jjtc000 = true;\r
+ jjtree.openNodeScope(jjtn000);Token t;\r
try {\r
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
case 30:\r
jjtn000.op = "class";\r
break;\r
case 7:\r
- jj_consume_token(7);\r
- jjtn000.op = "model";\r
+ t = jj_consume_token(7);\r
+ jjtn000.op = "model"; jjtn000.line = t.beginLine;\r
break;\r
case 61:\r
jj_consume_token(61);\r
try {\r
if (jj_2_1(2)) {\r
t = jj_consume_token(IDENT);\r
- jjtn000.op = t.image;\r
+ jjtn000.op = t.image; jjtn000.line = t.beginLine;\r
string_comment();\r
composition();\r
jj_consume_token(35);\r
Parameter ret = new Parameter();\r
try {\r
jj_consume_token(IDENT);\r
- ret.name = new String(token.image); jjtn000.op = token.image;\r
+ ret.name = new String(token.image); jjtn000.op = token.image; jjtn000.line = token.beginLine;\r
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
case 66:\r
array_subscripts();\r
break;\r
case 29:\r
jj_consume_token(29);\r
+ jjtn000.op = "break";\r
break;\r
case 18:\r
jj_consume_token(18);\r
+ jjtn000.op = "return";\r
break;\r
case 31:\r
if_statement();\r
break;\r
case 80:\r
jj_consume_token(80);\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ jjtn000.op = ".+";\r
break;\r
case 81:\r
jj_consume_token(81);\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ jjtn000.op = ".-";\r
break;\r
default:\r
jj_la1[103] = jj_gen;\r
jjtree.openNodeScope(jjtn000);\r
try {\r
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
- case 82:\r
- jj_consume_token(82);\r
- jjtree.closeNodeScope(jjtn000, true);\r
- jjtc000 = false;\r
- jjtn000.op = "*";\r
- break;\r
- case 83:\r
- jj_consume_token(83);\r
- jjtree.closeNodeScope(jjtn000, true);\r
- jjtc000 = false;\r
- jjtn000.op = "/";\r
- break;\r
case 84:\r
jj_consume_token(84);\r
- jjtree.closeNodeScope(jjtn000, true);\r
- jjtc000 = false;\r
- jjtn000.op = ".*";\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ jjtn000.op = ".*";\r
break;\r
case 85:\r
jj_consume_token(85);\r
- jjtree.closeNodeScope(jjtn000, true);\r
- jjtc000 = false;\r
- jjtn000.op = "./";\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ jjtn000.op = "./";\r
+ break;\r
+ case 82:\r
+ jj_consume_token(82);\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ jjtn000.op = "*";\r
+ break;\r
+ case 83:\r
+ jj_consume_token(83);\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ jjtn000.op = "/";\r
break;\r
default:\r
jj_la1[105] = jj_gen;\r
;\r
}\r
t = jj_consume_token(IDENT);\r
- jjtn000.op = t.image;\r
+ jjtn000.op = t.image; jjtn000.line = t.beginLine;\r
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
case 66:\r
array_subscripts();\r
finally { jj_save(9, xla); }\r
}\r
\r
+ private boolean jj_3R_136() {\r
+ if (jj_scan_token(81)) return true;\r
+ return false;\r
+ }\r
+\r
private boolean jj_3R_74() {\r
if (jj_scan_token(62)) return true;\r
Token xsp;\r
xsp = jj_scanpos;\r
- if (jj_3R_167()) jj_scanpos = xsp;\r
+ if (jj_3R_169()) jj_scanpos = xsp;\r
if (jj_scan_token(63)) return true;\r
return false;\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_154() {\r
+ private boolean jj_3R_156() {\r
Token xsp;\r
xsp = jj_scanpos;\r
if (jj_scan_token(68)) jj_scanpos = xsp;\r
if (jj_scan_token(IDENT)) return true;\r
xsp = jj_scanpos;\r
- if (jj_3R_162()) jj_scanpos = xsp;\r
+ if (jj_3R_164()) jj_scanpos = xsp;\r
while (true) {\r
xsp = jj_scanpos;\r
- if (jj_3R_163()) { jj_scanpos = xsp; break; }\r
+ if (jj_3R_165()) { jj_scanpos = xsp; break; }\r
}\r
return false;\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_160() {\r
- if (jj_scan_token(58)) return true;\r
+ private boolean jj_3R_153() {\r
+ if (jj_scan_token(82)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_77() {\r
- if (jj_scan_token(68)) return true;\r
+ private boolean jj_3R_162() {\r
+ if (jj_scan_token(58)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_151() {\r
- if (jj_scan_token(84)) return true;\r
+ private boolean jj_3R_77() {\r
+ if (jj_scan_token(68)) return true;\r
return false;\r
}\r
\r
return false;\r
}\r
\r
+ private boolean jj_3R_135() {\r
+ if (jj_scan_token(80)) return true;\r
+ return false;\r
+ }\r
+\r
private boolean jj_3R_124() {\r
if (jj_scan_token(74)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_147() {\r
- if (jj_3R_156()) return true;\r
+ private boolean jj_3R_149() {\r
+ if (jj_3R_158()) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_165() {\r
+ private boolean jj_3R_167() {\r
if (jj_scan_token(70)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_146() {\r
+ private boolean jj_3R_148() {\r
if (jj_scan_token(66)) return true;\r
- if (jj_3R_155()) return true;\r
+ if (jj_3R_157()) return true;\r
if (jj_scan_token(67)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_145() {\r
+ private boolean jj_3R_147() {\r
if (jj_scan_token(62)) return true;\r
if (jj_3R_47()) return true;\r
if (jj_scan_token(63)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_143() {\r
- if (jj_3R_153()) return true;\r
+ private boolean jj_3R_145() {\r
+ if (jj_3R_155()) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_158() {\r
+ private boolean jj_3R_160() {\r
if (jj_scan_token(87)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_144() {\r
- if (jj_3R_154()) return true;\r
+ private boolean jj_3R_146() {\r
+ if (jj_3R_156()) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_135() {\r
+ private boolean jj_3R_137() {\r
Token xsp;\r
xsp = jj_scanpos;\r
- if (jj_3R_138()) {\r
- jj_scanpos = xsp;\r
- if (jj_3R_139()) {\r
- jj_scanpos = xsp;\r
if (jj_3R_140()) {\r
jj_scanpos = xsp;\r
if (jj_3R_141()) {\r
jj_scanpos = xsp;\r
if (jj_3R_147()) {\r
jj_scanpos = xsp;\r
+ if (jj_3R_148()) {\r
+ jj_scanpos = xsp;\r
+ if (jj_3R_149()) {\r
+ jj_scanpos = xsp;\r
if (jj_scan_token(35)) return true;\r
}\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_138() {\r
+ private boolean jj_3R_140() {\r
if (jj_scan_token(UNSIGNED_NUMBER)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_142() {\r
+ private boolean jj_3R_144() {\r
if (jj_scan_token(33)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_141() {\r
+ private boolean jj_3R_143() {\r
if (jj_scan_token(6)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_140() {\r
+ private boolean jj_3R_142() {\r
if (jj_scan_token(STRING)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_139() {\r
+ private boolean jj_3R_141() {\r
if (jj_scan_token(UNSIGNED_INTEGER)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_150() {\r
- if (jj_scan_token(83)) return true;\r
+ private boolean jj_3R_152() {\r
+ if (jj_scan_token(85)) return true;\r
return false;\r
}\r
\r
return false;\r
}\r
\r
- private boolean jj_3R_156() {\r
+ private boolean jj_3R_158() {\r
if (jj_scan_token(64)) return true;\r
- if (jj_3R_166()) return true;\r
+ if (jj_3R_168()) return true;\r
if (jj_scan_token(65)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_136() {\r
- if (jj_3R_148()) return true;\r
- if (jj_3R_135()) return true;\r
+ private boolean jj_3R_138() {\r
+ if (jj_3R_150()) return true;\r
+ if (jj_3R_137()) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_155() {\r
- if (jj_3R_164()) return true;\r
+ private boolean jj_3R_157() {\r
+ if (jj_3R_166()) return true;\r
Token xsp;\r
while (true) {\r
xsp = jj_scanpos;\r
- if (jj_3R_165()) { jj_scanpos = xsp; break; }\r
+ if (jj_3R_167()) { jj_scanpos = xsp; break; }\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_159() {\r
+ private boolean jj_3R_161() {\r
if (jj_3R_60()) return true;\r
return false;\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_153() {\r
+ private boolean jj_3R_155() {\r
Token xsp;\r
xsp = jj_scanpos;\r
- if (jj_3R_159()) {\r
+ if (jj_3R_161()) {\r
jj_scanpos = xsp;\r
- if (jj_3R_160()) {\r
+ if (jj_3R_162()) {\r
jj_scanpos = xsp;\r
- if (jj_3R_161()) return true;\r
+ if (jj_3R_163()) return true;\r
}\r
}\r
if (jj_3R_74()) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_148() {\r
+ private boolean jj_3R_150() {\r
Token xsp;\r
xsp = jj_scanpos;\r
- if (jj_3R_157()) {\r
+ if (jj_3R_159()) {\r
jj_scanpos = xsp;\r
- if (jj_3R_158()) return true;\r
+ if (jj_3R_160()) return true;\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_157() {\r
+ private boolean jj_3R_159() {\r
if (jj_scan_token(86)) return true;\r
return false;\r
}\r
\r
private boolean jj_3R_120() {\r
- if (jj_3R_135()) return true;\r
+ if (jj_3R_137()) return true;\r
Token xsp;\r
xsp = jj_scanpos;\r
- if (jj_3R_136()) jj_scanpos = xsp;\r
+ if (jj_3R_138()) jj_scanpos = xsp;\r
return false;\r
}\r
\r
private boolean jj_3R_121() {\r
- if (jj_3R_137()) return true;\r
+ if (jj_3R_139()) return true;\r
if (jj_3R_120()) return true;\r
return false;\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_137() {\r
+ private boolean jj_3R_139() {\r
Token xsp;\r
xsp = jj_scanpos;\r
- if (jj_3R_149()) {\r
+ if (jj_3R_151()) {\r
jj_scanpos = xsp;\r
- if (jj_3R_150()) {\r
+ if (jj_3R_152()) {\r
jj_scanpos = xsp;\r
- if (jj_3R_151()) {\r
+ if (jj_3R_153()) {\r
jj_scanpos = xsp;\r
- if (jj_3R_152()) return true;\r
+ if (jj_3R_154()) return true;\r
}\r
}\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_149() {\r
- if (jj_scan_token(82)) return true;\r
+ private boolean jj_3R_151() {\r
+ if (jj_scan_token(84)) return true;\r
return false;\r
}\r
\r
jj_scanpos = xsp;\r
if (jj_3R_134()) {\r
jj_scanpos = xsp;\r
- if (jj_scan_token(80)) {\r
+ if (jj_3R_135()) {\r
jj_scanpos = xsp;\r
- if (jj_scan_token(81)) return true;\r
+ if (jj_3R_136()) return true;\r
}\r
}\r
}\r
return false;\r
}\r
\r
+ private boolean jj_3R_107() {\r
+ Token xsp;\r
+ xsp = jj_scanpos;\r
+ if (jj_scan_token(50)) jj_scanpos = xsp;\r
+ if (jj_scan_token(44)) return true;\r
+ return false;\r
+ }\r
+\r
private boolean jj_3R_66() {\r
if (jj_3R_80()) return true;\r
return false;\r
return false;\r
}\r
\r
- private boolean jj_3R_107() {\r
- Token xsp;\r
- xsp = jj_scanpos;\r
- if (jj_scan_token(50)) jj_scanpos = xsp;\r
- if (jj_scan_token(44)) return true;\r
- return false;\r
- }\r
-\r
private boolean jj_3R_84() {\r
Token xsp;\r
xsp = jj_scanpos;\r
return false;\r
}\r
\r
+ private boolean jj_3R_165() {\r
+ if (jj_scan_token(68)) return true;\r
+ if (jj_scan_token(IDENT)) return true;\r
+ return false;\r
+ }\r
+\r
private boolean jj_3R_58() {\r
if (jj_scan_token(IDENT)) return true;\r
if (jj_3R_74()) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_174() {\r
+ private boolean jj_3R_176() {\r
if (jj_3R_47()) return true;\r
return false;\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_163() {\r
- if (jj_scan_token(68)) return true;\r
- if (jj_scan_token(IDENT)) return true;\r
+ private boolean jj_3R_164() {\r
+ if (jj_3R_170()) return true;\r
return false;\r
}\r
\r
return false;\r
}\r
\r
- private boolean jj_3R_173() {\r
+ private boolean jj_3R_175() {\r
if (jj_scan_token(69)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_169() {\r
+ private boolean jj_3R_171() {\r
if (jj_scan_token(71)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_171() {\r
+ private boolean jj_3R_173() {\r
Token xsp;\r
xsp = jj_scanpos;\r
- if (jj_3R_173()) {\r
+ if (jj_3R_175()) {\r
jj_scanpos = xsp;\r
- if (jj_3R_174()) return true;\r
+ if (jj_3R_176()) return true;\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_162() {\r
- if (jj_3R_168()) return true;\r
- return false;\r
- }\r
-\r
private boolean jj_3R_48() {\r
Token xsp;\r
xsp = jj_scanpos;\r
return false;\r
}\r
\r
- private boolean jj_3R_168() {\r
+ private boolean jj_3R_170() {\r
if (jj_scan_token(66)) return true;\r
- if (jj_3R_171()) return true;\r
+ if (jj_3R_173()) return true;\r
return false;\r
}\r
\r
return false;\r
}\r
\r
- private boolean jj_3R_164() {\r
+ private boolean jj_3R_166() {\r
if (jj_3R_47()) return true;\r
Token xsp;\r
while (true) {\r
xsp = jj_scanpos;\r
- if (jj_3R_169()) { jj_scanpos = xsp; break; }\r
+ if (jj_3R_171()) { jj_scanpos = xsp; break; }\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_175() {\r
+ private boolean jj_3R_177() {\r
if (jj_scan_token(IDENT)) return true;\r
if (jj_scan_token(88)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_161() {\r
+ private boolean jj_3R_163() {\r
if (jj_scan_token(46)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_172() {\r
- if (jj_3R_175()) return true;\r
+ private boolean jj_3R_154() {\r
+ if (jj_scan_token(83)) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_152() {\r
- if (jj_scan_token(85)) return true;\r
+ private boolean jj_3R_174() {\r
+ if (jj_3R_177()) return true;\r
return false;\r
}\r
\r
- private boolean jj_3R_170() {\r
- if (jj_3R_172()) return true;\r
+ private boolean jj_3R_172() {\r
+ if (jj_3R_174()) return true;\r
return false;\r
}\r
\r
return false;\r
}\r
\r
- private boolean jj_3R_166() {\r
+ private boolean jj_3R_168() {\r
Token xsp;\r
xsp = jj_scanpos;\r
if (jj_3_10()) {\r
jj_scanpos = xsp;\r
- if (jj_3R_170()) return true;\r
+ if (jj_3R_172()) return true;\r
}\r
return false;\r
}\r
\r
- private boolean jj_3R_167() {\r
- if (jj_3R_166()) return true;\r
+ private boolean jj_3R_169() {\r
+ if (jj_3R_168()) return true;\r
return false;\r
}\r
\r
{\r
case 0:\r
if ((active1 & 0x80000L) != 0L)\r
- return 22;\r
+ return 23;\r
if ((active1 & 0xb30010L) != 0L)\r
- return 10;\r
- if ((active0 & 0x884210842108400L) != 0L)\r
+ return 11;\r
+ if ((active0 & 0x377bdef7bdef7bf0L) != 0L || (active1 & 0x180000000L) != 0L)\r
{\r
jjmatchedKind = 90;\r
- return 48;\r
+ return 49;\r
}\r
- if ((active0 & 0x377bdef7bdef7bf0L) != 0L || (active1 & 0x180000000L) != 0L)\r
+ if ((active0 & 0x884210842108400L) != 0L)\r
{\r
jjmatchedKind = 90;\r
- return 2;\r
+ return 50;\r
}\r
return -1;\r
case 1:\r
- if ((active0 & 0x108420080400000L) != 0L)\r
- return 2;\r
if ((active0 & 0x3ef7bdff7fbffff0L) != 0L || (active1 & 0x180000000L) != 0L)\r
{\r
if (jjmatchedPos != 1)\r
jjmatchedKind = 90;\r
jjmatchedPos = 1;\r
}\r
- return 2;\r
+ return 49;\r
}\r
+ if ((active0 & 0x108420080400000L) != 0L)\r
+ return 49;\r
return -1;\r
case 2:\r
if ((active0 & 0x400000800201200L) != 0L)\r
- return 2;\r
+ return 49;\r
if ((active0 & 0x3bfffdf77f9fedf0L) != 0L || (active1 & 0x180000000L) != 0L)\r
{\r
jjmatchedKind = 90;\r
jjmatchedPos = 2;\r
- return 2;\r
+ return 49;\r
}\r
return -1;\r
case 3:\r
if ((active0 & 0x1000084212118400L) != 0L)\r
- return 2;\r
+ return 49;\r
if ((active0 & 0x2bfff5b56d8e69f0L) != 0L || (active1 & 0x180000000L) != 0L)\r
{\r
if (jjmatchedPos != 3)\r
jjmatchedKind = 90;\r
jjmatchedPos = 3;\r
}\r
- return 2;\r
+ return 49;\r
}\r
return -1;\r
case 4:\r
- if ((active0 & 0x1090004290008c0L) != 0L)\r
- return 2;\r
if ((active0 & 0x2af6f5b1469e6130L) != 0L || (active1 & 0x180000000L) != 0L)\r
{\r
jjmatchedKind = 90;\r
jjmatchedPos = 4;\r
- return 2;\r
+ return 49;\r
}\r
+ if ((active0 & 0x1090004290008c0L) != 0L)\r
+ return 49;\r
return -1;\r
case 5:\r
if ((active0 & 0x22200011009c0000L) != 0L)\r
- return 2;\r
+ return 49;\r
if ((active0 & 0x8d6f5a046026130L) != 0L || (active1 & 0x180000000L) != 0L)\r
{\r
jjmatchedKind = 90;\r
jjmatchedPos = 5;\r
- return 2;\r
+ return 49;\r
}\r
return -1;\r
case 6:\r
- if ((active0 & 0x80d0a000000000L) != 0L)\r
- return 2;\r
if ((active0 & 0x856250046026130L) != 0L || (active1 & 0x180000000L) != 0L)\r
{\r
if (jjmatchedPos != 6)\r
jjmatchedKind = 90;\r
jjmatchedPos = 6;\r
}\r
- return 2;\r
+ return 49;\r
}\r
+ if ((active0 & 0x80d0a000000000L) != 0L)\r
+ return 49;\r
return -1;\r
case 7:\r
+ if ((active0 & 0x802200006020020L) != 0L || (active1 & 0x180000000L) != 0L)\r
+ return 49;\r
if ((active0 & 0x54150040006110L) != 0L)\r
{\r
if (jjmatchedPos != 7)\r
jjmatchedKind = 90;\r
jjmatchedPos = 7;\r
}\r
- return 2;\r
+ return 49;\r
}\r
- if ((active0 & 0x802200006020020L) != 0L || (active1 & 0x180000000L) != 0L)\r
- return 2;\r
return -1;\r
case 8:\r
if ((active0 & 0x10140000000110L) != 0L)\r
- return 2;\r
+ return 49;\r
if ((active0 & 0x44010040006000L) != 0L)\r
{\r
jjmatchedKind = 90;\r
jjmatchedPos = 8;\r
- return 2;\r
+ return 49;\r
}\r
return -1;\r
case 9:\r
{\r
jjmatchedKind = 90;\r
jjmatchedPos = 9;\r
- return 2;\r
+ return 49;\r
}\r
if ((active0 & 0x4000000004000L) != 0L)\r
- return 2;\r
+ return 49;\r
return -1;\r
case 10:\r
- if ((active0 & 0x10000002000L) != 0L)\r
- return 2;\r
if ((active0 & 0x40000040000000L) != 0L)\r
{\r
jjmatchedKind = 90;\r
jjmatchedPos = 10;\r
- return 2;\r
+ return 49;\r
}\r
+ if ((active0 & 0x10000002000L) != 0L)\r
+ return 49;\r
return -1;\r
case 11:\r
if ((active0 & 0x40000000L) != 0L)\r
- return 2;\r
+ return 49;\r
if ((active0 & 0x40000000000000L) != 0L)\r
{\r
jjmatchedKind = 90;\r
jjmatchedPos = 11;\r
- return 2;\r
+ return 49;\r
}\r
return -1;\r
case 12:\r
if ((active0 & 0x40000000000000L) != 0L)\r
- return 2;\r
+ return 49;\r
return -1;\r
default :\r
return -1;\r
jjmatchedKind = 68;\r
return jjMoveStringLiteralDfa1_0(0x0L, 0xb30000L);\r
case 47:\r
- return jjStartNfaWithStates_0(0, 83, 22);\r
+ return jjStartNfaWithStates_0(0, 83, 23);\r
case 58:\r
jjmatchedKind = 69;\r
return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000L);\r
return jjMoveStringLiteralDfa2_0(active0, 0x2400000000042100L, active1, 0L);\r
case 102:\r
if ((active0 & 0x80000000L) != 0L)\r
- return jjStartNfaWithStates_0(1, 31, 2);\r
+ return jjStartNfaWithStates_0(1, 31, 49);\r
break;\r
case 104:\r
return jjMoveStringLiteralDfa2_0(active0, 0x1080010000000L, active1, 0L);\r
return jjMoveStringLiteralDfa2_0(active0, 0x200000000000L, active1, 0L);\r
case 114:\r
if ((active0 & 0x400000L) != 0L)\r
- return jjStartNfaWithStates_0(1, 22, 2);\r
+ return jjStartNfaWithStates_0(1, 22, 49);\r
return jjMoveStringLiteralDfa2_0(active0, 0x10000220000000L, active1, 0L);\r
case 115:\r
return jjMoveStringLiteralDfa2_0(active0, 0x80000L, active1, 0L);\r
return jjMoveStringLiteralDfa3_0(active0, 0x2000002040000400L, active1, 0L);\r
case 100:\r
if ((active0 & 0x200L) != 0L)\r
- return jjStartNfaWithStates_0(2, 9, 2);\r
+ return jjStartNfaWithStates_0(2, 9, 49);\r
else if ((active0 & 0x800000000L) != 0L)\r
- return jjStartNfaWithStates_0(2, 35, 2);\r
+ return jjStartNfaWithStates_0(2, 35, 49);\r
return jjMoveStringLiteralDfa3_0(active0, 0x180L, active1, 0L);\r
case 101:\r
return jjMoveStringLiteralDfa3_0(active0, 0x80030020000L, active1, 0x180000000L);\r
return jjMoveStringLiteralDfa3_0(active0, 0x104005000002000L, active1, 0L);\r
case 114:\r
if ((active0 & 0x200000L) != 0L)\r
- return jjStartNfaWithStates_0(2, 21, 2);\r
+ return jjStartNfaWithStates_0(2, 21, 49);\r
else if ((active0 & 0x400000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(2, 58, 2);\r
+ return jjStartNfaWithStates_0(2, 58, 49);\r
return jjMoveStringLiteralDfa3_0(active0, 0x840000800000L, active1, 0L);\r
case 115:\r
return jjMoveStringLiteralDfa3_0(active0, 0x2188020L, active1, 0L);\r
case 116:\r
if ((active0 & 0x1000L) != 0L)\r
- return jjStartNfaWithStates_0(2, 12, 2);\r
+ return jjStartNfaWithStates_0(2, 12, 49);\r
return jjMoveStringLiteralDfa3_0(active0, 0x8a0000108040000L, active1, 0L);\r
case 117:\r
return jjMoveStringLiteralDfa3_0(active0, 0x210200000000L, active1, 0L);\r
jjmatchedPos = 3;\r
}\r
else if ((active0 & 0x200000000L) != 0L)\r
- return jjStartNfaWithStates_0(3, 33, 2);\r
+ return jjStartNfaWithStates_0(3, 33, 49);\r
else if ((active0 & 0x4000000000L) != 0L)\r
- return jjStartNfaWithStates_0(3, 38, 2);\r
+ return jjStartNfaWithStates_0(3, 38, 49);\r
return jjMoveStringLiteralDfa4_0(active0, 0x88800000a980180L, active1, 0L);\r
case 104:\r
if ((active0 & 0x400L) != 0L)\r
- return jjStartNfaWithStates_0(3, 10, 2);\r
+ return jjStartNfaWithStates_0(3, 10, 49);\r
return jjMoveStringLiteralDfa4_0(active0, 0x20000000000000L, active1, 0L);\r
case 107:\r
return jjMoveStringLiteralDfa4_0(active0, 0x2000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa4_0(active0, 0x10000000000L, active1, 0L);\r
case 110:\r
if ((active0 & 0x10000000L) != 0L)\r
- return jjStartNfaWithStates_0(3, 28, 2);\r
+ return jjStartNfaWithStates_0(3, 28, 49);\r
else if ((active0 & 0x80000000000L) != 0L)\r
- return jjStartNfaWithStates_0(3, 43, 2);\r
+ return jjStartNfaWithStates_0(3, 43, 49);\r
return jjMoveStringLiteralDfa4_0(active0, 0x108000000000L, active1, 0L);\r
case 111:\r
return jjMoveStringLiteralDfa4_0(active0, 0x2000001000004010L, active1, 0L);\r
case 112:\r
if ((active0 & 0x1000000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(3, 60, 2);\r
+ return jjStartNfaWithStates_0(3, 60, 49);\r
return jjMoveStringLiteralDfa4_0(active0, 0x100000000L, active1, 0L);\r
case 114:\r
return jjMoveStringLiteralDfa4_0(active0, 0x20000L, active1, 0x180000000L);\r
return jjMoveStringLiteralDfa4_0(active0, 0x100000000040000L, active1, 0L);\r
case 119:\r
if ((active0 & 0x10000L) != 0L)\r
- return jjStartNfaWithStates_0(3, 16, 2);\r
+ return jjStartNfaWithStates_0(3, 16, 49);\r
break;\r
default :\r
break;\r
return jjMoveStringLiteralDfa5_0(active0, 0x100L, active1, 0L);\r
case 101:\r
if ((active0 & 0x40L) != 0L)\r
- return jjStartNfaWithStates_0(4, 6, 2);\r
+ return jjStartNfaWithStates_0(4, 6, 49);\r
else if ((active0 & 0x1000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(4, 48, 2);\r
+ return jjStartNfaWithStates_0(4, 48, 49);\r
return jjMoveStringLiteralDfa5_0(active0, 0x10118000000000L, active1, 0L);\r
case 105:\r
return jjMoveStringLiteralDfa5_0(active0, 0x220c00000100000L, active1, 0L);\r
case 107:\r
if ((active0 & 0x1000000L) != 0L)\r
- return jjStartNfaWithStates_0(4, 24, 2);\r
+ return jjStartNfaWithStates_0(4, 24, 49);\r
else if ((active0 & 0x20000000L) != 0L)\r
- return jjStartNfaWithStates_0(4, 29, 2);\r
+ return jjStartNfaWithStates_0(4, 29, 49);\r
break;\r
case 108:\r
if ((active0 & 0x80L) != 0L)\r
- return jjStartNfaWithStates_0(4, 7, 2);\r
+ return jjStartNfaWithStates_0(4, 7, 49);\r
else if ((active0 & 0x800L) != 0L)\r
- return jjStartNfaWithStates_0(4, 11, 2);\r
+ return jjStartNfaWithStates_0(4, 11, 49);\r
break;\r
case 109:\r
return jjMoveStringLiteralDfa5_0(active0, 0x40000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa5_0(active0, 0x40000000L, active1, 0L);\r
case 114:\r
if ((active0 & 0x8000000L) != 0L)\r
- return jjStartNfaWithStates_0(4, 27, 2);\r
+ return jjStartNfaWithStates_0(4, 27, 49);\r
else if ((active0 & 0x8000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(4, 51, 2);\r
+ return jjStartNfaWithStates_0(4, 51, 49);\r
return jjMoveStringLiteralDfa5_0(active0, 0x28000010000c0030L, active1, 0L);\r
case 115:\r
if ((active0 & 0x400000000L) != 0L)\r
- return jjStartNfaWithStates_0(4, 34, 2);\r
+ return jjStartNfaWithStates_0(4, 34, 49);\r
break;\r
case 116:\r
if ((active0 & 0x100000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(4, 56, 2);\r
+ return jjStartNfaWithStates_0(4, 56, 49);\r
return jjMoveStringLiteralDfa5_0(active0, 0x42200004004000L, active1, 0L);\r
case 117:\r
return jjMoveStringLiteralDfa5_0(active0, 0x100000000L, active1, 0L);\r
return jjMoveStringLiteralDfa6_0(active0, 0x2c00000004000L, active1, 0L);\r
case 99:\r
if ((active0 & 0x200000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 57, 2);\r
+ return jjStartNfaWithStates_0(5, 57, 49);\r
return jjMoveStringLiteralDfa6_0(active0, 0x10108000002000L, active1, 0L);\r
case 100:\r
if ((active0 & 0x2000000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 61, 2);\r
+ return jjStartNfaWithStates_0(5, 61, 49);\r
return jjMoveStringLiteralDfa6_0(active0, 0x84000000000000L, active1, 0L);\r
case 101:\r
return jjMoveStringLiteralDfa6_0(active0, 0x40000000020L, active1, 0L);\r
case 102:\r
if ((active0 & 0x100000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 20, 2);\r
+ return jjStartNfaWithStates_0(5, 20, 49);\r
break;\r
case 103:\r
return jjMoveStringLiteralDfa6_0(active0, 0x2000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa6_0(active0, 0x100L, active1, 0L);\r
case 109:\r
if ((active0 & 0x800000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 23, 2);\r
+ return jjStartNfaWithStates_0(5, 23, 49);\r
break;\r
case 110:\r
if ((active0 & 0x40000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 18, 2);\r
+ return jjStartNfaWithStates_0(5, 18, 49);\r
else if ((active0 & 0x20000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 53, 2);\r
+ return jjStartNfaWithStates_0(5, 53, 49);\r
return jjMoveStringLiteralDfa6_0(active0, 0x800000000000000L, active1, 0L);\r
case 114:\r
return jjMoveStringLiteralDfa6_0(active0, 0x40010000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa6_0(active0, 0x40000000L, active1, 0L);\r
case 116:\r
if ((active0 & 0x80000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 19, 2);\r
+ return jjStartNfaWithStates_0(5, 19, 49);\r
else if ((active0 & 0x100000000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 32, 2);\r
+ return jjStartNfaWithStates_0(5, 32, 49);\r
else if ((active0 & 0x1000000000L) != 0L)\r
- return jjStartNfaWithStates_0(5, 36, 2);\r
+ return jjStartNfaWithStates_0(5, 36, 49);\r
return jjMoveStringLiteralDfa6_0(active0, 0x20000L, active1, 0x180000000L);\r
default :\r
break;\r
return jjMoveStringLiteralDfa7_0(active0, 0x844010000000100L, active1, 0L);\r
case 101:\r
if ((active0 & 0x2000000000L) != 0L)\r
- return jjStartNfaWithStates_0(6, 37, 2);\r
+ return jjStartNfaWithStates_0(6, 37, 49);\r
return jjMoveStringLiteralDfa7_0(active0, 0x2002000L, active1, 0L);\r
case 108:\r
if ((active0 & 0x400000000000L) != 0L)\r
- return jjStartNfaWithStates_0(6, 46, 2);\r
+ return jjStartNfaWithStates_0(6, 46, 49);\r
else if ((active0 & 0x800000000000L) != 0L)\r
- return jjStartNfaWithStates_0(6, 47, 2);\r
+ return jjStartNfaWithStates_0(6, 47, 49);\r
break;\r
case 110:\r
return jjMoveStringLiteralDfa7_0(active0, 0x2000000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa7_0(active0, 0x200004020000L, active1, 0x180000000L);\r
case 115:\r
if ((active0 & 0x80000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(6, 55, 2);\r
+ return jjStartNfaWithStates_0(6, 55, 49);\r
break;\r
case 116:\r
if ((active0 & 0x8000000000L) != 0L)\r
return jjMoveStringLiteralDfa8_0(active0, 0x4000000000000L, active1, 0L);\r
case 101:\r
if ((active0 & 0x20L) != 0L)\r
- return jjStartNfaWithStates_0(7, 5, 2);\r
+ return jjStartNfaWithStates_0(7, 5, 49);\r
return jjMoveStringLiteralDfa8_0(active0, 0x10040000000000L, active1, 0L);\r
case 104:\r
return jjMoveStringLiteralDfa8_0(active0, 0x10L, active1, 0L);\r
return jjMoveStringLiteralDfa8_0(active0, 0x40000000004000L, active1, 0L);\r
case 108:\r
if ((active0 & 0x800000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(7, 59, 2);\r
+ return jjStartNfaWithStates_0(7, 59, 49);\r
return jjMoveStringLiteralDfa8_0(active0, 0x40000000L, active1, 0L);\r
case 110:\r
if ((active0 & 0x2000000L) != 0L)\r
- return jjStartNfaWithStates_0(7, 25, 2);\r
+ return jjStartNfaWithStates_0(7, 25, 49);\r
else if ((active0 & 0x4000000L) != 0L)\r
- return jjStartNfaWithStates_0(7, 26, 2);\r
+ return jjStartNfaWithStates_0(7, 26, 49);\r
else if ((active0 & 0x200000000000L) != 0L)\r
- return jjStartNfaWithStates_0(7, 45, 2);\r
+ return jjStartNfaWithStates_0(7, 45, 49);\r
break;\r
case 111:\r
return jjMoveStringLiteralDfa8_0(active0, 0x100000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa8_0(active0, 0x100L, active1, 0x180000000L);\r
case 116:\r
if ((active0 & 0x2000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(7, 49, 2);\r
+ return jjStartNfaWithStates_0(7, 49, 49);\r
return jjMoveStringLiteralDfa8_0(active0, 0x10000000000L, active1, 0L);\r
default :\r
break;\r
return jjMoveStringLiteralDfa9_0(active0, 0x2000L, active1, 0L);\r
case 100:\r
if ((active0 & 0x10000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(8, 52, 2);\r
+ return jjStartNfaWithStates_0(8, 52, 49);\r
break;\r
case 101:\r
if ((active0 & 0x100L) != 0L)\r
- return jjStartNfaWithStates_0(8, 8, 2);\r
+ return jjStartNfaWithStates_0(8, 8, 49);\r
break;\r
case 105:\r
return jjMoveStringLiteralDfa9_0(active0, 0x10000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa9_0(active0, 0x4000000000000L, active1, 0L);\r
case 109:\r
if ((active0 & 0x10L) != 0L)\r
- return jjStartNfaWithStates_0(8, 4, 2);\r
+ return jjStartNfaWithStates_0(8, 4, 49);\r
break;\r
case 110:\r
return jjMoveStringLiteralDfa9_0(active0, 0x40000000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa9_0(active0, 0x4000L, active1, 0L);\r
case 114:\r
if ((active0 & 0x40000000000L) != 0L)\r
- return jjStartNfaWithStates_0(8, 42, 2);\r
+ return jjStartNfaWithStates_0(8, 42, 49);\r
else if ((active0 & 0x100000000000L) != 0L)\r
- return jjStartNfaWithStates_0(8, 44, 2);\r
+ return jjStartNfaWithStates_0(8, 44, 49);\r
break;\r
default :\r
break;\r
{\r
case 101:\r
if ((active0 & 0x4000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(9, 50, 2);\r
+ return jjStartNfaWithStates_0(9, 50, 49);\r
return jjMoveStringLiteralDfa10_0(active0, 0x40000000000000L, active1, 0L);\r
case 102:\r
return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x80000000L);\r
return jjMoveStringLiteralDfa10_0(active0, 0x2000L, active1, 0L);\r
case 110:\r
if ((active0 & 0x4000L) != 0L)\r
- return jjStartNfaWithStates_0(9, 14, 2);\r
+ return jjStartNfaWithStates_0(9, 14, 49);\r
break;\r
case 111:\r
return jjMoveStringLiteralDfa10_0(active0, 0x10000000000L, active1, 0L);\r
return jjMoveStringLiteralDfa11_0(active0, 0x40000000000000L, active1, 0L);\r
case 101:\r
if ((active0 & 0x2000L) != 0L)\r
- return jjStartNfaWithStates_0(10, 13, 2);\r
+ return jjStartNfaWithStates_0(10, 13, 49);\r
return jjMoveStringLiteralDfa11_0(active0, 0x40000000L, active1, 0x100000000L);\r
case 110:\r
if ((active0 & 0x10000000000L) != 0L)\r
- return jjStartNfaWithStates_0(10, 40, 2);\r
+ return jjStartNfaWithStates_0(10, 40, 49);\r
break;\r
case 117:\r
return jjMoveStringLiteralDfa11_0(active0, 0L, active1, 0x80000000L);\r
return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x100000000L);\r
case 100:\r
if ((active0 & 0x40000000L) != 0L)\r
- return jjStartNfaWithStates_0(11, 30, 2);\r
+ return jjStartNfaWithStates_0(11, 30, 49);\r
break;\r
case 110:\r
return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x80000000L);\r
return jjMoveStringLiteralDfa13_0(active0, 0L, active1, 0x100000000L);\r
case 121:\r
if ((active0 & 0x40000000000000L) != 0L)\r
- return jjStartNfaWithStates_0(12, 54, 2);\r
+ return jjStartNfaWithStates_0(12, 54, 49);\r
break;\r
default :\r
break;\r
private int jjMoveNfa_0(int startState, int curPos)\r
{\r
int startsAt = 0;\r
- jjnewStateCnt = 48;\r
+ jjnewStateCnt = 49;\r
int i = 1;\r
jjstateSet[0] = startState;\r
int kind = 0x7fffffff;\r
{\r
switch(jjstateSet[--i])\r
{\r
+ case 23:\r
+ if (curChar == 47)\r
+ {\r
+ if (kind > 3)\r
+ kind = 3;\r
+ jjCheckNAdd(30);\r
+ }\r
+ else if (curChar == 42)\r
+ jjCheckNAddStates(0, 2);\r
+ break;\r
+ case 49:\r
+ if ((0x3ff000000000000L & l) != 0L)\r
+ {\r
+ if (kind > 90)\r
+ kind = 90;\r
+ jjCheckNAddTwoStates(2, 3);\r
+ }\r
+ else if (curChar == 46)\r
+ jjCheckNAdd(2);\r
+ break;\r
case 0:\r
if ((0x3ff000000000000L & l) != 0L)\r
{\r
if (kind > 93)\r
kind = 93;\r
- jjCheckNAddStates(0, 6);\r
+ jjCheckNAddStates(3, 9);\r
}\r
else if ((0x100002600L & l) != 0L)\r
{\r
kind = 1;\r
}\r
else if (curChar == 47)\r
- jjAddStates(7, 8);\r
+ jjAddStates(10, 11);\r
else if (curChar == 46)\r
- jjCheckNAdd(10);\r
+ jjCheckNAdd(11);\r
else if (curChar == 34)\r
- jjCheckNAddStates(9, 11);\r
+ jjCheckNAddStates(12, 14);\r
break;\r
- case 48:\r
- if ((0x3ff400000000000L & l) != 0L)\r
+ case 50:\r
+ if ((0x3ff000000000000L & l) != 0L)\r
{\r
if (kind > 90)\r
kind = 90;\r
- jjCheckNAdd(2);\r
+ jjCheckNAddTwoStates(2, 3);\r
}\r
else if (curChar == 43)\r
{\r
if (kind > 92)\r
kind = 92;\r
}\r
- break;\r
- case 22:\r
- if (curChar == 47)\r
- {\r
- if (kind > 3)\r
- kind = 3;\r
- jjCheckNAdd(29);\r
- }\r
- else if (curChar == 42)\r
- jjCheckNAddStates(12, 14);\r
+ else if (curChar == 46)\r
+ jjCheckNAdd(2);\r
break;\r
case 2:\r
- if ((0x3ff400000000000L & l) == 0L)\r
+ if ((0x3ff000000000000L & l) == 0L)\r
break;\r
if (kind > 90)\r
kind = 90;\r
- jjCheckNAdd(2);\r
+ jjCheckNAddTwoStates(2, 3);\r
break;\r
case 3:\r
- if (curChar == 34)\r
- jjCheckNAddStates(9, 11);\r
+ if (curChar == 46)\r
+ jjCheckNAdd(2);\r
break;\r
case 4:\r
+ if (curChar == 34)\r
+ jjCheckNAddStates(12, 14);\r
+ break;\r
+ case 5:\r
if ((0xfffffffbfffffbffL & l) != 0L)\r
- jjCheckNAddStates(9, 11);\r
+ jjCheckNAddStates(12, 14);\r
break;\r
- case 6:\r
+ case 7:\r
if ((0xfffffffffffffbffL & l) != 0L)\r
- jjCheckNAddStates(9, 11);\r
+ jjCheckNAddStates(12, 14);\r
break;\r
- case 7:\r
+ case 8:\r
if (curChar == 34 && kind > 91)\r
kind = 91;\r
break;\r
- case 9:\r
+ case 10:\r
if (curChar == 46)\r
- jjCheckNAdd(10);\r
+ jjCheckNAdd(11);\r
break;\r
- case 10:\r
+ case 11:\r
if ((0x3ff000000000000L & l) == 0L)\r
break;\r
if (kind > 94)\r
kind = 94;\r
jjCheckNAddStates(15, 18);\r
break;\r
- case 12:\r
+ case 13:\r
if ((0x3ff000000000000L & l) == 0L)\r
break;\r
if (kind > 94)\r
kind = 94;\r
- jjCheckNAdd(12);\r
+ jjCheckNAdd(13);\r
break;\r
- case 14:\r
+ case 15:\r
if (curChar == 45)\r
- jjCheckNAdd(12);\r
+ jjCheckNAdd(13);\r
break;\r
- case 15:\r
+ case 16:\r
if (curChar == 43)\r
- jjCheckNAdd(12);\r
+ jjCheckNAdd(13);\r
break;\r
- case 18:\r
+ case 19:\r
if (curChar == 45 && kind > 92)\r
kind = 92;\r
break;\r
- case 19:\r
+ case 20:\r
if (curChar == 43 && kind > 92)\r
kind = 92;\r
break;\r
- case 21:\r
+ case 22:\r
if (curChar == 47)\r
- jjAddStates(7, 8);\r
+ jjAddStates(10, 11);\r
break;\r
- case 23:\r
+ case 24:\r
if ((0xfffffbffffffffffL & l) != 0L)\r
- jjCheckNAddStates(12, 14);\r
+ jjCheckNAddStates(0, 2);\r
break;\r
- case 24:\r
+ case 25:\r
if (curChar == 42)\r
- jjstateSet[jjnewStateCnt++] = 25;\r
+ jjstateSet[jjnewStateCnt++] = 26;\r
break;\r
- case 25:\r
+ case 26:\r
if ((0xffff7fffffffffffL & l) != 0L)\r
- jjCheckNAddStates(12, 14);\r
+ jjCheckNAddStates(0, 2);\r
break;\r
- case 26:\r
+ case 27:\r
if (curChar == 47 && kind > 2)\r
kind = 2;\r
break;\r
- case 27:\r
+ case 28:\r
if (curChar == 42)\r
- jjstateSet[jjnewStateCnt++] = 26;\r
+ jjstateSet[jjnewStateCnt++] = 27;\r
break;\r
- case 28:\r
+ case 29:\r
if (curChar != 47)\r
break;\r
if (kind > 3)\r
kind = 3;\r
- jjCheckNAdd(29);\r
+ jjCheckNAdd(30);\r
break;\r
- case 29:\r
+ case 30:\r
if ((0xfffffffffffffbffL & l) == 0L)\r
break;\r
if (kind > 3)\r
kind = 3;\r
- jjCheckNAdd(29);\r
+ jjCheckNAdd(30);\r
break;\r
- case 30:\r
+ case 31:\r
if ((0x3ff000000000000L & l) == 0L)\r
break;\r
if (kind > 93)\r
kind = 93;\r
- jjCheckNAddStates(0, 6);\r
+ jjCheckNAddStates(3, 9);\r
break;\r
- case 31:\r
+ case 32:\r
if ((0x3ff000000000000L & l) == 0L)\r
break;\r
if (kind > 93)\r
kind = 93;\r
- jjCheckNAdd(31);\r
+ jjCheckNAdd(32);\r
break;\r
- case 32:\r
+ case 33:\r
if ((0x3ff000000000000L & l) != 0L)\r
- jjCheckNAddTwoStates(32, 33);\r
+ jjCheckNAddTwoStates(33, 34);\r
break;\r
- case 33:\r
+ case 34:\r
if (curChar != 46)\r
break;\r
if (kind > 94)\r
kind = 94;\r
jjCheckNAddStates(19, 22);\r
break;\r
- case 34:\r
+ case 35:\r
if ((0x3ff000000000000L & l) == 0L)\r
break;\r
if (kind > 94)\r
kind = 94;\r
jjCheckNAddStates(19, 22);\r
break;\r
- case 36:\r
+ case 37:\r
if ((0x3ff000000000000L & l) == 0L)\r
break;\r
if (kind > 94)\r
kind = 94;\r
- jjCheckNAdd(36);\r
+ jjCheckNAdd(37);\r
break;\r
- case 38:\r
+ case 39:\r
if (curChar == 45)\r
- jjCheckNAdd(36);\r
+ jjCheckNAdd(37);\r
break;\r
- case 39:\r
+ case 40:\r
if (curChar == 43)\r
- jjCheckNAdd(36);\r
+ jjCheckNAdd(37);\r
break;\r
- case 41:\r
+ case 42:\r
if ((0x3ff000000000000L & l) != 0L)\r
jjCheckNAddStates(23, 26);\r
break;\r
- case 43:\r
+ case 44:\r
if ((0x3ff000000000000L & l) == 0L)\r
break;\r
if (kind > 94)\r
kind = 94;\r
- jjCheckNAdd(43);\r
+ jjCheckNAdd(44);\r
break;\r
- case 45:\r
+ case 46:\r
if (curChar == 45)\r
- jjCheckNAdd(43);\r
+ jjCheckNAdd(44);\r
break;\r
- case 46:\r
+ case 47:\r
if (curChar == 43)\r
- jjCheckNAdd(43);\r
+ jjCheckNAdd(44);\r
break;\r
default : break;\r
}\r
{\r
switch(jjstateSet[--i])\r
{\r
+ case 49:\r
+ case 2:\r
+ if ((0x7fffffe87fffffeL & l) == 0L)\r
+ break;\r
+ if (kind > 90)\r
+ kind = 90;\r
+ jjCheckNAddTwoStates(2, 3);\r
+ break;\r
case 0:\r
if ((0x7fffffe87fffffeL & l) != 0L)\r
{\r
if (kind > 90)\r
kind = 90;\r
- jjCheckNAdd(2);\r
+ jjCheckNAddTwoStates(2, 3);\r
}\r
if ((0x2000000020L & l) != 0L)\r
{\r
kind = 92;\r
}\r
if (curChar == 69)\r
- jjCheckNAddTwoStates(18, 19);\r
+ jjCheckNAddTwoStates(19, 20);\r
else if (curChar == 101)\r
- jjCheckNAddTwoStates(18, 19);\r
+ jjCheckNAddTwoStates(19, 20);\r
break;\r
- case 48:\r
- case 2:\r
+ case 50:\r
if ((0x7fffffe87fffffeL & l) == 0L)\r
break;\r
if (kind > 90)\r
kind = 90;\r
- jjCheckNAdd(2);\r
+ jjCheckNAddTwoStates(2, 3);\r
break;\r
case 1:\r
if ((0x7fffffe87fffffeL & l) == 0L)\r
break;\r
if (kind > 90)\r
kind = 90;\r
- jjCheckNAdd(2);\r
+ jjCheckNAddTwoStates(2, 3);\r
break;\r
- case 4:\r
+ case 5:\r
if ((0xffffffffefffffffL & l) != 0L)\r
- jjCheckNAddStates(9, 11);\r
+ jjCheckNAddStates(12, 14);\r
break;\r
- case 5:\r
+ case 6:\r
if (curChar == 92)\r
- jjstateSet[jjnewStateCnt++] = 6;\r
+ jjstateSet[jjnewStateCnt++] = 7;\r
break;\r
- case 6:\r
- jjCheckNAddStates(9, 11);\r
+ case 7:\r
+ jjCheckNAddStates(12, 14);\r
break;\r
- case 8:\r
+ case 9:\r
if ((0x2000000020L & l) != 0L && kind > 92)\r
kind = 92;\r
break;\r
- case 11:\r
+ case 12:\r
if ((0x2000000020L & l) != 0L)\r
- jjstateSet[jjnewStateCnt++] = 12;\r
+ jjstateSet[jjnewStateCnt++] = 13;\r
break;\r
- case 13:\r
+ case 14:\r
if (curChar == 101)\r
- jjCheckNAddTwoStates(14, 15);\r
+ jjCheckNAddTwoStates(15, 16);\r
break;\r
- case 16:\r
+ case 17:\r
if (curChar == 69)\r
- jjCheckNAddTwoStates(14, 15);\r
+ jjCheckNAddTwoStates(15, 16);\r
break;\r
- case 17:\r
+ case 18:\r
if (curChar == 101)\r
- jjCheckNAddTwoStates(18, 19);\r
+ jjCheckNAddTwoStates(19, 20);\r
break;\r
- case 20:\r
+ case 21:\r
if (curChar == 69)\r
- jjCheckNAddTwoStates(18, 19);\r
+ jjCheckNAddTwoStates(19, 20);\r
break;\r
- case 23:\r
- case 25:\r
- jjCheckNAddStates(12, 14);\r
+ case 24:\r
+ case 26:\r
+ jjCheckNAddStates(0, 2);\r
break;\r
- case 29:\r
+ case 30:\r
if (kind > 3)\r
kind = 3;\r
- jjstateSet[jjnewStateCnt++] = 29;\r
+ jjstateSet[jjnewStateCnt++] = 30;\r
break;\r
- case 35:\r
+ case 36:\r
if ((0x2000000020L & l) != 0L)\r
- jjstateSet[jjnewStateCnt++] = 36;\r
+ jjstateSet[jjnewStateCnt++] = 37;\r
break;\r
- case 37:\r
+ case 38:\r
if (curChar == 101)\r
- jjCheckNAddTwoStates(38, 39);\r
+ jjCheckNAddTwoStates(39, 40);\r
break;\r
- case 40:\r
+ case 41:\r
if (curChar == 69)\r
- jjCheckNAddTwoStates(38, 39);\r
+ jjCheckNAddTwoStates(39, 40);\r
break;\r
- case 42:\r
+ case 43:\r
if ((0x2000000020L & l) != 0L)\r
- jjstateSet[jjnewStateCnt++] = 43;\r
+ jjstateSet[jjnewStateCnt++] = 44;\r
break;\r
- case 44:\r
+ case 45:\r
if (curChar == 101)\r
- jjCheckNAddTwoStates(45, 46);\r
+ jjCheckNAddTwoStates(46, 47);\r
break;\r
- case 47:\r
+ case 48:\r
if (curChar == 69)\r
- jjCheckNAddTwoStates(45, 46);\r
+ jjCheckNAddTwoStates(46, 47);\r
break;\r
default : break;\r
}\r
{\r
switch(jjstateSet[--i])\r
{\r
- case 4:\r
- case 6:\r
+ case 5:\r
+ case 7:\r
if ((jjbitVec0[i2] & l2) != 0L)\r
- jjCheckNAddStates(9, 11);\r
+ jjCheckNAddStates(12, 14);\r
break;\r
- case 23:\r
- case 25:\r
+ case 24:\r
+ case 26:\r
if ((jjbitVec0[i2] & l2) != 0L)\r
- jjCheckNAddStates(12, 14);\r
+ jjCheckNAddStates(0, 2);\r
break;\r
- case 29:\r
+ case 30:\r
if ((jjbitVec0[i2] & l2) == 0L)\r
break;\r
if (kind > 3)\r
kind = 3;\r
- jjstateSet[jjnewStateCnt++] = 29;\r
+ jjstateSet[jjnewStateCnt++] = 30;\r
break;\r
default : break;\r
}\r
kind = 0x7fffffff;\r
}\r
++curPos;\r
- if ((i = jjnewStateCnt) == (startsAt = 48 - (jjnewStateCnt = startsAt)))\r
+ if ((i = jjnewStateCnt) == (startsAt = 49 - (jjnewStateCnt = startsAt)))\r
return curPos;\r
try { curChar = input_stream.readChar(); }\r
catch(java.io.IOException e) { return curPos; }\r
}\r
}\r
static final int[] jjnextStates = {
- 31, 32, 33, 41, 42, 44, 47, 22, 28, 4, 5, 7, 23, 24, 27, 10,
- 11, 13, 16, 34, 35, 37, 40, 41, 42, 44, 47,
+ 24, 25, 28, 32, 33, 34, 42, 43, 45, 48, 23, 29, 5, 6, 8, 11,
+ 12, 14, 17, 35, 36, 38, 41, 42, 43, 45, 48,
};\r
\r
/** Token literal values. */\r
0xeL, 0x0L,
};\r
protected SimpleCharStream input_stream;\r
-private final int[] jjrounds = new int[48];\r
-private final int[] jjstateSet = new int[96];\r
+private final int[] jjrounds = new int[49];\r
+private final int[] jjstateSet = new int[98];\r
private final StringBuilder jjimage = new StringBuilder();\r
private StringBuilder image = jjimage;\r
private int jjimageLen;\r
{\r
int i;\r
jjround = 0x80000001;\r
- for (i = 48; i-- > 0;)\r
+ for (i = 49; i-- > 0;)\r
jjrounds[i] = 0x80000000;\r
}\r
\r
| "*" | "/" | ".*" | "./"\r
| "^" | ".^"\r
| "=" | ":=" \r
-| <IDENT: ["a"-"z","A"-"Z","_"] (["a"-"z","A"-"Z","_",".", "0"-"9"])* >\r
+| <IDENT: ["a"-"z","A"-"Z","_"] (["a"-"z","A"-"Z","_","0"-"9"] | "." ["a"-"z","A"-"Z","_","0"-"9"])* >\r
| <STRING: "\"" (~["\"", "\\", "\n"] | "\\" ~["\n"])* "\"">\r
{ matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); }\r
| <EXP: "e" | "e-" | "E" | "E-" | "E+" | "e+" >\r
/*** Class Definition **********************************************/\r
\r
void class_definition() : {/*@bgen(jjtree) class_definition */\r
- SimpleNode jjtn000 = new SimpleNode(JJTCLASS_DEFINITION);\r
- boolean jjtc000 = true;\r
- jjtree.openNodeScope(jjtn000);\r
-/*@egen*/\r
+ SimpleNode jjtn000 = new SimpleNode(JJTCLASS_DEFINITION);\r
+ boolean jjtc000 = true;\r
+ jjtree.openNodeScope(jjtn000);\r
+/*@egen*/ Token t;\r
} {/*@bgen(jjtree) class_definition */\r
try {\r
/*@egen*/\r
// class_specifier\r
( "encapsulated" )?\r
( "partial" )?\r
- ( "class" { jjtn000.op = "class"; } | "model" { jjtn000.op = "model"; } | "record" | "block" | ( "expandable" )? "connector" | "type" |\r
+ ( "class" { jjtn000.op = "class"; } | t = "model" { jjtn000.op = "model"; jjtn000.line = t.beginLine; } | "record" | "block" | ( "expandable" )? "connector" | "type" |\r
"package" { jjtn000.op = "package"; } | "function" { jjtn000.op = "function"; } | "operator" | "operator function" | "operator record" )\r
class_specifier()/*@bgen(jjtree)*/\r
} catch (Throwable jjte000) {\r
// | IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment\r
// | extends IDENT [ class_modification ] string_comment composition\r
// end IDENT \r
- LOOKAHEAD(2) t=<IDENT> { jjtn000.op = t.image; } string_comment() composition() "end" <IDENT>\r
+ LOOKAHEAD(2) t=<IDENT> { jjtn000.op = t.image; jjtn000.line = t.beginLine; } string_comment() composition() "end" <IDENT>\r
| LOOKAHEAD(2) <IDENT> "=" base_prefix() name() ( array_subscripts() )? ( class_modification() )? comment()\r
| LOOKAHEAD(3) <IDENT> "=" "der" "(" name() "," <IDENT> ( "," <IDENT> )* ")" comment()\r
| LOOKAHEAD(3) <IDENT> "=" "enumeration" "(" ( ( enum_list() )? | ":" ) ")" comment()/*@bgen(jjtree)*/\r
try {\r
/*@egen*/\r
// IDENT [ array_subscripts ] [ modification ]\r
- <IDENT> { ret.name = new String(token.image); jjtn000.op = token.image; }\r
+ <IDENT> { ret.name = new String(token.image); jjtn000.op = token.image; jjtn000.line = token.beginLine; }\r
( array_subscripts() )?\r
( ret.optional = modification() )?/*@bgen(jjtree)*/\r
{\r
// comment\r
( component_reference() ( ":=" expression() | function_call_args() )\r
| "(" output_expression_list() ")" ":=" component_reference() function_call_args()\r
- | "break"\r
- | "return"\r
+ | "break" { jjtn000.op = "break";}\r
+ | "return" { jjtn000.op = "return";}\r
| if_statement()\r
| for_statement()\r
| while_statement()\r
jjtree.closeNodeScope(jjtn000, true);\r
jjtc000 = false;\r
}\r
-/*@egen*/ { jjtn000.op = "-";} | ".+" | ".-"/*@bgen(jjtree)*/\r
+/*@egen*/ { jjtn000.op = "-";} | ".+"/*@bgen(jjtree)*/\r
+ {\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ }\r
+/*@egen*/ { jjtn000.op = ".+";} | ".-"/*@bgen(jjtree)*/\r
+ {\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ }\r
+/*@egen*/ { jjtn000.op = ".-";}/*@bgen(jjtree)*/\r
} finally {\r
if (jjtc000) {\r
jjtree.closeNodeScope(jjtn000, true);\r
} {/*@bgen(jjtree) mul_op */\r
try {\r
/*@egen*/\r
- "*"/*@bgen(jjtree)*/\r
- {\r
- jjtree.closeNodeScope(jjtn000, true);\r
- jjtc000 = false;\r
- }\r
-/*@egen*/ { jjtn000.op = "*";} | "/"/*@bgen(jjtree)*/\r
- {\r
- jjtree.closeNodeScope(jjtn000, true);\r
- jjtc000 = false;\r
- }\r
-/*@egen*/ { jjtn000.op = "/";} | ".*"/*@bgen(jjtree)*/\r
- {\r
- jjtree.closeNodeScope(jjtn000, true);\r
- jjtc000 = false;\r
- }\r
+ ".*"/*@bgen(jjtree)*/\r
+ {\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ }\r
/*@egen*/ { jjtn000.op = ".*";} | "./"/*@bgen(jjtree)*/\r
- {\r
- jjtree.closeNodeScope(jjtn000, true);\r
- jjtc000 = false;\r
- }\r
-/*@egen*/ { jjtn000.op = "./";}/*@bgen(jjtree)*/\r
+ {\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ }\r
+/*@egen*/ { jjtn000.op = "./";} | "*"/*@bgen(jjtree)*/\r
+ {\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ }\r
+/*@egen*/ { jjtn000.op = "*";} | "/"/*@bgen(jjtree)*/\r
+ {\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtc000 = false;\r
+ }\r
+/*@egen*/ { jjtn000.op = "/";}/*@bgen(jjtree)*/\r
} finally {\r
if (jjtc000) {\r
jjtree.closeNodeScope(jjtn000, true);\r
}\r
}\r
-/*@egen*/\r
+/*@egen*/ \r
}\r
\r
void factor() : {/*@bgen(jjtree) factor */\r
try {\r
/*@egen*/\r
// [ "." ] IDENT [ array_subscripts ] { "." IDENT [ array_subscripts ] }\r
- ( "." )? t=<IDENT> { jjtn000.op = t.image; } ( array_subscripts() )? ( "." <IDENT> ( array_subscripts() )? )*/*@bgen(jjtree)*/\r
+ ( "." )? t=<IDENT> { jjtn000.op = t.image; jjtn000.line = t.beginLine; } ( array_subscripts() )? ( "." <IDENT> ( array_subscripts() )? )*/*@bgen(jjtree)*/\r
} catch (Throwable jjte000) {\r
if (jjtc000) {\r
jjtree.clearNodeScope(jjtn000);\r
| "*" | "/" | ".*" | "./"\r
| "^" | ".^"\r
| "=" | ":=" \r
-| <IDENT: ["a"-"z","A"-"Z","_"] (["a"-"z","A"-"Z","_",".", "0"-"9"])* >\r
+| <IDENT: ["a"-"z","A"-"Z","_"] (["a"-"z","A"-"Z","_","0"-"9"] | "." ["a"-"z","A"-"Z","_","0"-"9"])* >\r
| <STRING: "\"" (~["\"", "\\", "\n"] | "\\" ~["\n"])* "\"">\r
{ matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); }\r
| <EXP: "e" | "e-" | "E" | "E-" | "E+" | "e+" >\r
\r
/*** Class Definition **********************************************/\r
\r
-void class_definition() : {\r
+void class_definition() : { Token t;\r
} {\r
// class_definition :\r
// [ encapsulated ]\r
// class_specifier\r
( "encapsulated" )?\r
( "partial" )?\r
- ( "class" { jjtThis.op = "class"; } | "model" { jjtThis.op = "model"; } | "record" | "block" | ( "expandable" )? "connector" | "type" |\r
+ ( "class" { jjtThis.op = "class"; } | t = "model" { jjtThis.op = "model"; jjtThis.line = t.beginLine; } | "record" | "block" | ( "expandable" )? "connector" | "type" |\r
"package" { jjtThis.op = "package"; } | "function" { jjtThis.op = "function"; } | "operator" | "operator function" | "operator record" )\r
class_specifier()\r
}\r
// | IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment\r
// | extends IDENT [ class_modification ] string_comment composition\r
// end IDENT \r
- LOOKAHEAD(2) t=<IDENT> { jjtThis.op = t.image; } string_comment() composition() "end" <IDENT>\r
+ LOOKAHEAD(2) t=<IDENT> { jjtThis.op = t.image; jjtThis.line = t.beginLine; } string_comment() composition() "end" <IDENT>\r
| LOOKAHEAD(2) <IDENT> "=" base_prefix() name() ( array_subscripts() )? ( class_modification() )? comment()\r
| LOOKAHEAD(3) <IDENT> "=" "der" "(" name() "," <IDENT> ( "," <IDENT> )* ")" comment()\r
| LOOKAHEAD(3) <IDENT> "=" "enumeration" "(" ( ( enum_list() )? | ":" ) ")" comment()\r
Parameter ret = new Parameter();\r
} {\r
// IDENT [ array_subscripts ] [ modification ]\r
- <IDENT> { ret.name = new String(token.image); jjtThis.op = token.image; }\r
+ <IDENT> { ret.name = new String(token.image); jjtThis.op = token.image; jjtThis.line = token.beginLine; }\r
( array_subscripts() )?\r
( ret.optional = modification() )?\r
{\r return ret;\r }\r
// comment\r
( component_reference() ( ":=" expression() | function_call_args() )\r
| "(" output_expression_list() ")" ":=" component_reference() function_call_args()\r
- | "break"\r
- | "return"\r
+ | "break" { jjtThis.op = "break";}\r
+ | "return" { jjtThis.op = "return";}\r
| if_statement()\r
| for_statement()\r
| while_statement()\r
\r
void add_op() : {\r
} {\r
- "+" { jjtThis.op = "+";} | "-" { jjtThis.op = "-";} | ".+" | ".-"\r
+ "+" { jjtThis.op = "+";} | "-" { jjtThis.op = "-";} | ".+" { jjtThis.op = ".+";} | ".-" { jjtThis.op = ".-";}\r
}\r
\r
\r
\r
void mul_op() : {\r
} {\r
- "*" { jjtThis.op = "*";} | "/" { jjtThis.op = "/";} | ".*" { jjtThis.op = ".*";} | "./" { jjtThis.op = "./";}\r
+ ".*" { jjtThis.op = ".*";} | "./" { jjtThis.op = "./";} | "*" { jjtThis.op = "*";} | "/" { jjtThis.op = "/";} \r
}\r
\r
void factor() : {\r
Token t;\r
} {\r
// [ "." ] IDENT [ array_subscripts ] { "." IDENT [ array_subscripts ] }\r
- ( "." )? t=<IDENT> { jjtThis.op = t.image; } ( array_subscripts() )? ( "." <IDENT> ( array_subscripts() )? )*\r
+ ( "." )? t=<IDENT> { jjtThis.op = t.image; jjtThis.line = t.beginLine; } ( array_subscripts() )? ( "." <IDENT> ( array_subscripts() )? )*\r
}\r
\r
void function_call_args() : {\r
protected Object value;\r
protected ModelParser parser;\r
\r
+ public int line = -1;\r
public String op;\r
\r
public SimpleNode(int i) {\r