[racket] Survey of parsing libraries for Racket?
That's very cool, Danny!
(BTW, what was that other language you did-- brain something? It was
excellent. ;)
Robby
On Mon, Mar 12, 2012 at 2:58 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
>> Incidentally, I'm not sure of the performance implications, but I like the
>> idea of having the parser for a programming language translate the syntax
>> objects to sexp-like syntax objects promptly, and then "syntax-parse" the
>> heck out of that newly sexp-encoded language to turn it into Racket code.
>
>
> That's just crazy talk.
>
> It's completely unreasonable to expect something like this, to have a
> file called "calc.rkt"
>
> ;; calc.rkt ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang planet dyoo/autogrammar/lalr
> expr : term ('+' term)*
> term : factor ('*' factor)*
> factor : INT
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> and expect to be able to use that as a language:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang racket/base
> (require "calc.rkt"
> parser-tools/lex
> (prefix-in : parser-tools/lex-sre))
>
> (define lex/1
> (lexer-src-pos [(:+ numeric) (token-INT lexeme)]
> ["*" (token-* lexeme)]
> ["+" (token-+ lexeme)]
> [whitespace (return-without-pos (lex/1 input-port))]
> [(eof) (token-EOF eof)]))
>
> (define (tokenize ip)
> (port-count-lines! ip)
> (lambda () (lex/1 ip)))
>
> (parse "a-sample-program"
> (tokenize (open-input-string "3 * 4 + 5 * 6")))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> and just have it work and produce syntax objects.
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users