Compound Grammar Indexing

It is possible to index a compound grammar like an array in order to reference a single grammar contained in the compound grammar. This is done using the [] operator as when indexing an array, whether the compound grammar is represented with the || operator or the grammar is from the grammar repository that results in a compound grammar.

If the supplied index is out of bounds, a parse time or an evaluation time ExpressionArrayIndexOutOfBoundsException might be thrown as a result. If the grammar being indexed does not represent a compound grammar, then an ExpressionClassCastException is thrown.

Examples of compound grammar indexing expressions that all result in grammar expressions are shown in Table 5-1.

Compound Grammar Indexing Examples

1

G[grammar.tgl][1]

2

(G[grammar1.digit] || G[grammar2.grxml])[0]

3

((DG[dtmf-1|word=true] || G[grammar.tgl) || GG[hello|dtmf-3])[0][1]