[antlr-interest] Anyone has a LISP ANTLR3 grammar and can con tribute it to Drools?

Stuart Watt SWatt at infobal.com
Thu Jan 24 10:20:13 PST 2008


Yup, for the * => + was my fault - missed that one folks, sorry.

As I said, quote and backquote are properly handled dynamically through
readtables. It is possible to change ' and ` to do entirely different
things, even dynamically. Of course, anyone who did so would not be writing
Lisp any more, but Lispers used this kind of trick to make cheap
approximations to domain specific languages. Adding backquote to Lisp was
even an example in CLTL2, and it is far from simple, especially when nested
(which does happen). 

Approximating readtables by fixing them in ANTLR is a good move. However, I
have seen Lisp grammars that go as far as lexing the special form symbols
specially, as if they are keywords; not a good move. Essentially the Lisp
reader produces an expression from the text, and the interpreter/compiler
operates on these expressions. ANTLR's parser can do the reader, and tree
grammars handle execution, but Lisp coupled them far more closely, by
allowing the interpreter to call the reader and vice versa. 

A good example is the #. syntax which reads the following text as an
expression, runs it, and puts the value in the resulting expression at read
time. i.e., (print #.(+ 1 2)) reads in the expression (print 3). This is a
good example of why full CL parsing/reading can be intertwined with the Lisp
evaluator. It is also an amazing example of the total flexibility which made
Lisp such a powerful language. This flexibility unfortunately made it
possible for people to write some of the worst code I have ever seen. 

--S

-----Original Message-----
From: Randall R Schulz [mailto:rschulz at sonic.net]
Sent: Thursday, January 24, 2008 12:45 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Anyone has a LISP ANTLR3 grammar and can
con tribute it to Drools?


On Thursday 24 January 2008 06:40, Stuart Watt wrote:
> Yes, CL is definitely the way to go.
>
> However, with Lisp, the easy stuff is:
>
> expression =
>   '(' expression* ('.' expression)? ')'

Shouldn't that be:

  '(' expression+ ('.' expression)? ')'


Otherwise you'll accept invalid S-Expressions like this:

  ( . foo )


Also, I think you'll need lexeme and grammar productions to handle quote 
(the apostrophe reader macro, not the (quote ...) form) and back-quote, 
at a minimum.


I've written a pretty complete Common Lisp reader and printer library 
with lists (cons cells), vectors, the full complement of numeric 
representations, reader macros and a read-table. The input side is 
quite complete (up to the aspects that require an evaluator), while the 
printer is somewhat less so.

I wrote it all "by hand," with no parser generator support. This seems 
reasonable for Lisp in ways it would not be for most any other 
language.


> ...


Randall Schulz


More information about the antlr-interest mailing list