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...

I'm attempting to parse arbitrary strings in Prolog. If the arbitrary string

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!