1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
From barmar@think.com Thu Feb 24 15:51:42 EST 1994
Article: 12113 of comp.lang.lisp
Xref: glinda.oz.cs.cmu.edu comp.lang.lisp:12113
Path: honeydew.srv.cs.cmu.edu!das-news.harvard.edu!spdcc!think.com!barmar
From: barmar@think.com (Barry Margolin)
Newsgroups: comp.lang.lisp
Subject: Re: Lisp BNF available?
Date: 24 Feb 1994 18:17:09 GMT
Organization: Thinking Machines Corporation, Cambridge MA, USA
Lines: 47
Message-ID: <2kiqv6INNboq@early-bird.think.com>
References: <CLp2rM.828@sparc0a.cs.uiuc.edu>
NNTP-Posting-Host: telecaster.think.com
In article <CLp2rM.828@sparc0a.cs.uiuc.edu> hovig@cs.uiuc.edu writes:
> I would like a BNF grammar for Lisp. It need not be complete; it
>is only for the cursory lexical analysis, but then again it mustn't
>be overly simple, either, like those sometimes in educational sources.
Here's a grammar for a Lisp subset that we used in a project here; this is
yacc source with the actions omitted.
start :
| s_exp
;
s_exp : atom
| list
| ERROR error
;
atom : NUMBER
| SYMBOL
| STRING
;
list : '(' ')'
| '(' s_exp_list ')'
| '(' s_exp_list '.' s_exp ')'
| '\'' s_exp
| SHARP_QUOTE s_exp
;
s_exp_list : s_exp
| s_exp_list s_exp
;
Here are some comments by the author:
Hope it helps. With yacc, the difficulty typically isn't in coming up
with the grammar, it's in coming up with the actions that accompany it;
and the appropriate actions are very problem dependent.
For many languages the lexer is very simple; for lisp it's a bit more
compilicated. For my parser much of the "magic" was in the lexer; the
actions were very simple.
--
Barry Margolin
System Manager, Thinking Machines Corp.
barmar@think.com {uunet,harvard}!think!barmar
|