HeavyDelta | 2 Oct 07:37
Favicon

List of Predicates... help


So I'm completely new to Prolog and am coding a shift reduce parser. My first
step is to transform a list of tokens...

[1,+,2,*,3]

into a more meaningful list of predicates (called compound terms??)

[term(int,1), term(plus,_), term(int,2), term(times,_), term(int,3)]

After 15 hours of staring at a blank screen, I produced this, which seems to
work.

term(int,A) :- number(A).
term(plus,A) :- A = '+'.
term(times,A) :- A = '*'.
transform(T,A) :- term(T,A).
map([],[]).
map([A|B],[X|C]) :- map(B,C),transform(T,A),X = term(T,A).

eg.
map([1,+,2,*,3], X).
X = [term(int,1), term(plus,_), term(int,2), term(times,_), term(int,3)].

My problem is that (I think) each element in the list is really just an
atom/string to Prolog instead of a predicate... does that make sense?

I tried replacing "X = term(T,A)". with "X is term(T,A)" (I don't even know
the difference) but then it says "term is not a function you woodpecker!!"

So how do I make it into a list of predicates, if i am making any sense at
all.

PS
if in the code there is a clause like...
input([1,+,2,*,3]).

Is there a way I can call my map function using that input instead of typing
the list out every time..

Any help would be greatly appreciated... really.. you could blurt out any
trivial fact about prolog and I will have learnt something.
--

-- 
View this message in context: http://www.nabble.com/List-of-Predicates...-help-tp19773700p19773700.html
Sent from the SWI Prolog mailing list archive at Nabble.com.

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog <at> iai.uni-bonn.de
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog


Gmane