[racket] parser-tools help
Hi Marijn,
Two quick points:
(1) The parser works with token structs, not symbols. Whenever you declare
a token, a cooresponding "token-<name>" form is made available to you when
using lexer.
You can find two examples of all this in your
Racket\collects\parser-tools\examples folder. To see the process, try this
in interactions:
(define pt (open-input-string input))
(turn0-lexer pt)
(turn0-lexer pt)
and so on. If you want the turn token to contain the number that follows,
you'll need to change the regexp that matches the token to include the
number in the lexeme.
(2) Parsers expect a nullary function that invokes the lexer on a port, so
you need a small modification:
(define (main port)
(write (turn0-parser (lambda () (turn0-lexer port)))))
If you instead write
(define (main port)
(write (turn0-parser (turn0-lexer port))))
the parser is passed the first token itself, not a thunk it can call to get
successive tokens, which is what it wants.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111130/ed408f32/attachment.html>