[plt-scheme] Parser-tools problem: "Cannot continue after error"

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Thu Oct 27 10:37:50 EDT 2005

Dear Schemers,

I'm trying to create a simple parser for a custom language using the
PLT parser-tools library. I have done equivalent things in Java
before, but I am new to Scheme and this is my first Scheme based
parseresque thing.

I've distilled my problem down to a fairly small test case, which is
supposed to recognise the strings "abc" and "def":

----- START test_parser.scm -----
(require (lib "lex.ss" "parser-tools")
         (lib "yacc.ss" "parser-tools"))

(define-tokens my-tokens (ABC DEF EOF))

(define-lex-abbrevs
  [abc "abc"]
  [def "def"])

(define my-lexer
  (lexer [(eof) (token-EOF #f)]
         [abc (token-ABC "it's ABC")]
         [def (token-DEF "it's DEF")]))

(define my-parser
  (parser (start start)
          (end EOF)
          (debug "test.txt")
          (tokens my-tokens)
          (error (lambda (a b c) (write (list "error" a b c)) (newline)))
          (grammar
           [start
            ((ABC) (token-value $1))
            ((DEF) (token-value $1))])))

(my-parser (lambda () (my-lexer (open-input-string "abc"))))
----- END test_parser.scm -----

Running this file from DrScheme produces the folowing output:

("error" #t ABC "it's ABC")
(#<struct:stack-frame> #<struct:stack-frame>)
[BUG_ICON] parser: Cannot continue after error

and fills "test.txt" with dump information appended to the end of this
email. Unfortunately I don't really understand what is going on and I
lack the Scheme debugging skills to work it out for myself.

When run separately, the lexer seems to work as expected: the first
call to my-lexer produces token-ABC and repeated calls produce
token-EOF.

Does anyone have any potentially useful advice?

Many thanks,

-- Dave

----- START test.txt -----
0	g457	=	(g458)
1	g458	=	(start EOF)
2	start	=	(ABC)
3	start	=	(DEF)
State 0
	g457 -> . g458

	g458					goto	1
	ABC					shift	3
	start					goto	2
	DEF					shift	4

State 1
	g457 -> g458 .


State 2
	g458 -> start . EOF

	EOF					accept	

State 3
	start -> ABC .

	EOF					reduce	2

State 4
	start -> DEF .

	EOF					reduce	3

State 5
	g458 -> start EOF .


----- END test.txt -----


Posted on the users mailing list.