test-glr-basics-01.scm 866 B

123456789101112131415161718192021222324252627282930313233343536
  1. ;;; test-lr-basics-01.scm --
  2. ;;
  3. ;;A grammar that only accept a single terminal as input. It refuses the
  4. ;;end-of-input as first token.
  5. ;;
  6. (load "common-test.scm")
  7. (define (doit . tokens)
  8. (let* ((lexer (make-lexer tokens))
  9. (parser (lalr-parser (expect: 0)
  10. (driver: glr)
  11. (A)
  12. (e (A) : $1))))
  13. (parser lexer error-handler)))
  14. (check
  15. (doit (make-lexical-token 'A #f 1))
  16. => '(1))
  17. (check
  18. (doit)
  19. => '())
  20. (check
  21. ;;Parse correctly the first A and reduce it. The second A triggers
  22. ;;an error which empties the stack and consumes all the input
  23. ;;tokens. Finally, an unexpected end-of-input error is returned
  24. ;;because EOI is invalid as first token after the start.
  25. (doit (make-lexical-token 'A #f 1)
  26. (make-lexical-token 'A #f 2)
  27. (make-lexical-token 'A #f 3))
  28. => '())
  29. ;;; end of file