%token NUM = /(\d+)/ %token OP = /([-+*\/])/ %{ my $nxr = 0; my $nxs = 0; %} %conflict isInTheMiddle { $nxs++; if ($nxs == $nxr+1) { print "Reducing by :MIDx input = '".unexpendedInput()."'\n"; $self->YYSetReduce(['NUM', 'OP', ';' ], ':MIDx' ); $nxr = $nxs = 0; } else { $self->YYSetShift('NUM') } } %explorer isInTheMiddle { ($nxr) = $self->YYPreParse('ExpList'); print "Number of x's = $nxr\n"; $nxr = int ($nxr/2); } %% T: %isInTheMiddle? S ';' %isInTheMiddle? S ';' ; S: x %PREC isInTheMiddle S x | %name :MIDx x %PREC isInTheMiddle ; x: NUM | NUM OP x ; %% =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 -P ExpList.eyp $ eyapp -TC noPackratSolvedExpRGconcept.eyp Run it with: $ ./noPackratSolvedExpRGconcept.pm -t -i -m 1 -c '2; 1 2+2 3-5;' =head1 SEE ALSO Files C, C, C =cut