This is the mail archive of the
guile@sources.redhat.com
mailing list for the Guile project.
Re: PHP fork project- Guile vs Python vs ?
- To: Mikael Djurfeldt <djurfeldt at nada dot kth dot se>
- Subject: Re: PHP fork project- Guile vs Python vs ?
- From: Ian Grant <Ian dot Grant at cl dot cam dot ac dot uk>
- Date: Mon, 10 Jul 2000 16:52:46 +0100
- cc: guile at sourceware dot cygnus dot com, Ian dot Grant at cl dot cam dot ac dot uk
Mikael said:
> ... I have previously rewritten the flex lexical
> analyzer to use tables provided from Scheme and started to do the same
> for Bison. There is, however, currently no one working on this. Any
> contribution in this area would be very good.
I would like to see the flex driver changes. I'm curious why you're did this
though. What does it get you? Don't you now need a special flex to generate
the scheme tables? What's wrong with using flex/bison as is? (Apart from the
problem that the C scanners generated by flex are not re-entrant.)
I have been playing around with embedding flex scanners and bison parsers into
guile modules. I have a module that implements an infix arithmetic parser.
The actions for each production all invoke a scheme function to obtain the
semantic value of that production. It reads from an arbitrary port so it can
plug in to the reader as a hash extension. Now I can write horrible things like
(define (func x y) #[x + y]) :-)
The action procedure turned out to be remarkably simple:
(lambda (x . rest)
(if (or (eq? x 'parenthesis)
(eq? x 'symbol)
(eq? x 'number))
(car rest)
(cons x rest)))
the bison input looks like this:
line : expr { ((struct parser_param *)yyparam)->retval = $1; YYACCEPT; }
expr EOEXP { ((struct parser_param *)yyparam)->retval = $1; YYACCEPT;
}
| error { YYABORT }
;
expr : expr '+' expr
{$$ = scm_apply(PARSER_PROC, SYMB("+"), LISTOF2($1, $3)); }
| expr '-' expr
{$$ = scm_apply(PARSER_PROC, SYMB("-"), LISTOF2($1, $3)); }
| expr '*' expr
{$$ = scm_apply(PARSER_PROC, SYMB("*"), LISTOF2($1, $3)); }
| expr '/' expr
{$$ = scm_apply(PARSER_PROC, SYMB("/"), LISTOF2($1, $3)); }
| expr '%' expr
{$$ = scm_apply(PARSER_PROC, SYMB("modulo"), LISTOF2($1, $3)); }
| expr '\\' expr
{$$ = scm_apply(PARSER_PROC, SYMB("quotient"), LISTOF2($1, $3)); }
| expr '^' expr
{$$ = scm_apply(PARSER_PROC, SYMB("expt"), LISTOF2($1, $3)); }
| '(' expr ')'
{$$ = scm_apply(PARSER_PROC, SYMB("parenthesis"), LISTOF1($2)); }
| SYMBOL '(' expr ')'
{$$ = scm_apply(PARSER_PROC, $1, LISTOF1($3)); }
| '-' expr %prec UMINUS
{$$ = scm_apply(PARSER_PROC, SYMB("-"), LISTOF1($2)); }
| NUMBER {$$ = scm_apply(PARSER_PROC, SYMB("number"), LISTOF1($1)); }
| SYMBOL {$$ = scm_apply(PARSER_PROC, SYMB("symbol"), LISTOF1($1)); }
Ian
--
Ian Grant, Computer Lab., New Museums Site, Pembroke Street, Cambridge
Phone: +44 1223 334420 Personal e-mail: iang at pobox dot com
--
Ian Grant, Computer Lab., New Museums Site, Pembroke Street, Cambridge
Phone: +44 1223 334420 Personal e-mail: iang at pobox dot com