private Object subscript(IEnvironment environment, IExpression[] subscripts, int position) {\r
\r
IExpression e = subscripts[position];\r
- int index = Utils.getIndex(e.evaluate(environment));\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
}\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