Bläddra i källkod

Implement array initialization rules as described in Issue #83

Lucas de Souza 4 år sedan
förälder
incheckning
712823d337
1 ändrade filer med 12 tillägg och 0 borttagningar
  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);
     }