runner.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. import { Location } from "./memory/location";
  7. export function runner () {
  8. const ivprogLexer = LanguageService.getCurrentLexer();
  9. // const lexer = new ivprogLexer(new InputStream(input));
  10. // const stream = new CommonTokenStream(lexer);
  11. // stream.fill();
  12. // let i = 1;
  13. // let token = null;
  14. // while ((token = stream.LT(i)).type !== ivprogLexer.EOF && token.type !== ivprogLexer.WHITESPACE) {
  15. // console.log(`${token.type}-${token.text}`);
  16. // console.log('\n')
  17. // i++;
  18. // }
  19. // const anaSin = new IVProgParser(input, ivprogLexer);
  20. const editor = new window.JsonEditor('#json-renderer', {});
  21. const domConsole = new DOMConsole("#console", true);
  22. domConsole.hide();
  23. // proc.interpretAST().then( sto => {
  24. // console.log(sto.applyStore('a'));
  25. // }).catch(e => console.log(e));
  26. try {
  27. window.$('#btn').click( () => {
  28. const input = window.$('#input').val();
  29. const analiser = new IVProgParser(input, ivprogLexer);
  30. try {
  31. const data = analiser.parseTree();
  32. const semAna = new SemanticAnalyser(data);
  33. const proc = new IVProgProcessor(semAna.analyseTree());
  34. proc.registerInput(domConsole);
  35. domConsole.clear();
  36. proc.registerOutput(domConsole);
  37. proc.interpretAST().then(sto => {
  38. console.log(sto);
  39. editor.load(sto.store);
  40. console.log(Location.size());
  41. }).catch( e => {
  42. alert(e);
  43. console.log(e);
  44. console.log(Location.size());
  45. });
  46. } catch (error) {
  47. alert(error);
  48. console.log(error);
  49. console.log(Location.size());
  50. }
  51. });
  52. } catch(a) {
  53. console.log(a);
  54. }
  55. }