Selaa lähdekoodia

Implement array initialization rules as described in Issue #83

Lucas de Souza 5 vuotta sitten
vanhempi
commit
712823d337
1 muutettua tiedostoa jossa 12 lisäystä ja 0 poistoa
  1. 12 0
      js/ast/ivprogParser.js

+ 12 - 0
js/ast/ivprogParser.js

@@ -339,10 +339,22 @@ export class IVProgParser {
     let n_lines = dim1;
     let n_columns = dim2;
     let initial = null;
+    let dim_is_id = false;
+    if(dim1 instanceof Expressions.VariableLiteral || dim2 instanceof Expressions.VariableLiteral) {
+      dim_is_id = true;
+      if(dimensions > 1 && (dim1 == null || dim2 == null)) {
+        // TODO better error message
+        throw new Error("array with id dimension must have all dims");
+      }
+    }
     if(isConst && equalsToken.type !== this.lexerClass.EQUAL ) {
       throw SyntaxErrorFactory.const_not_init(sourceInfo);
     }
     if(equalsToken.type === this.lexerClass.EQUAL) {
+      if(dim_is_id) {
+        // TODO better error message
+        throw new Error("Cannot init array with a variable as dimesion");
+      }
       this.pos += 1
       initial = this.parseArrayLiteral(typeString);
     }