Ever wondered how to graphically represent EBNF?
There are some packages out there that can produce so called
Railroad diagrams.
Phillips has a package called
Elegant (you can see some examples in
this document)
Then there is LaTeX-style
rail.sty online, where the results are quite ok as well (the png image is scaled to 600pt in width, so the real quality is better) :
So, how does one read the diagram? For the start form left to right :-) Words in rounded boxes are terminals (i.e. words that you put literally in your code) Words in normal boxes are non-terminals that refer to other diagrams. A construct like in the start with "AVG", "MAX", ... is a switch statement, where you can choose one ot the options. You will see that above "DISTINCT" is a line without a box. This means that "DISTINCT" is optional.
And this is basically all about reading those diagrams.
Unfortunately, this package does not directly know about the 'ususal' EBNF syntax ( AggreagateExpression ::= ....), but uses its own, which looks like the following for the above example
AggregateExpression : ("AVG" |"MAX" |"MIN" |"SUM")
(
(
'DISTINCT' ? StateFieldPathExpression
) | 'COUNT'
(
'DISTINCT' ? IdentificationVariable
| StateFieldPathExpression
| SingleValuedAssociationPathExpression
)
)
;
Perhaps I am going to write some translator between the formats in Perl ...