|
Additional Common Notations:
The grammars above use only two metasymbols (= symbols that
have special meaning within the grammar, distinct from the terminal
and non-terminal symbols): "−−>" and "|".
As you introduce more powerful possibilities for notation,
you have to introduce more metasymbols. Here are some common
examples:
- Use curly brackets to mean "zero or more occurrences of "
what is inside the brackets.
- Use square brackets to mean " zero or one occurrence of ",
that is, an optional item.
- Use parentheses for grouping, so that
('+' | '-') ident means the same as:
'+' ident | '-' ident.
- Use regular expressions.
Syntax Diagrams:
The diagrams below show another, quite different, way to
represent BNF Grammars, but the syntax diagrams are
completely equivalent to the other notations.
In the example below, the "normal" grammar is on the
left. On the right are the syntax diagrams. There are endless
variations with these diagrams, but here each separate
diagram defines a non-terminal. Non-terminals are in boxes
and terminals are in ovals. To use the definition you just
follow the arrows.
|