test-glr-basics-03.scm 727 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. (driver: glr)
  9. (A)
  10. (e (A) : (list $1)
  11. (A A) : (list $1 $2)
  12. (A A A) : (list $1 $2 $3)
  13. () : 0))))
  14. (parser (make-lexer tokens) error-handler)))
  15. (check
  16. (doit (make-lexical-token 'A #f 1))
  17. => '((1)))
  18. (check
  19. (doit (make-lexical-token 'A #f 1)
  20. (make-lexical-token 'A #f 2))
  21. => '((1 2)))
  22. (check
  23. (doit (make-lexical-token 'A #f 1)
  24. (make-lexical-token 'A #f 2)
  25. (make-lexical-token 'A #f 3))
  26. => '((1 2 3)))
  27. (check
  28. (doit)
  29. => '(0))
  30. ;;; end of file