Grammar Rules

Rules based on the (-->)/2 functor are historically called definite clause grammars (DCG). The term definite refers to the absence of negation. But this is not the case anymore nowa-days, since grammar rules might also include a grammatical negation. The head predicate of a grammar rule represents a non-terminal. The predicates in the body of a grammar rule normally refer to other non-terminals. The list and the set construct are used to escape this interpretation. The form of grammar rules can be summarized as follows:

clause’      --> gr_clause 
| head ":-" body
| head.
gr_rule      --> gr_head "-->" gr_body.

gr_body --> gr_goal [ "," gr_body ].
gr_goal --> set
| list
| non-terminal
| variable
| gr_body "->" gr_body
| gr_body ";" gr_body
| "call(" non-terminal "," arguments ")"
| "!" | "fail" | "\\+" gr_goal.

gr_head --> non_terminal "," gr_body
| non_terminal.

non-terminal --> callable.
zero --> "0".                 % is a grammar rule.
s(s(X,Y)) --> np(X), vp(Y).   % is a grammar rule.

The list construct allows referring to terminals, and the set construct allows referring to normal rule bodies. The terminals in a list construct need not only be character codes. They can be arbitrary terms, so as to allow higher level parsing and un-parsing. Again the head of a grammar rule has to be a callable. It is not possible to have grammar rules for numbers or variables. Double quoted strings are short hands for lists of character codes, and they will therefore be interpreted as character code terminals in the body of a grammar rule.