I am trying to understand prolog and definite clause grammar but I am having a very hard time understanding both of them.
I am really trying to understand how to use the dcg syntax...
Here I have two examples:
The first is actually the code from another question on this forum but with an additional question:
The code looked like this:
s --> first, operator, second.
first --> [X].
operator --> ['+'].
second --> [X].
And when Prolog is asked about this, it returns true/false but I can't for the life of me figure out how to actually modify this to "bind" the value so if asked s(X, [2,+,2],[]). it would return the value of first, so instead of returning true it'd say X = 2
Anyway back to the actual question. I have a few rules in normal prolog and this is one of them; it doesn't actually do anything and was merely made up as an example.
do(X, Y, [H|T], Sum):-
H == 1, %check if H is 1
X = H,
Y = T,
Additional is H+5,
Sum is Additional+Additional.
Basically, I am asking if someone could translate this to DCG so that I could try and understand the basic syntax of DCG! I've tried reading some tutorials but I feel like I haven't gotten any wiser...