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


Alternatives

No choice is not good. It is very common for a non-terminal to be expandable in several directions. In the third example, we expand the language from the first example to the language of parentheses, square brackets, and braces. The new grammar becomes:

%class ex3

language: expr*;
expr: '(' expr* ')'
    | '[' expr* ']'
    | '{' expr* '}'
    ;

The vertical bar (`|') divides the various alternatives for the expansion of an expr. Now `()', `[]', and `{}' are all valid expansions of expr. Note that the (implicit) concatenation of entities has a higher priority than the alternatives: it is not necessary to group each alternative, like in `['(' expr* ')']'.


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