################################################################### use strict; use warnings; $::RD_HINT=1; use Data::Dumper; #use autodie; use Parse::RecDescent; my $grammar =<<'END_OF_GRAMMAR'; #Start up action(executed in parser namespace): { use Data::Dumper; } startrule: expr { print "startrule:"; print Dumper(\@item); $return = \@item; } expr: operand(s) { print "expr rule:"; print Dumper(\@item); my $result = $item[1]; print 'Inside expr rule: $result='; print Dumper($result); $return = $result; } operand: /and|or/i { print "operand and/or:"; print Dumper(\@item); $return = lc($item[1]); } operand: /not/i { print "operand not:"; print Dumper(\@item); $return = [lc($item[1])]; } operand: '(' expr ')' { print "operand rule:"; print Dumper(\@item); $return = $item[2]; } | term { $item[1] } term: /[\w\s=><\/:"'\*_]+/ END_OF_GRAMMAR my $input = "(cvtype='problem') and ((problem_description match '*') and (((problem_synopsis match 'FCSIM') or (problem_synopsis match 'ATTE')) OR not ((create_time>time('06/01/2014 0:00:00')) and (create_timenew($grammar); my $result = $parser->startrule($input) or die "Could Not Parse!\n"; print "\n\nresult:"; print Dumper $result; #### result:$VAR1 = [ 'startrule', [ [ 'cvtype=\'problem\'' ], 'and', [ [ 'problem_description match \'*\'' ], 'and', [ [ [ 'problem_synopsis match \'FCSIM\'' ], 'or', [ 'problem_synopsis match \'ATTE\'' ] ], 'or', 'not', [ [ 'create_time>time', [ '\'06/01/2014 0:00:00\'' ] ], 'and', [ 'create_time## result:$VAR1 = [ 'startrule', [ [ 'cvtype=\'problem\'' ], 'and', [ [ 'problem_description match \'*\'' ], 'and', [ [ [ 'problem_synopsis match \'FCSIM\'' ], 'or', [ 'problem_synopsis match \'ATTE\'' ] ], 'or', [ [ 'not', ] [ [ 'create_time>time', [ '\'06/01/2014 0:00:00\'' ] ], 'and', [ 'create_time