1
0

runner.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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", true);
  21. domConsole.hide();
  22. // proc.interpretAST().then( sto => {
  23. // console.log(sto.applyStore('a'));
  24. // }).catch(e => console.log(e));
  25. try {
  26. $('#btn').click( () => {
  27. const input = $('#input').val();
  28. const analiser = new IVProgParser(input, ivprogLexer);
  29. try {
  30. const data = analiser.parseTree();
  31. const semAna = new SemanticAnalyser(data);
  32. const proc = new IVProgProcessor(semAna.analyseTree());
  33. proc.registerInput(domConsole);
  34. domConsole.clear();
  35. proc.registerOutput(domConsole);
  36. proc.interpretAST().then(sto => editor.load(sto.store))
  37. .catch( e => {alert(e); console.log(e)});
  38. } catch (error) {
  39. alert(error);
  40. console.log(error);
  41. }
  42. });
  43. } catch(a) {
  44. console.log(a);
  45. }
  46. }