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

From: Scott Owens (sowens at cs.utah.edu)
Date: Thu Oct 27 12:54:13 EDT 2005

Richard's post is accurate, but the problem doesn't actually have  
anything to do with lexers and parsers.  It instead has to do with  
the interaction between first-class functions and state.  This is  
important to understand in general, and so, since your new to Scheme,  
consider the following simple examples.  They capture the essence of  
what was wrong in the call to the parser.

 > (define f
     (lambda ()
       (read (open-input-string "1 2 3"))))
 > (f)
1
 > (f)
1
 > (define g
     (let ((i (open-input-string "1 2 3")))
       (lambda ()
         (read i))))
 > (g)
1
 > (g)
2
 >

-Scott



On Oct 27, 2005, at 8:56 AM, Richard Cobbe wrote:


> On Thu, Oct 27, 2005 at 03:37:50PM +0100, Dave Gurnell wrote:
>
>
>> 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"))))
>>
>>
>
> This same problem came up just last week on this list.  See
> <http://list.cs.brown.edu/pipermail/plt-scheme/2005-October/ 
> 010097.html>
> for my response; that fix should work for you too.
>
> Richard
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>




Posted on the users mailing list.