main.js 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. retorne 0
  16. caso contrario:
  17. retorne 4
  18. }
  19. }
  20. }`;
  21. // const lexer = new ivprogLexer(new InputStream(input));
  22. // const stream = new CommonTokenStream(lexer);
  23. // stream.fill();
  24. // let i = 1;
  25. // let token = null;
  26. // while ((token = stream.LT(i)).type !== ivprogLexer.EOF && token.type !== ivprogLexer.WHITESPACE) {
  27. // console.log(`${token.type}-${token.text}`);
  28. // console.log('\n')
  29. // i++;
  30. // }
  31. const anaSin = new IVProgParser(input, ivprogLexer);
  32. try {
  33. console.log(anaSin.parseTree());
  34. } catch(a) {
  35. console.log(a);
  36. }