mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
Taken from r51 of <http://lalr-scm.googlecode.com/svn/trunk>. * module/Makefile.am (SYSTEM_BASE_SOURCES): Add `system/base/lalr.scm'. (NOCOMP_SOURCES): Add `system/base/lalr.upstream.scm'. * module/system/base/lalr.scm, module/system/base/lalr.upstream.scm: New files. * test-suite/Makefile.am (LALR_TESTS, LALR_EXTRA, TESTS, TESTS_ENVIRONMENT): New variables. (EXTRA_DIST): Add $(LALR_EXTRA). * test-suite/lalr/common-test.scm, test-suite/lalr/glr-test.scm, test-suite/lalr/test-glr-associativity.scm, test-suite/lalr/test-glr-basics-01.scm, test-suite/lalr/test-glr-basics-02.scm, test-suite/lalr/test-glr-basics-03.scm, test-suite/lalr/test-glr-basics-04.scm, test-suite/lalr/test-glr-basics-05.scm, test-suite/lalr/test-glr-script-expression.scm, test-suite/lalr/test-glr-single-expressions.scm, test-suite/lalr/test-lr-associativity-01.scm, test-suite/lalr/test-lr-associativity-02.scm, test-suite/lalr/test-lr-associativity-03.scm, test-suite/lalr/test-lr-associativity-04.scm, test-suite/lalr/test-lr-basics-01.scm, test-suite/lalr/test-lr-basics-02.scm, test-suite/lalr/test-lr-basics-03.scm, test-suite/lalr/test-lr-basics-04.scm, test-suite/lalr/test-lr-basics-05.scm, test-suite/lalr/test-lr-error-recovery-01.scm, test-suite/lalr/test-lr-error-recovery-02.scm, test-suite/lalr/test-lr-no-clause.scm, test-suite/lalr/test-lr-script-expression.scm, test-suite/lalr/test-lr-single-expressions.scm: New files.
35 lines
866 B
Scheme
35 lines
866 B
Scheme
;;; 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)
|
|
(driver: glr)
|
|
(A)
|
|
(e (A) : $1))))
|
|
(parser lexer error-handler)))
|
|
|
|
(check
|
|
(doit (make-lexical-token 'A #f 1))
|
|
=> '(1))
|
|
|
|
(check
|
|
(doit)
|
|
=> '())
|
|
|
|
(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.
|
|
(doit (make-lexical-token 'A #f 1)
|
|
(make-lexical-token 'A #f 2)
|
|
(make-lexical-token 'A #f 3))
|
|
=> '())
|
|
|
|
;;; end of file
|