1
0
Преглед на файлове

Implement syntatic analysis for the new keywords

Implement new semantics of the do until command
Lucas de Souza преди 5 години
родител
ревизия
acfd95cd11
променени са 5 файла, в които са добавени 21 реда и са изтрити 21 реда
  1. 1 1
      js/ast/commands/doWhile.js
  2. 2 2
      js/ast/commands/index.js
  3. 8 8
      js/ast/ivprogParser.js
  4. 4 4
      js/processor/ivprogProcessor.js
  5. 6 6
      js/util/editorMode2.js

+ 1 - 1
js/ast/commands/doWhile.js

@@ -1,6 +1,6 @@
 import { While } from './while';
 
-export class DoWhile extends While {
+export class DoUntil extends While {
 
   constructor(condition, commandBlock) {
     super(condition, commandBlock);

+ 2 - 2
js/ast/commands/index.js

@@ -9,7 +9,7 @@ import { For } from './for';
 import { Function } from './function';
 import { IfThenElse } from './ifThenElse';
 import { CommandBlock } from './commandBlock';
-import { DoWhile } from './doWhile';
+import { DoUntil } from './doUntil';
 import { Switch } from './switch';
 import { Case } from './case';
 import { SysCall } from './sysCall';
@@ -28,7 +28,7 @@ export {
   Function,
   IfThenElse,
   CommandBlock,
-  DoWhile,
+  DoUntil,
   Switch,
   Case,
   SysCall,

+ 8 - 8
js/ast/ivprogParser.js

@@ -781,9 +781,9 @@ export class IVProgParser {
       return this.parseIDCommand();
     } else if (token.type === this.lexerClass.RK_RETURN) {
       return this.parseReturn();
-    } else if (token.type === this.lexerClass.RK_WHILE) {
+    } else if (token.type === this.lexerClass.RK_WHILE || token.type === this.lexerClass.RK_WHILE_ALT) {
       return this.parseWhile();
-    } else if (token.type === this.lexerClass.RK_FOR) {
+    } else if (token.type === this.lexerClass.RK_FOR || token.type === this.lexerClass.RK_FOR_ALT) {
       return this.parseFor();
     } else if (token.type === this.lexerClass.RK_BREAK ) {
       if(!this.insideScope(IVProgParser.BREAKABLE)) {
@@ -796,7 +796,7 @@ export class IVProgParser {
     } else if (token.type === this.lexerClass.RK_SWITCH) {
       return this.parseSwitchCase();
     } else if (token.type === this.lexerClass.RK_DO) {
-      return this.parseDoWhile();
+      return this.parseDoUntil();
     } else if (token.type === this.lexerClass.RK_IF) {
       return this.parseIfThenElse();
     } else if (this.checkEOS(true)){
@@ -831,15 +831,15 @@ export class IVProgParser {
     return new Commands.Switch(exp, casesList);
   }
 
-  parseDoWhile () {
+  parseDoUntil () {
     this.pos++;
     this.consumeNewLines();
     this.pushScope(IVProgParser.BREAKABLE);
     const commandsBlock = this.parseCommandBlock();
     this.consumeNewLines(); //Maybe not...
     const whileToken = this.getToken();
-    if (whileToken.type !== this.lexerClass.RK_WHILE) {
-      throw SyntaxErrorFactory.token_missing_one(this.lexer.literalNames[this.lexerClass.RK_WHILE], whileToken);
+    if (whileToken.type !== this.lexerClass.RK_DO_UNTIL) {
+      throw SyntaxErrorFactory.token_missing_one(this.lexer.literalNames[this.lexerClass.RK_DO_UNTIL], whileToken);
     }
     this.pos++;
     this.checkOpenParenthesis();
@@ -851,7 +851,7 @@ export class IVProgParser {
     this.pos++;
     this.checkEOS();
     this.popScope();
-    return new Commands.DoWhile(condition, commandsBlock);
+    return new Commands.DoUntil(condition, commandsBlock);
   }
 
   parseIfThenElse () {
@@ -909,7 +909,7 @@ export class IVProgParser {
     // END parse ID
     const for_from = this.parseForParameters(this.lexerClass.RK_FOR_FROM);
     const for_to = this.parseForParameters(this.lexerClass.RK_FOR_TO);
-    let maybePass = this.parseForParameters(this.lexerClass.RK_FOR_PASS);
+    const maybePass = this.parseForParameters(this.lexerClass.RK_FOR_PASS);
     this.consumeNewLines();
     const commandsBlock = this.parseCommandBlock();
     this.popScope();

+ 4 - 4
js/processor/ivprogProcessor.js

@@ -234,8 +234,8 @@ export class IVProgProcessor {
       return this.executeReturn(store, cmd);
     } else if (cmd instanceof Commands.IfThenElse) {
       return this.executeIfThenElse(store, cmd);
-    } else if (cmd instanceof Commands.DoWhile) {
-      return this.executeDoWhile(store, cmd);
+    } else if (cmd instanceof Commands.DoUntil) {
+      return this.executeDoUntil(store, cmd);
     } else if (cmd instanceof Commands.While) {
       return this.executeWhile(store, cmd);
     } else if (cmd instanceof Commands.For) {
@@ -350,7 +350,7 @@ export class IVProgProcessor {
     }).catch(error => Promise.reject(error));
   }
 
-  executeDoWhile (store, cmd) {
+  executeDoUntil (store, cmd) {
     try {
       this.loopTimers.push(Date.now());
       this.context.push(Context.BREAKABLE);
@@ -367,7 +367,7 @@ export class IVProgProcessor {
           if (!vl.type.isCompatible(Types.BOOLEAN)) {
             return Promise.reject(ProcessorErrorFactory.loop_condition_type_full(cmd.sourceInfo));
           }
-          if (vl.get()) {
+          if (!vl.get()) {
             this.context.pop();
             if(this.loopTimers.length > 0) {
               const time = this.loopTimers[0];

+ 6 - 6
js/util/editorMode2.js

@@ -1,5 +1,11 @@
 import { getCodeEditorModeConfig } from "./utils";
 
+/**
+ * Source: https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/clike/clike.js
+ * @author arijn Haverbeke and others
+ * @author Lucas de Souza
+ * @param {CodeMirror} CodeMirror 
+ */
 export function CodeEditorMode (CodeMirror) {
   "use strict";
 
@@ -270,14 +276,8 @@ export function CodeEditorMode (CodeMirror) {
 
   const ivprogKeywords =  codeConfig.keywords.join(" ");
 
-  // Do not use this. Use the cTypes function below. This is global just to avoid
-  // excessive calls when cTypes is being called multiple times during a parse.
   const basicTypes = words(codeConfig.types.join(" "));
 
-  // Returns true if identifier is a "C" type.
-  // C type is defined as those that are reserved by the compiler (basicTypes),
-  // and those that end in _t (Reserved by POSIX for types)
-  // http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html
   function ivprogTypes(identifier) {
     return contains(basicTypes, identifier);
   }