[net.lang.lisp] BNF for LISP

bzs@bu-cs.UUCP (Barry Shein) (11/21/85)

And the answer is...ya can't do it. At least not in any useful way.
Readmacros are one good counter-example, hunks and comma syntax
((a . b . c) and (a , b , c)) were all forgotten for a while. Super
parens (closing off some set of open parens, either all or up to
the last super-open such as "<defun fact (a) (cond ((< a 2) 1)(t ....>"
or some such are hard I guess.

The real answer is, take it from people who have built a (read), it's
hairy and BNF doesn't help (now consider things like backquote syntax.)
It's a nice fantasy but not useful.

	-Barry Shein, Boston University

israel@umcp-cs.UUCP (Bruce Israel) (11/21/85)

In article <771@bu-cs.UUCP> bzs@bu-cs.UUCP (Barry Shein) writes:
>							   Super
>parens (closing off some set of open parens, either all or up to
>the last super-open such as "<defun fact (a) (cond ((< a 2) 1)(t ....>"
>or some such are hard I guess.

At our site we had this discussion about a lisp BNF a few years ago.
At the time I came up with the following non-ambiguous BNF that
handles '.'s as well as the '[' & ']' super-parens.

S		::=	SEXPR S			; lisp is a sequence of s-exprs
		|	<empty>			; (possibly empty)

SEXPR-list	::=	S			; a list of sexprs ...
		|	S SEXPR . SEXPR		; maybe dotted

SEXPR		::=	'('   SEXPR-list ')'    ; sexpr has matching )'s,
		|	'['   SEXPR-list ']'    ; or matching ]'s,
		|	<atom>			; or none,
		|	'('   S-MINUS-]   ')'	; or matching that close off
		|	'['   S-MINUS-)   ']'	;    one inside,
		!	S-MINUS-)-1 ']'		; or non-matching that is
		!	S-MINUS-]-1 ')'		;    closed by an unmatched one

S-MINUS-]	::=	SEXPR-list S-MINUS-]-1	; can be closed by a ')'
						; because its a list of sexprs
						; where the last one ends
						; without a ']'

S-MINUS-)	::=	SEXPR-list S-MINUS-)-1	; ditto

S-MINUS-]-1	::=	'[' SEXPR-list		; either the ')' closes one,
		|	'[' S-MINUS-]		; or more than one.

S-MINUS-)-1	::=	'(' SEXPR-list		; ditto
		|	'(' S-MINUS-)

-- 

Bruce Israel

University of Maryland, Computer Science Dept.
{rlgvax,seismo}!umcp-cs!israel (Usenet)    israel@Maryland (Arpanet)

barmar@mit-eddie.UUCP (Barry Margolin) (11/24/85)

In my previous posting about the reason that a parser must know about
read macros, I meant to also mention that a parser must also know about
the SETSYNTAX functions.  Using this, a programmer can reprogram the
meaning of any character.  Thus, I could tell the reader to treat any
character as equivalent to parentheses, the cons dot, quote, etc.  The
BNF cannot take this into account.
-- 
    Barry Margolin
    ARPA: barmar@MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar