I'm trying to find a grammar (for feeding to lex/yacc to be used in a
C app) that will parse Lisp s-expressions. Basically, I want to write
a chunk of code that will read from a stream and spit out a
box-and-pointers-like data structure representing the stuff read.
(I'd write it myself but I'm getting lazy in my old age ...)
Anyone know of such a beast? Google was unresponsive.
thx -
--
Michael J. Barillier | ``When you have to shoot,
blackwolf(at)shadizar.dyndns.org | shoot. Don't talk.''
http://shadizar.dyndns.org/~blackwolf/ | -- Tuco Ramirez
Public key 0x35E54973: EDB9 4FBC 4D0B 070C C0E3 2EE4 D822 78CE 35E5 4973
Michael J. Barillier wrote:
> I'm trying to find a grammar (for feeding to lex/yacc to be used in a
> C app) that will parse Lisp s-expressions. Basically, I want to write
> a chunk of code that will read from a stream and spit out a
> box-and-pointers-like data structure representing the stuff read.
> (I'd write it myself but I'm getting lazy in my old age ...)
>
> Anyone know of such a beast? Google was unresponsive.
>
You do not need lex/yacc. There exists s-expression parsers
in abundance already, various Lisp implementations. Instead
of using lex/yacc, read the s-expression into a Lisp and
write a Lisp program to ouput data to the C App.
Wade
On Fri, 20 May 2005 17:02:13 GMT, <··················@telus.net> wrote:
> Michael J. Barillier wrote:
>> I'm trying to find a grammar (for feeding to lex/yacc to be used in a
>> C app) that will parse Lisp s-expressions. Basically, I want to write
>> a chunk of code that will read from a stream and spit out a
>> box-and-pointers-like data structure representing the stuff read.
> You do not need lex/yacc. There exists s-expression parsers
> in abundance already, various Lisp implementations. Instead
> of using lex/yacc, read the s-expression into a Lisp and
> write a Lisp program to ouput data to the C App.
An appropriate 'Lisp' is ECL, which you can insert into your C
application.
--
With sufficient thrust, pigs fly fine.
You are better off asking these questions on the ecls mailing lists.
Cheers
--
Marco
Stefan Ram wrote:
> GP lisper <········@CloudDancer.com> writes:
>
>>An appropriate 'Lisp' is ECL, which you can insert into your C
>>application.
>
>
> Under Windows, 0.9c seems to have some problems with the
> generation of C code
>
> http://groups.google.es/groups?selm=2uucolF2f0l1vU1%40uni-berlin.de&output=gplain
>
> and the download link provided now for 0.9d
>
> http://ecls.sourceforge.net/ecl-0.9d.exe
>
> does not work.
>
> It should be possible to compile it under Windows with Mingw,
> but this does not seem so easy to me, because it seem to need
> several Mingw-tools (such as autoconfig) and one seem to have
> to figure out, which tools are needed and so.
>
Michael J. Barillier <········@midsouth.rr.com> writes:
> I'm trying to find a grammar (for feeding to lex/yacc to be used in a
> C app) that will parse Lisp s-expressions.
An S-expression is just a Lisp expression.
Millions of years ago (ok, maybe just 40 or so), in Lisp 1.5 and
earlier, back in the 1960's, there were both M-expressions and
S-expressions. M-expressions were the base language and S-expresions
were how you could represent the language as data. Eventually, they
realized that S-expressions were adequate and dropped M-expressions.
The name had no useful meaning by the 1970's, but still hung on and
continues to confuse people today.
To parse a Lisp expression, call READ from in Lisp.
There is no grammar in the way you're meaning. The definition is
procedural, not syntactic, since it can be extended by user programs.
(You may be working with a subset that is more tractable than that to
a grammar, but since you didn't say, and only you would know, we have
to answer generally.)
> Basically, I want to write
> a chunk of code that will read from a stream and spit out a
> box-and-pointers-like data structure representing the stuff read.
> (I'd write it myself but I'm getting lazy in my old age ...)
As others have suggested, you're doing this from the wrong side.
Call up a Lisp, get it to call READ, and then use the Lisp printer
to re-format your data in a format your parser is happier with,
such as XML.
> Anyone know of such a beast? Google was unresponsive.
Google isn't (yet) a problem solver. It doesn't find things that
are not there. ;) But there ARE some Lispers working there, so you
never know what the future may bring...
>>>>> "kp" == Kent M Pitman <······@nhplace.com> writes:
kp> To parse a Lisp expression, call READ from in Lisp.
kp> There is no grammar in the way you're meaning. The definition
kp> is procedural, not syntactic, since it can be extended by user
kp> programs.
The code I'm working on is a C app that interfaces to a running Lisp
via a pipe. My implementation choices are a) have the C side
read/write Lisp-friendly data streams, b) have the Lisp side
read/write C-friendly data streams, or c) have the C side write
Lisp-friendly data streams (i.e., s-expressions) and the Lisp side
write C-friendly data streams (of unknown format). Option c requires
that the interface implementation be split across two applications and
could become something of a maintenance headache. My supposition was
that if there was a parser grammar available that option a would be a
cake-walk. Option b is less desirable because I'd still have to write
some sort of parser on the C side to handle the data stream generated
by Lisp (this applies to option c as well).
Plus, I've had other instances where having a simple s-expression
parser in a C library would be handy.
kp> (You may be working with a subset that is more tractable than
kp> that to a grammar, but since you didn't say, and only you
kp> would know, we have to answer generally.)
No read macros or anything, just simple ``(foo ("bar" . 123))''-like
stuff.
kp> ... use the Lisp printer to re-format your data in a format
kp> your parser is happier with, such as XML.
What's the quote? ``XML is for people who are afraid of parentheses''
(or something like that). :)
kp> Google isn't (yet) a problem solver. It doesn't find things
kp> that are not there. ;) But there ARE some Lispers working
kp> there, so you never know what the future may bring...
Not a problem solver, but it sure makes those ``do my homework for
me'' problems easier. Not that this is a homework assignment ... but
if the code was out there I had hoped Google would have indexed it.
And Microsoft's the future, not Google! Steve told me so!!
<http://it.slashdot.org/article.pl?sid=05/05/19/1218253> (j/k, I
despise Microsoft.)
Thanks -
--
Michael J. Barillier | ``When you have to shoot,
blackwolf(at)shadizar.dyndns.org | shoot. Don't talk.''
http://shadizar.dyndns.org/~blackwolf/ | -- Tuco Ramirez
Public key 0x35E54973: EDB9 4FBC 4D0B 070C C0E3 2EE4 D822 78CE 35E5 4973
A quick Google search yielding a few C sexpr libraries
http://sexpr.sourceforge.net/
http://theory.lcs.mit.edu/~rivest/sexp.html
and.. a link to a sexpr doc with a BNF grammar
http://theory.lcs.mit.edu/~rivest/sexp.txt
Either use the C libraries or translate the BNF
into lex/yacc.
Wade
Kent M Pitman <······@nhplace.com> writes:
> Millions of years ago (ok, maybe just 40 or so), in Lisp 1.5 and
> earlier, back in the 1960's, there were both M-expressions and
> S-expressions. M-expressions were the base language and S-expresions
Were there any actual implementations of M-expressions back then?
Paolo
--
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools (see also http://clrfi.alu.org):
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- UFFI: Foreign Function Interface
On Sun, 22 May 2005 11:28:32 +0200, <·······@mclink.it> wrote:
> Kent M Pitman <······@nhplace.com> writes:
>> S-expressions. M-expressions were the base language and S-expresions
>
> Were there any actual implementations of M-expressions back then?
You can find them in the Lisp 1.5 manual.
--
With sufficient thrust, pigs fly fine.
GP lisper <········@CloudDancer.com> writes:
> On Sun, 22 May 2005 11:28:32 +0200, <·······@mclink.it> wrote:
> > Kent M Pitman <······@nhplace.com> writes:
> >> S-expressions. M-expressions were the base language and S-expresions
> >
> > Were there any actual implementations of M-expressions back then?
>
> You can find them in the Lisp 1.5 manual.
I don't think there was an implementation of M-expressions.
That's why S-expressions were invented.
On Sun, 22 May 2005 15:22:58 GMT, <······@news.dtpq.com> wrote:
> GP lisper <········@CloudDancer.com> writes:
>
>> On Sun, 22 May 2005 11:28:32 +0200, <·······@mclink.it> wrote:
>> > Kent M Pitman <······@nhplace.com> writes:
>> >> S-expressions. M-expressions were the base language and S-expresions
>> >
>> > Were there any actual implementations of M-expressions back then?
>>
>> You can find them in the Lisp 1.5 manual.
>
> I don't think there was an implementation of M-expressions.
> That's why S-expressions were invented.
Well, I don't know for sure, but it does seem that the "M" involved
here used them and I cannot imagine that he didn't have a lisp
available to utilize his code. Perhaps it was an early and private
lisp for McCathy alone, but their presence the published 1.5 manual (a
large group effort) tends to make me guess otherwise.
--
With sufficient thrust, pigs fly fine.
GP lisper <········@CloudDancer.com> writes:
> On Sun, 22 May 2005 15:22:58 GMT, <······@news.dtpq.com> wrote:
> > GP lisper <········@CloudDancer.com> writes:
> >
> >> On Sun, 22 May 2005 11:28:32 +0200, <·······@mclink.it> wrote:
> >> > Kent M Pitman <······@nhplace.com> writes:
> >> >> S-expressions. M-expressions were the base language and S-expresions
> >> >
> >> > Were there any actual implementations of M-expressions back then?
> >>
> >> You can find them in the Lisp 1.5 manual.
> >
> > I don't think there was an implementation of M-expressions.
> > That's why S-expressions were invented.
>
> Well, I don't know for sure, but it does seem that the "M" involved
> here used them and I cannot imagine that he didn't have a lisp
> available to utilize his code. Perhaps it was an early and private
> lisp for McCathy alone, but their presence the published 1.5 manual (a
> large group effort) tends to make me guess otherwise.
Everything I've read by McCarthy says that the M-expression language
was an early notation for describing the semantics of the language,
and that S-expressions were the only thing that was implemented.
What do you mean by "the 'M' involved here"?
What in the Lisp 1.5 manual leads you to believe that
there is any implementation that accepts M-expressions?
Christopher C. Stacy wrote:
> ...
> Everything I've read by McCarthy says that the M-expression language
> was an early notation for describing the semantics of the language,
> and that S-expressions were the only thing that was implemented.
> What do you mean by "the 'M' involved here"?
> What in the Lisp 1.5 manual leads you to believe that
> there is any implementation that accepts M-expressions?
slightly off-topic: i remember having read (a long time ago, iirc in J.
Sammets programming languages book) about some project called lisp-2,
that implemented an algol or m-expr type syntax for lisp. from what i
remember, it was at stanford under an l. abrahams. does anybody
remember anything about this project? i did try a few web searches, but
came up empty
hs
···@zedat.fu-berlin.de (Stefan Ram) writes:
> When I wrote a comparison of Unotal with S-expressions,
> I became aware of the problem that there is not a single
> widely-accepted Lisp-implementation-independent formal
> specification of S-expressions.
>
> http://www.purl.org/stefan_ram/pub/s-expressions-compared-to-unotal
I don't see how s-exps are different from one lisp to another. Your
web page doesn't clear it up for me. Could you explain differently?
--
An ideal world is left as an excercise to the reader.
--- Paul Graham, On Lisp 8.1
No excuses. No apologies. Just do it.
--- Erik Naggum
Michael J. Barillier wrote:
> I'm trying to find a grammar (for feeding to lex/yacc to be used in a
> C app) that will parse Lisp s-expressions.
I don't think it's possible, because of the reader macros. Lisp is
ungrammatical :-)
alex goldman wrote:
> I don't think it's possible, because of the reader macros. Lisp is
> ungrammatical :-)
Surely not ungrammatical, since then you wouldn't be able to write a
Lisp interpreter or compiler (at least not on our current types of
computers). It's simply not context-free anymore (and probably not
context-sensitive either).
mkb.
"Michael J. Barillier" <········@midsouth.rr.com> wrote in message
···················@shadizar.dyndns.org...
> Basically, I want to write
> a chunk of code that will read from a stream and spit out a
> box-and-pointers-like data structure representing the stuff read.
> (I'd write it myself but I'm getting lazy in my old age ...)
http://www.complang.tuwien.ac.at/~schani/lispreader ?
--
Eivind