
phrase(+Grammar, ?Tokens, ?Remainder)

   Succeeds if Tokens can be parsed as part of the grammar defined in Grammar
and Remainder contains any remaining terms in Tokens.



Arguments
   Grammar             Compound Term or Atom.
   Tokens              List of Prolog terms.
   Remainder           List of Prolog terms.

Type
   Control

Description
   phrase/3 is used to parse grammars (DCGs) defined using the grammar rule
   operator -->.  The flag macro_expansion must be set on when compiling
   grammar rules.


   Giving a list of terms in Tokens, phrase/3 parses it according to the
   grammar defined in Grammar.  As the terms in Tokens are parsed in order,
   any remaining terms are returned in Remainder.  Further acceptable
   solutions are returned on backtracking.


Modes and Determinism
   phrase(+, -, -) is nondet
   phrase(+, +, -) is nondet
   phrase(+, +, +) is semidet

Modules
   This predicate is sensitive to its module context (tool predicate, see @/2).

Fail Conditions
   The initial terms in Tokens do not belong to Grammar

Resatisfiable
   Depends on the grammar

Exceptions
     4 --- Grammar is not instantiated.
     5 --- Grammar is a number or a string.

Examples
   
   [eclipse]: [user].
    a --> [].
    a --> [z],a.
    user compiled 212 bytes in 0.03 seconds
   yes.
   [eclipse]: phrase(a,[z,z],[]).

   yes.
   [eclipse]: phrase(a,[z,z,z,y],[z,y]).

   yes.
   [eclipse]: phrase(a,[z,z,y],R).

   R = [z, z, y]     More? (;)

   R = [z, y]     More? (;)

   R = [y]     More? (;)

   no (more) solution.
   [eclipse]: phrase(a,X,[y]).

   X = [y]     More? (;)

   X = [z, y]     More? (;)

   X = [z, z, y]     More? (;)

   X = [z, z, z, y]     More? (;)

   X = [z, z, z, z, y]     More? (;)
   yes.
   [eclipse]:

Fail:
   phrase(a, [z, z, y], []).

Error:
   phrase(X, [what, time, is, it], [is, it],R).  (Error 4).
   phrase("a", X,R).                             (Error 5).
   phrase(456, X,R).                             (Error 5).





See Also
   phrase / 2, current_macro / 4, macro / 3, erase_macro / 2
