test-lr-basics-01.scm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. (A)
  11. (e (A) : $1))))
  12. (parser lexer error-handler)))
  13. (check
  14. (doit (make-lexical-token 'A #f 1))
  15. => 1)
  16. (check
  17. (let ((r (doit)))
  18. (cons r *error*))
  19. => '(#f (error-handler "Syntax error: unexpected end of input")))
  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. (let ((r (doit (make-lexical-token 'A #f 1)
  26. (make-lexical-token 'A #f 2)
  27. (make-lexical-token 'A #f 3))))
  28. (cons r *error*))
  29. => '(#f
  30. (error-handler "Syntax error: unexpected end of input")
  31. (error-handler "Syntax error: unexpected token : " . A)))
  32. ;;; end of file