[antlr-interest] Syntactic predicates vs branch-local declarations.
r. clayton
rvclayton at acm.org
Sat Dec 9 12:00:53 PST 2006
I had never heard of it before
It comes from being anal retentive enough to always declare variables in the
smallest possible scope; see, for example, Section 10.4 of Code Complete (2nd
ed) by Steve McConnell.
Some confusion may come about because element labels are not branch local; the
rule
binaryOp
: Plus e1:exp e2:exp
| Minus e1:exp e2:exp
;
causes problems:
$ java antlr.Tool t.a
ANTLR Parser Generator Version 2.7.6 (20060528) 1989-2005
t.a:5:11: Label 'e1' has already been defined
t.a:5:18: Label 'e2' has already been defined
Exiting due to errors.
$
You have to resort to circumlocutions such as
binaryOp
: Plus pe1:exp pe2:exp
| Minus me1:exp me2:exp
;
which is annoying.
More information about the antlr-interest
mailing list