Grammar Rules

Grammar rules in Prolog are both a convenient way to express definite clause grammars and an extension of the well known context-free grammars.

A grammar rule is of the form:


 head --> body

where both head and body are sequences of one or more items linked by the standard conjunction operator ,.

Items can be:

  • a non-terminal symbol may be either a complex term or an atom.

  • a terminal symbol may be any Prolog symbol. Terminals are written as Prolog lists.

  • an empty body is written as the empty list [ ].

  • extra conditions may be inserted as Prolog procedure calls, by being written inside curly brackets { and }.

  • the left side of a rule consists of a nonterminal and an optional list of terminals.

  • alternatives may be stated in the right-hand side of the rule by using the disjunction operator ;.

  • the cut and conditional symbol (->) may be inserted in the right hand side of a grammar rule

Grammar related built-in predicates: