R
Rui Maciel
I'm a Perl newbie and I've started to look into the Parse::RecDescent
module. Meanwhile I've stumbled on a rule matching problem. I've defined
a couple of rules to be able to deal with two different types of numbers:
integers and decimal fractions with a single decimal place. The problem
is that RecDescent returns false positives by matching the integer rule
on decimal fraction numbers.
As far as I can tell, that could only happen if somehow RecDescent
doesn't make any use of any terminal symbol to specify if the rule really
matches a pattern, which I believe could lead to a lot of false positives.
So, am I missing something or is there no solution to this problem?
Some test code follows and thanks in advance
Rui Maciel
#! /usr/bin/perl -w
use strict;
use Parse::RecDescent;
use Encode;
my $text;
my $grammar = <<'EOG';
startrule: grade1 grade2
{ print "$item[1]\t$item[2]\n";
}
grade1: /\d{1,2}\.\d/
grade2: (/\d{1,2}/|"NA")
EOG
my $parser = new Parse::RecDescent($grammar) or die "Bad grammar!\n";
open(FILE, '-') or die "CRAP ON A STICK!";
while($text = <FILE>)
{
chomp($text);
defined $parser->startrule($text) or print "$text\t<------\n";
}
module. Meanwhile I've stumbled on a rule matching problem. I've defined
a couple of rules to be able to deal with two different types of numbers:
integers and decimal fractions with a single decimal place. The problem
is that RecDescent returns false positives by matching the integer rule
on decimal fraction numbers.
As far as I can tell, that could only happen if somehow RecDescent
doesn't make any use of any terminal symbol to specify if the rule really
matches a pattern, which I believe could lead to a lot of false positives.
So, am I missing something or is there no solution to this problem?
Some test code follows and thanks in advance
Rui Maciel
#! /usr/bin/perl -w
use strict;
use Parse::RecDescent;
use Encode;
my $text;
my $grammar = <<'EOG';
startrule: grade1 grade2
{ print "$item[1]\t$item[2]\n";
}
grade1: /\d{1,2}\.\d/
grade2: (/\d{1,2}/|"NA")
EOG
my $parser = new Parse::RecDescent($grammar) or die "Bad grammar!\n";
open(FILE, '-') or die "CRAP ON A STICK!";
while($text = <FILE>)
{
chomp($text);
defined $parser->startrule($text) or print "$text\t<------\n";
}