test-lr-basics-05.scm 698 B

12345678910111213141516171819202122232425262728293031323334353637
  1. ;;; test-lr-basics-05.scm --
  2. ;;
  3. ;;A grammar accepting a sequence of equal tokens of arbitrary length.
  4. ;;The return value is the list of values.
  5. ;;
  6. (load "common-test.scm")
  7. (define (doit . tokens)
  8. (let ((parser (lalr-parser (expect: 0)
  9. (A)
  10. (e (e A) : (cons $2 $1)
  11. (A) : (list $1)
  12. () : 0))))
  13. (parser (make-lexer tokens) error-handler)))
  14. (check
  15. (doit)
  16. => 0)
  17. (check
  18. (doit (make-lexical-token 'A #f 1))
  19. => '(1))
  20. (check
  21. (doit (make-lexical-token 'A #f 1)
  22. (make-lexical-token 'A #f 2))
  23. => '(2 1))
  24. (check
  25. (doit (make-lexical-token 'A #f 1)
  26. (make-lexical-token 'A #f 2)
  27. (make-lexical-token 'A #f 3))
  28. => '(3 2 1))
  29. ;;; end of file