[racket] Problem with macro
Hi all!
I want to create macro for creating a DFA automaton (similar to one described here: http://www.cs.brown.edu/~sk/Publications/Papers/Published/sk-automata-macros/paper.pdf )
My desire is that, for example, this form
(automaton init
(init : (c -> more))
(more : (a -> more)
(d -> more)
(r -> END)))
expands to:
(letrec ([curr-state empty]
[init
(lambda (symbol)
(case symbol
[(c) (set! curr-state more) 'ok]
[else 'transition-error]))]
[more
(lambda (symbol)
(case symbol
[(a) (set! curr-state more) 'ok]
[(d) (set! curr-state more) 'ok]
[(r) (set! curr-state END) 'endstate]
[else 'transition-error]))]
[END
(lambda (symbol)
'reading-past-end-error)])
(set! curr-state init)
(lambda (c)
(curr-state c))))
I've created the following two macros, but unfortunatelly they are wrong:
(define-syntax process-state
(syntax-rules (: -> END)
[(_ (label -> END))
[(label) (set! curr-state END) 'endstate]]
[(_ (label -> new-state))
[(label) (set! curr-state new-state) 'ok]]))
(define-syntax automaton
(syntax-rules (: -> END)
[(_ init-state
(state : transition ...)
...)
(letrec ([curr-state empty]
[state
(lambda (symbol)
(case symbol
[(process-state transition)]
...
[else 'transition-error]))]
...
[END
(lambda (symbol)
'reading-past-end-error)])
(set! curr-state init-state)
(lambda (c)
(curr-state c)))]))
Reported error is: case: bad syntax (missing expression after datum sequence) in: ((process-state (c -> more)))
It seems to me that macro process-state is not expanding at all.
Can somebody tell me what's wrong and how to fix it???
Thanks in advance,
Racket Noob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110811/38797899/attachment.html>