Procházet zdrojové kódy

Implement semantic analyser helper function

Lucas de Souza před 5 roky
rodič
revize
c486f6e4ab

+ 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();