I am having some difficulties understanding how to parse some text from stdin to the desired variables using DCG.
Players: player1 & player2
Board : 3 moves
1A : player1
5D : player2
8Z : player1
So a game has two player variable names and then some moves by each player, I would like to have predicate that unifies Players = [player1,player2] , turn1 = [1A,8A] , turn2 = [5D].
How Would I do this using DCG ?
I have tried the following:
main :-
read_string(user_input,"\n","\r",_,FirstLine),
phrase(readPlayers(Players),FirstLine),
write(Players).
parsePlayers --> [Players].
parseColon --> [:].
parseSpace --> [ ].
readPlayers([P1,P2]) --> parsePlayers,parseColon,parseSpace,P1,parseSpace,[&], parseSpace,P2.
However this doesn't work in SWI-Prolog, how can I achieve this?
":"in place of[:]. Similarly" "in place of[ ]which is the same as[]. AlsoparsePlayersmeans what exactly? At least you got a warning here. - false