Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.ecn.bgu.edu!news.moneng.mei.com!uwm.edu!news.alpha.net!news.mathworks.com!gatech!EU.net!Germany.EU.net!Munich.Germany.EU.net!ecrc!news
From: micha@ecrc.de (Micha Meier)
Subject: Re: Need Help about Parsing :)
Message-ID: <D8s7En.FnD@ecrc.de>
Sender: news@ecrc.de
Reply-To: micha@ecrc.de
Organization: European Computer-Industry Research Centre
References: <D8rx3z.An0@ecrc.de>
Date: Thu, 18 May 1995 16:06:23 GMT
Lines: 39

In article An0@ecrc.de, thom@ecrc.de (Thom Fruehwirth) writes:
>  ortlofrd@track.informatik.uni-stuttgart.de (Roland Ortloff) wrote:
> >An example sentence would be: a > 5 AND b < 3 OR c BETWEEN a AND b
> >
> >    is equivalent to: ((a > 5) AND (b < 3)) OR (c BETWEEN a AND b)
> 
> If you declare AND, OR and BETWEEN as operators in Prolog, the
> two notations are indeed equivalent.

In Prolog AND, OR etc. would be variables so you could not parse them
as operators. You can either quote them ('AND') or use lowercase (and, aND), though.
If you insist on using your notation, it is easier to switch to DCG's.
In the former case, you write e.g.
	:- op(300, xfy, and).
	:- op(400, xfy, or).
	:- op(400, xfx, between).

and just use read/1 to parse the input. For DCG's, you have to write the grammar:

expr -->
	id, ['>'], id.

bool_expr -->
	expr, ['AND'], expr 
	;
	expr, ['OR'], expr.

etc.

--Micha


---
Micha Meier			------------------------------------------------
ECRC, Arabellastr. 17		The opinions expressed above are private
D-81925 Munich 81		and may not reflect those of my employer.
micha@ecrc.de, Tel. +49-89-92699-108, Fax  +49-89-92699-170


