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.

I just got around to trying this out and wanted to confirm, it works like a charm. I.e. also the calculator demo you posted below (Tested in Ikarus) Thanks for investigating this Marco.

Ed

[1] <http://www.iro.umontreal.ca/~dube/>

As a usage example, put the following in  a file called
"calculator.l":

blanks          [ \n\t]+
decint          [0-9]+
binint          #[bB][01]+
octint          #[oO][0-7]+
hexint          #[xX][0-9A-Fa-f]+
integer         {decint}|{binint}|{octint}|{hexint}
exponent        ([eE][+\-]?[0-9]+)
truereal        [0-9]+\.|[0-9]*\.[0-9]+{exponent}?|[0-9]+{exponent}
real            {truereal}|{integer}
imag            ({decint}|{real})i
nan             \-nan\.0|\+nan\.0
inf             \-inf\.0|\+int\.0
initial         [a-zA-Z!$&:<=>?_~]
subsequent      {initial}|[0...@]
symbol          {initial}{subsequent}*
operator        [\+\-*/%\^\\]
comma           ,
oparen          \(
cparen          \)
paren           {oparen}|{cparen}
%%
{blanks}        ;; skip blanks, tabs and newlines
{imag}          (string->number (string-append "+" yytext))
{real}          (string->number yytext)
{nan}           (string->number yytext)
{inf}           (string->number yytext)
{operator}      (case (string-ref yytext 0)
                  ((#\+) +)
                  ((#\-) -)
                  ((#\*) *)
                  ((#\/) /)
                  ((#\%) mod)
                  ((#\^) expt))
{symbol}        (string->symbol yytext)
{comma}         (parse-comma)
{paren}         (string-ref yytext 0)
<<EOF>>             (parse-eof)

process it with the following program:

(import (rnrs)
  (silex))
(lex "calculator.l" "calculator.l.sls")

put the file "calculator.l.sls" into a Scheme program, with the
following tail:

(lexer-init 'string "1+23e-45+678.9e12*(4113+23i) / sin 545 + tan(1,
2)")
(define (parse-eof)
  #f)
(define (parse-comma)
  cons)
(do ((token (lexer) (lexer)))
    ((not token))
  (display token)
  (newline))

enjoy the output.
--
Marco Maggi


Reply via email to