Call Prolog Predicate

In the following tutorial: http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/7_3.html

There is a part:

test_parser :- repeat, write('?? '), read_line(X), ( c(F,X,[]) | q(F,X,[]) ), nl, write(X), nl, write(F), nl, fail. 

Now I am very confused about the parts c (F, X, []) and q (F, X, []), because it does not seem to correspond to any thing that I saw, c accepts only one parameter from that what can I say, and these parameters do not make sense for q. Please help me understand what is happening here.

+2
source share
2 answers

c defined using --> , which actually adds two hidden arguments to it. The first one is a list to be analyzed according to the grammar rule; the second - "what remains" after parsing. c(F,X,[]) calls c in the list X to get the result of F , expecting that [] will remain, i.e. the analyzer should use the entire list X

+2
source

c // 1 and q // 1 are entry points (like top-level production) of a particular grammar of certain positions where you find

 c(F) --> .... q(F) --> .... 

This style of "calling" at the DCG entry point is not recommended, it is usually better to call the phrase (Grammar, TextToAnalyze, TextAfterAnalysis) , in this case phrase((c(F) ; q(F)), "some text", "")...

The operator --> usually overwritten by adding 2 arguments that are of concern.

EDIT

those. c(L) --> lead_in,arrange(L),end.

corresponded to

c(L,X,Y) :- lead_in(X,X1),arrange(L,X1,X2),end(X2,Y).

+6
source

All Articles