我正在使用 Parse::RecDescent( 下面的代码) 来解析这样的东西
这 x=2 和 y=2 和 z=3
为什么下面的代码只打印 x!=2 而不是上面的所有行(即 x!=2 和 y!=2 和 z!=3),即使上面的行也被下面的代码解析,知道下面有什么问题代码 ?
use strict;
use warnings;
use Parse::RecDescent;
my $input = 'x=2 and y=3 and z=3';
my $grammar = q{
startrule: expr(s?)
expr: statement operator(s?)
{ return $item{statement}. $item{operator}; }
statement : operand equal value
{ return $item{operand}.' ' .'!='.' '.$item{value} }
equal : /\=/
operator : /and/i
operand: /\w+/
value : /\w+/
};
my $parser = Parse::RecDescent->new($grammar);
my $result = $parser->startrule($input) or die "Couldn't parse!\n";
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
print Dumper $result;