test-lr-basics-03.scm 696 B

12345678910111213141516171819202122232425262728293031323334353637
  1. ;;; test-lr-basics-03.scm --
  2. ;;
  3. ;;A grammar that accepts fixed sequences of a single terminal or the
  4. ;;EOI.
  5. (load "common-test.scm")
  6. (define (doit . tokens)
  7. (let ((parser (lalr-parser (expect: 0)
  8. (A)
  9. (e (A) : (list $1)
  10. (A A) : (list $1 $2)
  11. (A A A) : (list $1 $2 $3)
  12. () : 0))))
  13. (parser (make-lexer tokens) error-handler)))
  14. (check
  15. (doit (make-lexical-token 'A #f 1))
  16. => '(1))
  17. (check
  18. (doit (make-lexical-token 'A #f 1)
  19. (make-lexical-token 'A #f 2))
  20. => '(1 2))
  21. (check
  22. (doit (make-lexical-token 'A #f 1)
  23. (make-lexical-token 'A #f 2)
  24. (make-lexical-token 'A #f 3))
  25. => '(1 2 3))
  26. (check
  27. (doit)
  28. => 0)
  29. ;;; end of file