Let us start with the simple one: ";" is a backtracking "or" both in swi-Prolog and in Visual Prolog. I.e. means the same.
Visual Prolog does not (directly) support Definite Clause Grammars (DCG).
DCG is however a quite simple syntactic sugaring.
Code: Select all
sentence --> nounphrase, verbphrase
Is simply short for
Code: Select all
clauses
sentence(S1, S0) :-
nounphrase(S1, S2),
verbphrase(S2, S3),
S0 = S3. % S0 is normally used directly instead of S3
I.e. each nonterminal is extended with an input and an output argument, the overall input becomes input in the first nonterminal, each output goes as input to the next, and the final output becomes the overall output.
Semantic actions (enclosed in { .. }) are treated as regular predicate calls. So
Code: Select all
sentence --> nounphrase, {action}, verbphrase
means
Code: Select all
clauses
sentence(S1, S0) :-
nounphrase(S1, S2),
action(),
verbphrase(S2, S0).
Terminals (enclosed in [ .. ]) means match a list head. So
Code: Select all
sentence --> ["The"], nounphrase, {action}, verbphrase
means:
Code: Select all
clauses
sentence(S1, S0) :-
["The"|S2] = S1,
nounphrase(S2, S3),
action(),
verbphrase(S3, S0).
Maybe (my memory is not completely "fresh" on this matter) the list match is actually performed in an auxiliary predicate:
Code: Select all
clauses
sentence(S1, S0) :-
match(["The"], S1, S2),
nounphrase(S2, S3),
action(),
verbphrase(S3, S0).
The grammar clauses can use additional argumentswhich are simply maintained in the translation. So
Code: Select all
sentence(sentence(N,V)) --> ["The"], nounphrase(N), {action}, verbphrase(V)
Means:
Code: Select all
clauses
sentence(sentence(N,V), S1, S0) :-
match(["The"], S1, S2),
nounphrase(N, S2, S3),
action(),
verbphrase(V, S3, S0).