"Eduardo Cavazos" wrote:
>marcomaggi wrote:
>
>> I do not want to press Eduardo, but maybe someone can try
>> to port the following to R6RS Scheme:
>>
>> <http://code.google.com/p/lalr-scm/>
>
>That one looks good. Another one is 'essence':
>
> http://www.informatik.uni-freiburg.de/proglang/software/essence
>
> Essence itself only runs on Scheme48, but the
> documentation says it can generate parsers for R5RS. The
> interface also has an option for generating R6RS code.
BTW, I did an initial port or lalr-scm: It seems to work and
it is amazing how small it is the library holding the parser
driver itself. I still have to port the documentation from
the original HTML, I will probably post links into the
Nausicaa repository in a few days. If there is request, I
can prepare a small distribution of (silex) and (lalr)
outside of Nausicaa, just the sources ready to go.
One problem that needs to be solved is how to access
parser and lexer specific state when loading the
parser/lexer from a library. So far, the easy solution I
can think of is to use parameters; so I do:
(library (calc-parser-helper)
(export table-of-variables)
(import (rnrs) (parameters))
(define table-of-variables
(make-parameter #f)))
then I create the generic parser library:
(library (calc-parser)
(export calc-parser)
(import (rnrs)
(lalr lr-driver)
(calc-parser-helper))
;; access the "table-of-variables" parameter here
)
then I run an instance of the parser:
(import (nausicaa)
(silex lexer)
(calc-parser)
(calc-parser-helper)
(calc-parser-lexer))
(define (doit string)
(let* ((IS (lexer-make-IS :string string
:counters 'all))
(lexer (lexer-make-lexer
calc-parser-lexer-table IS))
(error-handler (lambda (message token)
---)
(calc-parser lexer error-handler)))
(parameterise ((table-of-variables (make-eq-hashtable)))
(doit "1 + 2 + 4 * 3
a = 2
a * 3
"))
It is absolutely mandatory to have a parser specific
state, else there is neither a way to return a result from
the parsing operation, nor a way to hand to the parser a
continuation to jump in and out.
I like parameters, but I am not crazy about the need to
create a library for them (the calc-parser-helper of the
example). But that is the way it is. I am open to
suggestions, though.
P.S.
I will take look a look at Essence, too.
--
Marco Maggi