[antlr-interest] Semantically guided parsing

Juancarlo Añez apalala at gmail.com
Mon Sep 24 16:45:47 PDT 2012


I solved it by moving the semantic check to the higher-level rule.

-- JA

On Mon, Sep 24, 2012 at 6:40 PM, Juancarlo Añez <apalala at gmail.com> wrote:

>
> 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*
>



-- 
Juancarlo *Añez*


More information about the antlr-interest mailing list