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