Hi all,
I've written a primitive kind of PROLOG, which requires queries in LISP
syntax:
(prove '(father charles harry))
Now I'm trying to write an interface for it which will translate PROLOG
syntax:
father (charles harry).
into the LISP which feeds my program. I originally wrote it with a (read)
loop, which seemed ideal because it translated input directly into
LISP lists rather than strings. However it isn't too happy with full
stops or | characters, which I need... Non of the texts I have come
across cover input in detail, particularly not when it is likely to
be similar but not identical to valid LISP. Does anyone know where I
could get information on this, or, what is the easiest way to grab LISP
lists from strings while still looking out for odd characters like .
and | ???
Thanks,
Emily (e dot winch at lancs dot ac dot uk)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
·······@lancs.ac.uk writes:
> be similar but not identical to valid LISP. Does anyone know where I
> could get information on this, or, what is the easiest way to grab LISP
> lists from strings while still looking out for odd characters like .
> and | ???
One normally uses modified readtables for this kind of problem. Read
section 2 (especially 2.1) of the HyperSpec, and the entries on READ,
*READTABLE*, SET-MACRO-CHARACTER, etc.
But beware that although readtables offer you some flexibility in
modifying the reader, many aspects of the reader algorithm are fixed.
So should your requirements stray to far from Common Lisp syntax, you
will probably get into trouble. The extensibility of Common Lisp's
reader was intended for embedding advanced constructs into Common Lisp
syntax, and not as a general lexer/parser mechanism for any old
syntax. Whether Prolog syntax meets these criteria I'm not sure,
since most of the "Prologs" that have been embedded in CL have assumed
a more lisp-ish syntax.
So if you want robust and secure parsing (especially in the presence
of errors), then whipping up a parser from scratch[1] _might_ be
better.
Regs, Pierre.
Footnotes:
[1] Or via one of the parser generators available freely, or built
into many (commercial) implementations.
--
Pierre Mai <····@acm.org> http://home.pages.de/~trillian/
"One smaller motivation which, in part, stems from altruism is Microsoft-
bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]
I would extend Pierre's warning and venture the opinion that you will probably
find it very difficult to use the lisp reader to tokenize Edinburgh Syntax
prolog. I suspect your only options are either to write your own tokenizer or to
use a lisp-like syntax. If you don't have a mountain of already-written
Edinburgh prolog to process, I would recommend the latter.
Good luck,
- nick