marcomaggi wrote:

FWIW I started repackaging SILex[1] by Danny Dube' into Nausicaa.
To make it work with R6RS I had to change almost nothing, I only
wrapped the file "silex.scm" into a LIBRARY form with the following
incipit:

(library (silex)
  (export lex lex-tables)
  (import (rnrs)
    (rnrs mutable-pairs)
    (rnrs mutable-strings)
    (rnrs r5rs))

and commented out the internal implementation of
STRING-DOWNCASE.

Eduardo Cavazos wrote:

I just got around to trying this out and wanted to confirm, it works like a charm.

For those of y'all who aren't sure what 'silex' is for, here's how I'm using it.

I have an R6RS program called 'generate-tokenizer':

(import (rnrs)
        (dharmatech silex silex))

(lex-lib "calculator.l"
         "tokenizer.sls"
         '(numero symbolic tokenizer))

It imports my hacked up version of silex. The stock silex provides a 'lex' procedure. Mine provides 'lex-lib' which basically wraps the generated file in a library form.

The input file "calculator.l" is similar to the one Marco shared.

Let's mess around with that generated library:

> (import (numero symbolic tokenizer))
> (lexer-init 'string "a+b")
> (lexer)
a
> (lexer)
+
> (lexer)
b
> (lexer)
#f
>

So it basically splits up the string into tokens.

I wired this up to my 'infix' procedure. Here's some examples:

> (import (numero symbolic alg))
> (alg "a+b")
(+ a b)
> (alg "1+2*3/4")
(+ 1 (/ (* 2 3) 4))
> (alg "f(x)")
(f x)
> (alg "f(x,y,z)")
(f x y z)
> (alg "f(g(x))")
(f (g x))
> (alg "sin(x) + cos(x)^2")
(+ (sin x) (^ (cos x) 2))

Ed

Reply via email to