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

Implement semantic analyser helper function

Lucas de Souza преди 5 години
родител
ревизия
c486f6e4ab
променени са 2 файла, в които са добавени 8 реда и са изтрити 4 реда
  1. 1 4
      js/assessment/ivprogAssessment.js
  2. 7 0
      js/processor/semantic/semanticAnalyser.js

+ 1 - 4
js/assessment/ivprogAssessment.js

@@ -24,10 +24,7 @@ export class IVProgAssessment {
 
   runTest () {
     try {
-      // try and show error messages through domconsole
-      const parser = IVProgParser.createParser(this.textCode);
-      const semantic = new SemanticAnalyser(parser.parseTree());
-      const validTree = semantic.analyseTree();
+      const validTree = SemanticAnalyser.analyseFromSource(this.textCode);
       // loop test cases and show messages through domconsole
       const partialTests = this.testCases.map( (t, name) => {
         return this.partialEvaluateTestCase(new IVProgProcessor(validTree), t.input, t.output, name);

+ 7 - 0
js/processor/semantic/semanticAnalyser.js

@@ -10,9 +10,16 @@ import { CompoundType } from '../../typeSystem/compoundType';
 import { MultiType } from '../../typeSystem/multiType';
 import { Config } from '../../util/config';
 import { Store } from '../store/store';
+import { IVProgParser } from '../../ast/ivprogParser';
 
 export class SemanticAnalyser {
 
+  static analyseFromSource (stringCode) {
+    const parser = IVProgParser.createParser(stringCode);
+    const semantic = new SemanticAnalyser(parser.parseTree());
+    return semantic.analyseTree();
+  }
+
   constructor(ast) {
     this.ast = ast;
     this.lexerClass = LanguageService.getCurrentLexer();