test-glr-single-expressions.scm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ;;; test-lr-single-expressions.scm --
  2. ;;
  3. ;;Grammar accepting single expressions.
  4. ;;
  5. (load "common-test.scm")
  6. (define (doit . tokens)
  7. (let ((parser (lalr-parser (expect: 0)
  8. (driver: glr)
  9. (N O C (left: A) (left: M) (nonassoc: U))
  10. (E (N) : $1
  11. (E A E) : ($2 $1 $3)
  12. (E M E) : ($2 $1 $3)
  13. (A E (prec: U)) : ($1 $2)
  14. (O E C) : $2))))
  15. (parser (make-lexer tokens) error-handler)))
  16. ;;; --------------------------------------------------------------------
  17. (check ;correct input
  18. (doit (make-lexical-token 'N #f 1))
  19. => '(1))
  20. (check ;correct input
  21. (doit (make-lexical-token 'A #f -)
  22. (make-lexical-token 'N #f 1))
  23. => '(-1))
  24. (check ;correct input
  25. (doit (make-lexical-token 'A #f +)
  26. (make-lexical-token 'N #f 1))
  27. => '(1))
  28. (check ;correct input
  29. (doit (make-lexical-token 'N #f 1)
  30. (make-lexical-token 'A #f +)
  31. (make-lexical-token 'N #f 2))
  32. => '(3))
  33. (check ;correct input
  34. (doit (make-lexical-token 'N #f 1)
  35. (make-lexical-token 'A #f +)
  36. (make-lexical-token 'N #f 2)
  37. (make-lexical-token 'M #f *)
  38. (make-lexical-token 'N #f 3))
  39. => '(9 7))
  40. (check ;correct input
  41. (doit (make-lexical-token 'O #f #\()
  42. (make-lexical-token 'N #f 1)
  43. (make-lexical-token 'A #f +)
  44. (make-lexical-token 'N #f 2)
  45. (make-lexical-token 'C #f #\))
  46. (make-lexical-token 'M #f *)
  47. (make-lexical-token 'N #f 3))
  48. => '(9))
  49. ;;; end of file