develooper Front page | perl.recdescent | Postings from October 2009

General question to RecDescent pattern matching

Thread Next
From:
Coote, Ravi
Date:
October 9, 2009 03:21
Subject:
General question to RecDescent pattern matching
Message ID:
321569CAB874B241BF19194870C85712366644@mailserv1.lorien.fkie.fgan.de
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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About