main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {
  2. InputStream,
  3. CommonTokenStream
  4. } from 'antlr4/index';
  5. import * as Commands from './ast/commands';
  6. import { IVProgParser } from './ast/ivprogParser';
  7. import Lexers from '../grammar/';
  8. import { IVProgProcessor } from './processor/ivprogProcessor';
  9. import {DOMInput} from './io/domInput';
  10. import {DOMOutput} from './io/domOutput';
  11. const lang = 'pt_br';
  12. const ivprogLexer = Lexers[lang];
  13. const input = `programa {
  14. funcao inicio() {
  15. inteiro a[2] = {1,2}
  16. }
  17. }`;
  18. // const lexer = new ivprogLexer(new InputStream(input));
  19. // const stream = new CommonTokenStream(lexer);
  20. // stream.fill();
  21. // let i = 1;
  22. // let token = null;
  23. // while ((token = stream.LT(i)).type !== ivprogLexer.EOF && token.type !== ivprogLexer.WHITESPACE) {
  24. // console.log(`${token.type}-${token.text}`);
  25. // console.log('\n')
  26. // i++;
  27. // }
  28. // const anaSin = new IVProgParser(input, ivprogLexer);
  29. const editor = new JsonEditor('#json-renderer', {});
  30. const domIn = new DOMInput('#dom-in');
  31. const domOut = new DOMOutput('#dom-out');
  32. // proc.interpretAST().then( sto => {
  33. // console.log(sto.applyStore('a'));
  34. // }).catch(e => console.log(e));
  35. try {
  36. $('#btn').click( () => {
  37. const input = $('#input').val();
  38. const analiser = new IVProgParser(input, ivprogLexer);
  39. try {
  40. const data = analiser.parseTree();
  41. const proc = new IVProgProcessor(data);
  42. proc.registerInput(domIn);
  43. domOut.clear();
  44. proc.registerOutput(domOut);
  45. proc.interpretAST().then(sto => editor.load(sto.store))
  46. .catch( e => alert(e));
  47. } catch (error) {
  48. alert(error);
  49. }
  50. });
  51. } catch(a) {
  52. console.log(a);
  53. }