1
0

runner.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { IVProgParser } from './ast/ivprogParser';
  2. import { IVProgProcessor } from './processor/ivprogProcessor';
  3. import {DOMConsole} from './io/domConsole';
  4. import { LanguageService } from './services/languageService';
  5. import { SemanticAnalyser } from './processor/semantic/semanticAnalyser';
  6. export function runner () {
  7. const ivprogLexer = LanguageService.getCurrentLexer();
  8. // const lexer = new ivprogLexer(new InputStream(input));
  9. // const stream = new CommonTokenStream(lexer);
  10. // stream.fill();
  11. // let i = 1;
  12. // let token = null;
  13. // while ((token = stream.LT(i)).type !== ivprogLexer.EOF && token.type !== ivprogLexer.WHITESPACE) {
  14. // console.log(`${token.type}-${token.text}`);
  15. // console.log('\n')
  16. // i++;
  17. // }
  18. // const anaSin = new IVProgParser(input, ivprogLexer);
  19. const editor = new JsonEditor('#json-renderer', {});
  20. const domConsole = new DOMConsole("#console");
  21. // proc.interpretAST().then( sto => {
  22. // console.log(sto.applyStore('a'));
  23. // }).catch(e => console.log(e));
  24. try {
  25. $('#btn').click( () => {
  26. const input = $('#input').val();
  27. const analiser = new IVProgParser(input, ivprogLexer);
  28. try {
  29. const data = analiser.parseTree();
  30. const semAna = new SemanticAnalyser(data);
  31. const proc = new IVProgProcessor(semAna.analyseTree());
  32. proc.registerInput(domConsole);
  33. domConsole.clear();
  34. proc.registerOutput(domConsole);
  35. proc.interpretAST().then(sto => editor.load(sto.store))
  36. .catch( e => {alert(e); console.log(e)});
  37. } catch (error) {
  38. alert(error);
  39. console.log(error);
  40. }
  41. });
  42. } catch(a) {
  43. console.log(a);
  44. }
  45. }