%token NUM = /(\d+)/ %token OP = /([-+*\/])/ %{ my $nxr = 0; my $nxs = 0; %} %conflict isInTheMiddle { return if $self->YYCurtok eq 'other'; $nxs++; warn "nxr = $nxr nxs = $nxs\n"; if ($nxs == $nxr+1) { warn "Reducing by :MIDx nxs = $nxs nxr = $nxr remaining input: ".unexpendedInput()."\n"; $self->YYSetReduce(['NUM', ], ':MIDx' ); #$nxr = $nxs = 0; } else { warn "Shifting remaining input: ".unexpendedInput()."\n"; #my $pos = pos(${$self->input}); #$self->YYSetShift(['NUM', ] ) } } %% T: preproc S 'other' 'things' ; preproc: /* empty */ { ($nxr) = $_[0]->YYPreParse('ExpList'); warn "Number of x's = $nxr\n"; $nxr = int ($nxr/2); } ; S: x %PREC isInTheMiddle S x | %name :MIDx x %PREC isInTheMiddle ; x: NUM | x OP NUM ; %% =head1 SYNOPSIS This grammar is similar to the one in file C. It can't be parsed by LR(k) nor LL(k) algorithms. Backtracking LR and GLR algorithms can but will perform poorly. Compile it with: $ eyapp ExpList.eyp $ eyapp -TC noPackratSolvedExpRG2.eyp Run it with: $ ./noPackratSolvedExpRG2.pm -t -i -m 1 -c '2-3 3*4 5+2' =head1 SEE ALSO Files C, C, C =cut