Hi folks,
because of the long discussion about generating parsers in
this group I decided to offer my version of using BISON as
a front end for LISP parser generation. To be more concrete
than in the last posting you can write the following lines
and you will obtain a parser in LISP. The BISON file below
is the desktop calculater from the lex&yacc book, with
LISP semantic actions !!!
To get a first impression of the tool, you may notice the
usage of %left, %right, %nonassoc and %prec.
So if you want this, drop me mail !
Regards, Greg
%token NAME 3
%token NUMBER 4
%left '-' 5
%left '+' 6
%left '*' 7
%left '/' 8
%token '(' 9
%token ')' 10
%token '=' 11
%nonassoc UMINUS 12
%token '&' 13
%%
statement_list
: statement
| statement_list '&' statement
{/* (lambda (sl ig s) s) */}
statement
: NAME '=' expression
{/* (lambda (s ig e) (set-name s e) e) */}
| expression
{/* (lambda (e) e) */}
;
expression
: expression '+' expression
{/* (DEFSEM semact (e1 p e2) (funcall p e1 e2)) */}
| expression '-' expression
{/* (USESEM semact) */}
| expression '*' expression
{/* (USESEM semact) */}
| expression '/' expression
{/* (USESEM semact) */}
| '-' expression %prec UMINUS
{/* (lambda (m e1) (- e1)) */}
| '(' expression ')'
{/* (lambda (ig1 e ig2) e) */}
| NUMBER
| NAME
{/* (lambda (n) (get-val n)) */}
| NAME '(' expression ')'
{/* (lambda (f ig1 e ig2) (funcall f e)) */}
;
%%
/* AUXILLIARIES
(defparameter sym-tab nil)
(defun set-name (n val)
(setq sym-tab (acons n val sym-tab))
)
(defun get-val (n)
(cdr (assoc n sym-tab))
)
*/