runner.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 => {editor.load(sto.store);console.log(Location.size());})
  38. .catch( e => {alert(e); console.log(e);console.log(Location.size());});
  39. } catch (error) {
  40. alert(error);
  41. console.log(error);
  42. console.log(Location.size());
  43. }
  44. });
  45. } catch(a) {
  46. console.log(a);
  47. }
  48. }