FAQ
Hi all,

I've got a question to the following perl script

------------------
#!/usr/bin/perl

use Parse::RecDescent;

# Create and compile the source file
$parser = Parse::RecDescent->new(q(
startrule : myterm
myterm : /h\d+/ | /h\d+/ "(" myterm ")"
));

# Test it on sample data
print "Valid 1\n" if $parser->startrule("h1");
print "Valid 2\n" if $parser->startrule("h1(h2,h34)");
------------------

Running it gives:
Valid 1
Valid 2

------------------

I don't understand, why String2 h1(h2,h34) is beeing parsed correctly. I
didn't specify a rule like
myterm : /h\d+/ | /h\d+/ "(" myterm ")" | /h\d+/ "(" myterm "," myterm
")" .

Actually it is possibly to put in every string after h1(h2,h34) like
h1(h2,h34)aaaaaaaaaaaa, which is parsed correctly. It gives Valid 2,
too. That shouldnt be, does it ?

Thank you for any hints! Probably i missed something !?

Regards,

Ravi Coote

Search Discussions

  • Dominique Dumont at Oct 13, 2009 at 10:08 am

    "Coote, Ravi" writes:

    I don't understand, why String2 h1(h2,h34) is beeing parsed correctly. I
    didn't specify a rule like
    myterm : /h\d+/ | /h\d+/ "(" myterm ")" | /h\d+/ "(" myterm "," myterm
    ")" .

    Actually it is possibly to put in every string after h1(h2,h34) like
    h1(h2,h34)aaaaaaaaaaaa, which is parsed correctly. It gives Valid 2,
    too. That shouldnt be, does it ?

    Thank you for any hints! Probably i missed something !?
    In fact, both your cases match /h\d+/. In the second case, (h2,h34) is
    not parsed.

    For more information, see

    http://search.cpan.org/~tbone/Parse-RecDescent-FAQ-6.0.i/FAQ.pm#Insuring_a_top-level_rule_match

    All the best

    --
    Dominique Dumont
    "Delivering successful solutions requires giving people what they
    need, not what they want." Kurt Bittner

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprecdescent @
categoriesperl
postedOct 9, '09 at 10:21a
activeOct 13, '09 at 10:08a
posts2
users2
websitemetacpan.org...

2 users in discussion

Dominique Dumont: 1 post Coote, Ravi: 1 post

People

Translate

site design / logo © 2019 Grokbase