main.js 679 B

1234567891011121314151617181920212223242526272829303132
  1. import { InputStream, CommonTokenStream } from 'antlr4/index';
  2. import Parsers from '../grammar/';
  3. const ivprogParser = Parsers['pt_br'];
  4. const input = `programa {
  5. const real PI = 0x25ff
  6. funcao inteiro casa(inteiro a, inteiro[][] b) {
  7. cadeia s = "teste"
  8. escreva(s)
  9. se (a <= 5) {
  10. a = 10;
  11. } senao se (a > 5 E a < 10) {
  12. a = 15
  13. } senao {
  14. a = 20
  15. }
  16. }
  17. }`;
  18. const lexer = new ivprogParser(new InputStream(input));
  19. const parser = new CommonTokenStream(lexer);
  20. parser.fill();
  21. let i = 1;
  22. let token = null;
  23. while((token = parser.LT(i)).type !== ivprogParser.EOF) {
  24. console.log(`${token.type}-${token.text}`);
  25. console.log('\n')
  26. i++;
  27. }