Ver Fonte

[FIX] Bug in parsePrograma for non-const declarations

[FIX] Test cases using 'casocontrario' instead of 'caso contrario'
Lucas de Souza há 6 anos atrás
pai
commit
e6fb1c7b25
5 ficheiros alterados com 19 adições e 19 exclusões
  1. 1 1
      js/ast/ivprogParser.js
  2. 13 13
      js/main.js
  3. 2 2
      tests/test12.spec.js
  4. 2 2
      tests/test13.spec.js
  5. 1 1
      tests/test14.spec.js

+ 1 - 1
js/ast/ivprogParser.js

@@ -81,7 +81,7 @@ export class IVProgParser {
       while(true) {
         this.consumeNewLines();
         const token = this.getToken();
-        if (token.type === this.lexerClass.RK_CONST || token.type === this.lexerClass.ID) {
+        if (token.type === this.lexerClass.RK_CONST || this.isVariableType(token)) {
           globalVars = globalVars.concat(this.parseGlobalVariables());
         } else if (token.type === this.lexerClass.RK_FUNCTION) {
           functions = functions.concat(this.parseFunction());

+ 13 - 13
js/main.js

@@ -10,20 +10,20 @@ const lang = 'pt_br';
 const ivprogLexer = Lexers[lang];
 
 const input = `programa {
-        const inteiro a[1][1] = {
-            {
-              1,2,3
-            },
-            {
-              1,3
-            }
-        }
 
-        funcao inicio() {
-            retorna
-        }
-    }`;
-// let input2 = 'test = i\nb = i + 1\n';
+  const real PI = 5.5
+  inteiro V = -10*2
+
+  funcao inteiro test(real i) {
+    escolha (i) {
+      caso 1:
+        retorne 0
+      caso contrario:
+        retorne 4
+    }
+  }
+}`;
+
 // const lexer = new ivprogLexer(new InputStream(input));
 // const stream = new CommonTokenStream(lexer);
 // stream.fill();

+ 2 - 2
tests/test12.spec.js

@@ -11,7 +11,7 @@ describe('SwitchCase command', () => {
       escolha (i) {
         caso 1:
           retorne 0
-        casocontrario:
+        caso contrario:
           retorne 4
       }
     }`;
@@ -20,6 +20,6 @@ describe('SwitchCase command', () => {
     it(`should not result in SyntaxError`, () => {
         const as = new IVProgParser(input, lexer);
         const fun = as.parseFunction.bind(as);
-        expect(fun).not.toThrow(SyntaxError);
+        expect(fun).not.toThrow();
     });
 });

+ 2 - 2
tests/test13.spec.js

@@ -16,7 +16,7 @@ describe('A complete program code', () => {
         escolha (i) {
           caso 1:
             retorne 0
-          casocontrario:
+          caso contrario:
             retorne 4
         }
       }
@@ -26,6 +26,6 @@ describe('A complete program code', () => {
     it(`should not result in SyntaxError`, () => {
         const as = new IVProgParser(input, lexer);
         const fun = as.parseTree.bind(as);
-        expect(fun).not.toThrow(SyntaxError);
+        expect(fun).not.toThrow();
     });
 });

+ 1 - 1
tests/test14.spec.js

@@ -6,7 +6,7 @@ import {
     SyntaxError
 } from './../js/ast/SyntaxError';
 
-describe('For command', () => {
+describe('For with no \';\'', () => {
     let input = `funcao inteiro test(real i) {
       inteiro a = 5 + i
       a = 5 + G[i][6]