chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] packrat example


From: Thomas Hafner
Subject: [Chicken-users] packrat example
Date: 02 Dec 2006 09:54:03 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Hello,

is ther somebody who also wants to use the packrat egg? To get used to
it, I tried to copy a usage example from
http://www.lshift.net/~tonyg/packrat.pdf . Unfortunately when trying
to copy the text, just garbage text arrives (why?), so I had to type
it again. That's the result:

  (require-extension packrat)

  ;; from 5.2 "A base-generator for a higher-level input stream of 
lexemes/tokens
  (define (generator tokens)
    (let ((stream tokens))
      (lambda ()
        (if (null? stream)
            (values #f #f)
            (let ((base-token (car stream)))
              (set! stream (cdr stream))
              (values #f base-token))))))

  ;; from 5.3 "A simple calculator"
  (define calc
    (packrat-parser
     expr
     (expr ((a <- mulexp '+ b <- mulexp)
            (+ a b))
           ((a <- mulexp) a))
     (mulexp (( a <- simple '* b <- simple)
              (*a b))
             ((a <- simple) a))
     (simple ((a <- 'num) a)
             (('oparen a <- expr 'cparen) a))))

The example is not yet complete (missing: 5.4 An example calculator
session), but I think it should compile already. The issue is, that it
doesn't compile:

| $ csc ./try-packrat.scm
| Warning: literal in operator position: ((quote oparen) a <- expr (quote 
cparen))

Or if I apply the interpreter, I get:

| Version 2.5 - linux-unix-gnu-x86-64 - [ 64bit libffi dload ptables applyhook ]
| (c)2000-2006 Felix L. Winkelmann
| ; loading ./try-packrat.scm ...
| ; loading /usr/local/lib/chicken/1/packrat.so ...
| Error: unbound variable: expr
| 
|         Call history:
| 
|         <eval>          (##sys#require (quote packrat))
|         <eval>          (packrat-parser expr (expr ((a <- mulexp (quote +) b 
<- mulexp) (+ a b)) ((a <- mulexp) a)) (mulexp ((a <- simple (quote......       
<--

Any idea? Who else is using packrat?

Regards
  Thomas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]