I've inserted the given context free grammar into the database using assert(....) If the grammar is something like
S-->a,S,b
S-->c
This grammar is inserted into the database. I have to write a dcg to generate sentences for the cfg in the database. For example if i define the dcg in this way myDcg('S',str), the 'S'(non terminal) should be called or substituted by aSb or c|d or so.
The problem is how can i call/substitute 'S' by facts from the database each time a non terminal('S') is encountered to generate sentences.
Hope you understood my question, if not i will try to edit the question.
Below(Sample code) is what i wanted to do exactly This is not dcg.
myGrammar([], []):-!.
myGrammar([T|Rest], [T|Sentence]):-
myGrammar(Rest, Sentence).
myGrammar([NT|Rest], Sentence):-
grammar(NT, Rest1),
append(Rest1,Rest, NewRest),
myGrammar(NewRest, Sentence).
Whenever a terminal is encountered it should be printed out and when a non terminal is encountered it will backtrack.