blob: 0176fe689d8450a9aa3c72a8a74d352e7f64ab6f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
;;; test-lr-basics-01.scm --
;;
;;A grammar that only accept a single terminal as input. It refuses the
;;end-of-input as first token.
;;
(load "common-test.scm")
(define (doit . tokens)
(let* ((lexer (make-lexer tokens))
(parser (lalr-parser (expect: 0)
(A)
(e (A) : $1))))
(parser lexer error-handler)))
(check
(doit (make-lexical-token 'A #f 1))
=> 1)
(check
(let ((r (doit)))
(cons r *error*))
=> '(#f (error-handler "Syntax error: unexpected end of input")))
(check
;;Parse correctly the first A and reduce it. The second A triggers
;;an error which empties the stack and consumes all the input
;;tokens. Finally, an unexpected end-of-input error is returned
;;because EOI is invalid as first token after the start.
(let ((r (doit (make-lexical-token 'A #f 1)
(make-lexical-token 'A #f 2)
(make-lexical-token 'A #f 3))))
(cons r *error*))
=> '(#f
(error-handler "Syntax error: unexpected end of input")
(error-handler "Syntax error: unexpected token : " . A)))
;;; end of file
|