test-lr-basics-02.scm 815 B

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