Metagrammars
All
symbols used for representing a grammar may be the terminals of a
metagrammar
whose role is to generate a set of (related) grammars. For instance, the
following metagrammar
RND
[A grammar is a set of rules]
<1>
S --> 'RND'; Ri
<10>
S --> S ; R
----------------------
RND
[Define context-free rules in Chomsky normal form]
Ri
--> 'S' '-->' Arg2
R
--> Arg1 '-->' Arg2
Arg1
--> Variable
<1>
Arg2 --> Constant
<5>
Arg2 --> Variable Variable
------------------------
RND
Variable
--> X
Variable
--> Y
Variable
--> Z
Constant
--> a
Constant
--> b
Constant
--> c
Constant
--> d
generates
any λ-free context-free grammar with variables {X,Y,Z} and terminal
symbols {a,b,c,d}. 'S', 'RND' and '-->' are terminal symbols of the
metagrammar itself, hence the single quotes. Semicolons generated by this
grammar are automatically converted to line feeds.
Most
grammars generated by "-gr.gramgene
1"
produce empty languages. There are better ways of producing grammars. A
grammar called "-gr.gramgene
2"
on the BP2 disk may be used to generate (non-empty-language) pattern grammars
such as for instance:
-ho.abc
RND
S --> Y Z
Y --> X X
Z --> X X
Y --> b
Z --> d
Y --> c
Z --> (=(= Z )(: Z ))(:(= Z )(: Z )) Y
Y --> d
Z --> X X
X --> b
X --> X Z
X --> a
X --> (= X )(: X ) Y