test-lr-single-expressions.scm 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. (N O C (left: A) (left: M) (nonassoc: U))
  9. (E (N) : $1
  10. (E A E) : ($2 $1 $3)
  11. (E M E) : ($2 $1 $3)
  12. (A E (prec: U)) : ($1 $2)
  13. (O E C) : $2))))
  14. (parser (make-lexer tokens) error-handler)))
  15. ;;; --------------------------------------------------------------------
  16. (check ;correct input
  17. (doit (make-lexical-token 'N #f 1))
  18. => 1)
  19. (check ;correct input
  20. (doit (make-lexical-token 'A #f -)
  21. (make-lexical-token 'N #f 1))
  22. => -1)
  23. (check ;correct input
  24. (doit (make-lexical-token 'A #f +)
  25. (make-lexical-token 'N #f 1))
  26. => 1)
  27. (check ;correct input
  28. (doit (make-lexical-token 'N #f 1)
  29. (make-lexical-token 'A #f +)
  30. (make-lexical-token 'N #f 2))
  31. => 3)
  32. (check ;correct input
  33. (doit (make-lexical-token 'N #f 1)
  34. (make-lexical-token 'A #f +)
  35. (make-lexical-token 'N #f 2)
  36. (make-lexical-token 'M #f *)
  37. (make-lexical-token 'N #f 3))
  38. => 7)
  39. (check ;correct input
  40. (doit (make-lexical-token 'O #f #\()
  41. (make-lexical-token 'N #f 1)
  42. (make-lexical-token 'A #f +)
  43. (make-lexical-token 'N #f 2)
  44. (make-lexical-token 'C #f #\))
  45. (make-lexical-token 'M #f *)
  46. (make-lexical-token 'N #f 3))
  47. => 9)
  48. ;;; end of file