[antlr-interest] Semantically guided parsing
Juancarlo Añez
apalala at gmail.com
Mon Sep 24 16:10:53 PDT 2012
I have to parse hierarchy of descriptions in which each level of the
hierarchy is indicated by an integer.
1 FIRST LEVEL
2 SECOND LEVEL
2 AGAIN SECOND
1 BACK TO FIRST
I've tried to have the parser pick up the hierarchy with semantic
predicates, but I get failures from the predicates instead of simple rule
rejection (the target is Python):
description[d]
:
level[d] text
(description[$d+1])*
level[d]
:
{ self.input.LA(1) == INTEGER and int(self.input.LT(1).getText()) ==
$d}?
INTEGER
;
"rule level failed predicate: { self.input.LA(1) == INTEGER and int(
self.input.LT(1).getText()) == $d}?"
Any ideas?
--
Juancarlo *Añez*
More information about the antlr-interest
mailing list