test-glr-basics-04.scm 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ;;; test-lr-basics-04.scm --
  2. ;;
  3. ;;A grammar accepting a sequence of equal tokens of arbitrary length.
  4. ;;The return value is the value of the last parsed token.
  5. (load "common-test.scm")
  6. (define (doit . tokens)
  7. (let ((parser (lalr-parser (expect: 0)
  8. (driver: glr)
  9. (A)
  10. (e (e A) : $2
  11. (A) : $1
  12. () : 0))))
  13. (parser (make-lexer tokens) error-handler)))
  14. (check
  15. (doit)
  16. => '(0))
  17. (check
  18. ;;Two results because there is a shift/reduce conflict, so two
  19. ;;processes are generated.
  20. (doit (make-lexical-token 'A #f 1))
  21. => '(1 1))
  22. (check
  23. ;;Two results because there is a shift/reduce conflict, so two
  24. ;;processes are generated. Notice that the rules:
  25. ;;
  26. ;; (e A) (A)
  27. ;;
  28. ;;generate only one conflict when the second "A" comes. The third
  29. ;;"A" comes when the state is inside the rule "(e A)", so there is
  30. ;;no conflict.
  31. ;;
  32. (doit (make-lexical-token 'A #f 1)
  33. (make-lexical-token 'A #f 2)
  34. (make-lexical-token 'A #f 3))
  35. => '(3 3))
  36. ;;; end of file