main.js 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {
  2. InputStream,
  3. CommonTokenStream
  4. } from 'antlr4/index';
  5. import { IVProgParser } from './ast/ivprogParser';
  6. import Lexers from '../grammar/';
  7. const lang = 'pt_br';
  8. const ivprogLexer = Lexers[lang];
  9. const input = `programa {
  10. const real PI = 5.5
  11. inteiro V = -10*2
  12. funcao inteiro test(real i) {
  13. escolha (i) {
  14. caso 1:
  15. i = i + 5
  16. retorne i
  17. caso contrario:
  18. i = i * 2 + 3
  19. retorne i
  20. }
  21. }
  22. }`;
  23. // const lexer = new ivprogLexer(new InputStream(input));
  24. // const stream = new CommonTokenStream(lexer);
  25. // stream.fill();
  26. // let i = 1;
  27. // let token = null;
  28. // while ((token = stream.LT(i)).type !== ivprogLexer.EOF && token.type !== ivprogLexer.WHITESPACE) {
  29. // console.log(`${token.type}-${token.text}`);
  30. // console.log('\n')
  31. // i++;
  32. // }
  33. const anaSin = new IVProgParser(input, ivprogLexer);
  34. try {
  35. const data = anaSin.parseTree();
  36. console.log(data);
  37. $('#json-renderer').jsonViewer(data);
  38. } catch(a) {
  39. console.log(a);
  40. }