Go to the first, previous, next, last section, table of contents.

Range Concatenation Grammars

Range Concatenation Grammars is a formalism introduced by Pierre Boullier. They provide an elegant way to specify non-contiguous or even overlapping constituant by expressing constraints on sub-ranges of the input string.

For instance, the following grammar defines the language a^nb^nc^nd^n:

s (X@Y@Z) --> a (X,Y,Z).
a ("a"@X,"b"@Y,"c"@Z) --> a (X,Y,Z).
a ("","","") --> true.

Note that the range arguments are separated from their predicate by a whitespace (Hilog notation).

RCG non terminals may be called from a logic program using rcg_phrase/1, for instance rcg_phrase(s (0:N).

RCG should be compiled with option -rcg to distinguish them from DCG.

RCG may be compiled with or without option -parse, depending if the grammar is to be used to parse from PROLOG lists or token databases.

RCG non terminals may be decorated with attributes and {} may be used to escape to PROLOG. For instance, the previous program may be rewritten to count.

s(N) (X@Y@Z) --> a(N) (X,Y,Z).
a(N) ("a"@X,"b"@Y,"c"@Z) --> a(M) (X,Y,Z), {N is M+1}.
a(0) ("","","") --> true.

A RCG predicate is characterized by its Prolog arity and its range arity. For instance, non-terminal a(N) (X,Y,Z) in the previous program formelly corresponds to predicate rcg(a/1,3).

Directives prolog/1 or rec_prolog/1 apply on RCG predicates to change their tabulation status.

Directive mode/2 also applies to alter their modulation status. The modulation only acts on the PROLOG arguments.

For instance, to be bottom up on the counting argument, use


Go to the first, previous, next, last section, table of contents.