Standard (right) regular grammars have three kinds of rules:
A <- "" A <- "a" A <- "a" B
This is OK for a theoretical point of view, but a big inconvenience to be usable in practice. A practical regular grammar should allow us to use commodity operators (
)), character sets and group multiple rules in a single one. For example, the following regular grammar describes fractional numbers:
start <- digit+ dot digit* | digit* dot digit+ digit <- [0-9] dot <- '.'
The question is, what restrictions must be applied to RHS non-terminals to keep this grammars regular (if it is possible at all)?
Q - Why regular grammars instead of regular expressions?
A - Regular expressions are OK for simple languages, but they are write-only for more complex ones. On the other hand, well written extended regular grammars are allot more readable and maintainable and allows us to extend them with captures and rule actions easily.