Browse Source

Merge branch 'master' into visualui

Lucas de Souza 5 years ago
parent
commit
3f725f2e0c

+ 27 - 26
js/processor/semantic/semanticAnalyser.js

@@ -55,6 +55,7 @@ export class SemanticAnalyser {
   }
 
   findFunction (name) {
+    console.log(name);
     if(name.match(/^\$.+$/)) {
       const fun = LanguageDefinedFunction.getFunction(name);
       if(!!!fun) {
@@ -237,29 +238,28 @@ export class SemanticAnalyser {
   }
 
   evaluateArrayLiteral (id, lines, columns, type, literal) {
-    if (literal instanceof ArrayLiteral) {
-      if (columns === null) {
-        // it's a vector...
-        const dimType = this.evaluateExpressionType(lines);
-        if (!dimType.isCompatible(Types.INTEGER)) {
-          throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
-        }
-        if ((lines instanceof IntLiteral)) {
-          if (!lines.value.eq(literal.value.length)) {
-            if(type.dimensions > 1) {
-              throw ProcessorErrorFactory.matrix_line_outbounds_full(id, literal.value.length, lines.values.toNumber(), literal.sourceInfo)
-            } else {
-              throw ProcessorErrorFactory.vector_line_outbounds_full(id, literal.value.length, lines.values.toNumber(), literal.sourceInfo)
-            }
-          } else if (lines.value.isNeg()) {
-            throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
+    /* if (literal instanceof ArrayLiteral) {
+      const dimType = this.evaluateExpressionType(lines);
+      if (!dimType.isCompatible(Types.INTEGER)) {
+        throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
+      }
+      if ((lines instanceof IntLiteral)) {
+        if (!lines.value.eq(literal.value.length)) {
+          if(type.dimensions > 1) {
+            throw ProcessorErrorFactory.matrix_line_outbounds_full(id, literal.value.length, lines.value.toNumber(), literal.sourceInfo)
+          } else {
+            throw ProcessorErrorFactory.vector_line_outbounds_full(id, literal.value.length, lines.value.toNumber(), literal.sourceInfo)
           }
-          
+        } else if (lines.value.isNeg()) {
+          throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
         }
+      }
+      if (columns === null) {
+        // it's a vector...
         literal.value.reduce((last, next) => {
           const eType = this.evaluateExpressionType(next);
           if (!last.canAccept(eType)) {
-            const strInfo = last.stringInfo();invalid
+            const strInfo = last.stringInfo();
             const info = strInfo[0];
             const strExp = literal.toString();
             throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
@@ -273,20 +273,20 @@ export class SemanticAnalyser {
           throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
         }
         if ((columns instanceof IntLiteral)) {
-          if (!columns.value.eq(literal.value.length)) {
+          const columnValue = literal.value[0].value.length;
+          if (!columns.value.eq(columnValue)) {
             if(type.dimensions > 1) {
-              throw ProcessorErrorFactory.matrix_column_outbounds_full(id, literal.value.length, columns.values.toNumber(), literal.sourceInfo)
+              throw ProcessorErrorFactory.matrix_column_outbounds_full(id, literal.value.length, columns.value.toNumber(), literal.sourceInfo)
             } else {
               throw ProcessorErrorFactory.invalid_matrix_access_full(id, literal.sourceInfo);
             }
           } else if (columns.value.isNeg()) {
             throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
           }
-          
-        }
-        for (let i = 0; i < columns; i++) {
-          const anotherArray = literal.value[i];
-          this.evaluateArrayLiteral(id, lines, null, type, anotherArray)
+          for (let i = 0; i < columns; i++) {
+            const anotherArray = literal.value[i];
+            this.evaluateArrayLiteral(id, columns, null, type, anotherArray)
+          }
         }
       }
 
@@ -306,7 +306,8 @@ export class SemanticAnalyser {
         throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
       }
       return true;
-    }
+    } */
+    return true;
   }
 
   assertFunction (fun) {

+ 2 - 2
js/services/languageService.js

@@ -2,12 +2,12 @@ import Lexers from './../../grammar/';
 import line_i18n from 'line-i18n';
 
 // This is for LanguageService with localStorage
-// const DEFAULT_LANG = "pt";
+const DEFAULT_LANG = "pt";
 
 class LanguageServiceExtended extends line_i18n.LanguageServiceNoLS {
 
   constructor () {
-    super(iLMparameters.lang);
+    super(DEFAULT_LANG);
   }
 
   getCurrentLexer () {

+ 3 - 3
tests/test65.spec.js

@@ -10,7 +10,7 @@ describe('Non initialized vector/matrix', function () {
 
     funcao inicio() {
       inteiro a[16] = {1,8,3,5,7,4,2,1,8,3,5,7,-4,2,10,-1}
-      inteiro tam = numero_elementos(a) - 1
+      inteiro tam = total_de_elementos(a) - 1
       inteiro i
       a = mergeSort(a, 0, tam)
       para(i = 0; i< tam; i = i + 1) {
@@ -36,8 +36,8 @@ describe('Non initialized vector/matrix', function () {
     }
   
     funcao inteiro[] merge(inteiro p1[], inteiro p2[]) {
-      inteiro lenp1 = numero_elementos(p1)
-      inteiro lenp2 = numero_elementos(p2)
+      inteiro lenp1 = total_de_elementos(p1)
+      inteiro lenp2 = total_de_elementos(p2)
       inteiro sizeF = lenp1 + lenp2
       inteiro f[sizeF]
       inteiro i = 0, a = 0, b =0

+ 1 - 1
tests/test68.spec.js

@@ -8,7 +8,7 @@ describe('Tangent of 90° angles', function () {
   let input = `programa {
 
     funcao inicio() {
-      escreva(Matematica.tan(90))
+      escreva(Matematica.tangente(90))
     }
   }`;
 

+ 23 - 0
tests/testMatrixSemantic.spec.js

@@ -0,0 +1,23 @@
+import { IVProgParser } from './../js/ast/ivprogParser';
+import { IVProgProcessor} from './../js/processor/ivprogProcessor'
+import { SemanticAnalyser } from "./../js/processor/semantic/semanticAnalyser";
+import { LanguageService } from '../js/services/languageService';
+
+describe('A valid matrix declaration', function () {
+
+  let input = `programa {
+
+    funcao inicio() {
+      real v[4][2] = {{1,1},{1,1},{1,1},{1,1}}
+    }
+  }`;
+
+  const lexer = LanguageService.getCurrentLexer();
+
+  it(`should not throw a semantic exception`, function () {
+    const parser = new IVProgParser(input, lexer);
+    const semantic = new SemanticAnalyser(parser.parseTree());
+    const fun = semantic.analyseTree.bind(semantic);
+    expect(fun).not.toThrow();
+  });
+});