phrase/[2,3]

Synopsis

phrase(+*PhraseType, +*List)

phrase(+*PhraseType, +*List, *Rest)

Used in conjunction with a grammar to parse or generate strings.

Arguments


PhraseType callable
non-variable, name of a phrase type. [MOD]
List list
a list of symbols -- tokens or character codes.
Rest list
a tail of List; what remains of List after PhraseType has been found.

Description

Runs through the grammar rules checking whether there is a path by which PhraseType can be rewritten as List.

If List is bound, this goal corresponds to using the grammar for parsing. If List is unbound, this goal corresponds to using the grammar for generation.

phrase/2 succeeds when the list List is a phrase of type PhraseType (according to the current grammar rules), where PhraseType is either a non-terminal or, more generally, a grammar rule body. This predicate is a convenient way to start execution of grammar rules.

phrase/3 succeeds when the portion of List between the start of List and the start of Rest is a phrase of type PhraseType (according to the current grammar rules), where PhraseType is either a non-terminal or, more generally, a grammar rule body.

phrase/3 allows variables to occur as non-terminals in grammar rule bodies, just as call/1 allows variables to occur as goals in clause bodies.

Exceptions


instantiation_error
PhraseType is not bound.
type_error
PhraseType is not callable.

Examples

See example in ref-gru-exa.

See also

-->/2, 'C'/3, expand_term/2, term_expansion/2 ref-gru