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

Re: [plt-scheme] lex and yacc rules for scheme

> i am writing a compiler for a language for programming distributed
> embedded systems. the syntax of the language is similar to that of
> scheme. i am looking for the (lex/yacc) rules written for scheme.

If you're using Scheme to parse a language with Scheme-like syntax, you
may be able to use the Scheme reader to scan the input language into
nested lists (a simple abstract syntax tree), and then recurse over the
lists for syntax-directed translation to your target code.

Alternatively, you may be able to define your language within Scheme, in
terms of Scheme procedures and/or macros.  When evaluated, those
procedures and macros could produce the intermediate and target code for
your embedded system.  (You can also have definitions in the
mini-language map to definitions within Scheme environment, though that
might not be helpful for your current problem.)  Macros would reduce the
need to quote things.  For illustration purposes, here's a simple
example without macros:

    (define (program    asm-filename . forms)    ...)
    (define (variable   name type default-value) ...)  ; -> variable-rec
    (define (subroutine name actuals . body)     ...)  ; -> subroutine-rec
    (program "robot-control.asm"
        (variable 'motor-speed integer 0)
        (variable 'berzerk     boolean false)
        (subroutine 'seek-and-destroy '(target speed pain)
            '(scan ...)
            '(move ...)

>From a purely pragmatic point of view, for writing a compiler that is
implemented in Scheme only incidentally, I would probably start with the
first suggestion (i.e., Scheme reader only), but keep the second
suggestion in mind.

                                                        Neil W. Van Dyke