\ + can be used to create less ambiguous grammars. The advantage of using \ + over! for example, declarative \ + is certain, so that, for example, DCG-derived rules can be reordered.
Let's make an example, consider the following grammar:
s([X|Y]) --> t(X), s(Y). % 1 s([]) --> []. % 2 t(2) --> [a,a]. % 3 t(1) --> [a]. % 4
The above grammar is very ambiguous, for example, I get some analyzes of the following input:
?- phrase(s(A),[a,a,a,a,a]). A = [2,2,1] ; A = [2,1,2] ; A = [2,1,1,1] ; etc..
Now suppose I want to prefer a long parsing of t over a short parsing of t. I can do this with a cut as follows:
t(2)
Sorry, I canβt change the order. Since the following is not given the desired result. Although s (A) now gives the results in a different order, we will return to the square, since the grammar is again ambiguous:
t(1)
Now try the same with \ +. We can replace the cut with the following negation:
t(2)
Now let's try changing the order. We reorder the grammar rules of t // 1:
t(1)
Declarative is very useful. This means, for example, that we can use \ + in the parser of a chart from right to left to select grammar rules in an arbitrary order. declaratively ensures that the bottom straight chain of the chart analyzer gives the same result regardless of the order in which DCG rules are entered.
You can then apply the DCG technique in large natural language (NL), and it scales well. NL grammars can be empirically tuned for determinism. The more deterministic grammar the more effective its analysis. Comprehensive NL grammars that otherwise unsolvable become possible.
Bye