Question: I'm attempting to parse arbitrary strings in Prolog. If the arbitrary string belongs to the language of the grammar, then the code should return true.
I'm attempting to parse arbitrary strings in Prolog. If the arbitrary string belongs to the language of the grammar, then the code should return true.
s-->ab
a-->[a]a
a-->[a]
b-->[b]b
b-->b
So far, I have...

However, when I have a query such as s([a,a,a,b,b],[]). , prolog returns false when it should be true. I think the code is stuck in infinite recursion, but I am uncertain how to fix it.
c([XIT],X,T c([XIT],X, T) s(Input, []) a(Input,c), b(c, [) a (Input, []) :- C' (Input,a,C), a (C, []) a (Input, []) :- a ([a Input], Input) b(Input, []) :- C' (Input,b,c), b(C, []) b(Input, [I)- c([bIInput], Input) c([XIT],X,T c([XIT],X, T) s(Input, []) a(Input,c), b(c, [) a (Input, []) :- C' (Input,a,C), a (C, []) a (Input, []) :- a ([a Input], Input) b(Input, []) :- C' (Input,b,c), b(C, []) b(Input, [I)- c([bIInput], Input)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
