user1845846
user1845846

Reputation: 49

Context Free Grammars to Prolog?

From your knowledge of translation and Type 2 grammars, recall example , defined as follows:

G = {N, T, S, P} 
T = {x, y, z} 
N = {A, B, C} 
S = A 
P = 
< A> ::= x<B>
< A> ::= x<C> 
< B> ::= x<B> 
< B> ::= y 
< C> ::= x<C> 
< C> ::= z

Write Prolog rules to represent this grammar. Test with the following lists:

[x,x,x,z]. 
[x, x, y]. 
[x]. 
[x, y, z]. 
[ ] 

Can someone help me with this question? I have no idea on how to represent this in prolog as most examples on the net are very different!

Thanks!

Upvotes: 3

Views: 437

Answers (1)

CapelliC
CapelliC

Reputation: 60014

just an hint, complete your assignment adding a clause for each production

'A' --> [x], 'B'.
...

test it this way

?- phrase('S', [x,x,x,z], []).

Upvotes: 1

Related Questions