Next: , Up: Output Information   [Contents][Index]


Initial Context-Free Grammar

An initial context-free grammar is a context-free grammar corresponding to a template regular expression grammar. Use the following command-line format to dump the initial context-free grammar before processing a training terminal symbol sequence:

$ topdown --qg[=NONT1] ... --qg[=NONTn] [--og=FILE] [--recurs=right] REGEX_GRAM_FILE

The following command-line options are applicable to dumping an initial context-free grammar:

--og=FILE

Write the initial context-free grammar to a FILE. If FILE is ‘-’, write the grammar to stdout. This option queries the initial context-free grammar.

--qg[=NONT]

Dump initial context-free grammar productions for a nonterminal symbol NONT of the template regular expression grammar to a file specified by the option --og=FILE. You can pass multiple options --qg=NONT to dump productions for multiple nonterminal symbols. If the option --og=FILE not supplied, dump queried productions to stdout. If NONT not supplied, dump the entire initial context-free grammar. This option queries the initial context-free grammar.

--recurs=left|right

Recursion type for the productions of the initial context-free grammar: left or right. By default, generate left-recursive productions.

Example:

$ cat >initial.rg <<EOF
S: . ( B? . | . B B ) ;
B: . (. .)* . ;
EOF
$ topdown --qg initial.rg
S: _S_1T _S_2C
;

B: _B_1T _B_2A _B_4T
;

_B_2A:
     | _B_2A _B_3T2
;

_S_2C: _S_3Q _S_4T
     | _S_5T B B
;

_S_3Q:
     | B
;

The nonterminal symbols of a template regular expression grammar become the nonterminal symbols of an initial context-free grammar. Auxiliary nonterminal symbols generated for a nonterminal symbol X have formats described below, where i is the ordinal number of an auxiliary nonterminal symbol for the nonterminal symbol X.

_X_iA

Repeating an expression using the quantifier ‘*’ (Asterisk). The repeating is either left-recursive or right-recursive (see the option --recurs=left|right). Example: _B_2A.

_X_iC

Choice alternatives separated by ‘|’. Example: _S_2C.

_X_iQ

An expression for the quantifier ‘?’ (Question). Example: _S_3Q.

_X_iT

A placeholder for a Terminal symbol. Example: _S_4T.

_X_iTj

A placeholder for a sequence of Terminal symbols with length j. Example: _B_3T2.


Next: , Up: Output Information   [Contents][Index]