Context-sensitive grammar prolog

223 Views Asked by At

I'm trying to write a DCG grammar in Prolog that would do this :

kkk ... k --> N * (k)

Where k could be anything (e.g. "a", "ab", "abc").

On the left is what I want to consume, on the right is what I want to generate.

Is this even possible with DCG ?

I was trying to do the simplest case with only a letter, like so:

s(N) --> a(N).
a(0) --> [].
a(R) --> [R], [*], [a].
a(M) --> [a], a(N), {M is N + 1}.

eval(X) :-
   s(_, X, []).

But I'm not sure this is the correct way.

Thanks for any help.

0

There are 0 best solutions below