From: Barry Margolin
Subject: Re: Lisp grammars
Date: 
Message-ID: <2mifo5INN16j@early-bird.think.com>
In article <··········@news.Hawaii.Edu> ·······@Hawaii.Edu (Jeremy T. Harrison) writes:
>I am looking for a lisp grammar (BNF form if possible).  It need not 
>comprehensive, a simple subset will do.  Do any of you know where I
>can pick up such a beast?  I appreciate any assistance which can be
>offered.  I am looking for either an ftp site, or the title of a 
>book wherein I can find such a thing.

The BNF for Lisp is extremely simple.  Below is a Bison parser for a Lisp
subset.  The complicated stuff isn't here -- it's in the lexer.  You can
download our entire Lisp subset parsing software from ftp.think.com in
users/taylor/lisp-parser.tar.gz.

/*
 * Grammar for yacc/bison to describe lisp syntax
 */

%{
#include "lisp.h"
/*#define bu_symbol bu_string	/* should eventually have its own type... */
/*#define YYSTYPE lispobj_t*/
%}

%union {
    lispobj *bu_lispobj;
}

%token <bu_lispobj> NUMBER
%token <bu_lispobj> STRING
%token <bu_lispobj> SYMBOL
/* %token SHARP_QUOTE */

%token ERROR

%type <bu_lispobj> s_exp atom list s_exp_list

%%

start		:
			{ Frecord(Qeof); }
		| s_exp
    			{ Frecord($1); } /* record the s-exp found */
		;

s_exp		: atom
			{ $$ = $1; }
		| list
			{ $$ = $1; }
		| ERROR error
			{ YYABORT; }
		;

atom		: NUMBER
			{ $$ = $1; }
		| SYMBOL
			{ $$ = $1; }
		| STRING
			{ $$ = $1; }
		;

list		: '(' ')'
			{ $$ = Qnil; }
		| '(' s_exp_list ')'
			{ $$ = $2; }
		| '(' s_exp_list '.' s_exp ')'
			{ $$ = Fnconc2($2, $4); }
    		| '\'' s_exp
			{ $$ = Fcons(Qquote, Fcons($2, Qnil)); }
/*
		| SHARP_QUOTE s_exp
			{ $$ = Fcons(Qfunction, $2); }
*/
		;

s_exp_list	: s_exp
			{ $$ = Fcons($1, Qnil); }
		| s_exp_list s_exp
			{ $$ = Fnconc2($1, Fcons($2, Qnil)); }
		;
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar