I am a very green when it comes to prolog, but essentially what I am trying to do is implement recursion to parse a grammar rule. What I have seems to be correct logically but obviously not because I am not getting the expected outcome.
Here is the rule I want to parse:
S -> X Y Z
X -> a X | a
Y -> b Y | b
Z -> c Y | c
Here is the prolog code:
match(X, [X|T], T).
xs(X0, X):- match(a, X0, X).
xs(X0, X):- xs(X0, X).
ys(X0, X):- match(b, X0, X).
ys(X0, X):- ys(X0, X).
zs(X0, X):- match(c, X0, X).
zs(X0, X):- zs(X0, X).
s(X0, X):- xs(X0, X1), ys(X1, X2), zs(X2, X).
Any help in understanding what I am doing wrong would be greatly appreciated.
Cheers.
maybe the grammar translation must be completed, like in
I would suggest to take a look at the translation that a DCG has to offer:
consulted and listed results in