The grammar basics
The top-level (global) parser is defined in the variable
$parse_global
. It is a global object and distinct from the
second-level parsers, which are all referenced in the %parsers
hash. Why
not have $parsers{GLOBAL}
instead of a separate variable?
Because the top-level parser is so distinct and so independent of all the
second-level parsers that grouping it with them in any way would, I felt, confuse the program structure.
The grammar consists of a Parse::RecDescent
grammar definition interpreted
in place by Parse::RecDescent
. Thus, $parse_global
is
a Parse::RecDescent
object (a parser) with methods corresponding to the
rules defined in the grammar.
The input()
method and its corresponding grammar rule are essential. This
is the only method I want from the top-level parser, since it unites all
the other rules in one. It's recommended to have only one top rule in a
grammar for clarity, unless you need to share grammar element definitions
between several disjoint grammars. If that's the case, make sure you
document your decision so a casual reader can immediately understand what's happening.
|
View The road to better programming: Chapter 8. The top-level and compound-class parsers Discussion
Page: 1 2 3 4 5 6 7 Next Page: The simple elements of the top-level parser