Next time try something like this when posting a question (or debugging)
#!/usr/bin/perl -lw use strict; use Parse::RecDescent; $::RD_TRACE = 1; # dump a trace $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an er +ror $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c +. $::RD_HINT = 1; # Give out hints to help fix problems. # universal token prefix pattern (default is: '\s*') warn "TOKEN SEPARATOR: $Parse::RecDescent::skip \n"; my $grammar = <<'_EOGRAMMAR_'; File: Tag(s) EOF Tag: | MT Element EOT { print "MT: ", $item[1], "\n"; print " ", $item[2], "\n"; } | MT Element { print "MT: ", $item[1], "\n"; print " ", $item[2], "\n"; } | MT EOT { print "MT: ", $item[1], "\n"; } | MT { print "MT: ", $item[1], "\n"; } | <error> MT: /<MT\d+>/ Element: /[^\/\n]+/ EOF: /^\Z/ EOT: /\// _EOGRAMMAR_ ### THIS IS THE END OF THE GOSH DURN GRAMMAR # Create and compile the source file my $parser = Parse::RecDescent->new($grammar) or die "Dang!! $!"; $parser->File(q[ <MT100> This SUCKS </MT100> <MT666> WHY? <MT066> CAUSE IT DOESN'T WORK <MT2> SO What you gonna DO?/NOW I dunno ]); __END__ TOKEN SEPARATOR: \s* Parse::RecDescent: Treating "File:" as a rule declaration Parse::RecDescent: Treating "Tag(s)" as a one-or-more subrule matc +h Parse::RecDescent: Treating "EOF" as a subrule match Parse::RecDescent: Treating "Tag:" as a rule declaration Parse::RecDescent: Treating "|" as a new production Parse::RecDescent: Treating "MT" as a subrule match Parse::RecDescent: Treating "Element" as a subrule match Parse::RecDescent: Treating "EOT" as a subrule match Parse::RecDescent: Treating "{ print "MT: ", $item[1], "\n"; print + " ", $item[2], "\n"; }" as an action Parse::RecDescent: Treating "|" as a new production Parse::RecDescent: Treating "MT" as a subrule match Parse::RecDescent: Treating "Element" as a subrule match Parse::RecDescent: Treating "{ print "MT: ", $item[1], "\n"; print + " ", $item[2], "\n"; }" as an action Parse::RecDescent: Treating "|" as a new production Parse::RecDescent: Treating "MT" as a subrule match Parse::RecDescent: Treating "EOT" as a subrule match Parse::RecDescent: Treating "{ print "MT: ", $item[1], "\n"; }" as + an action Parse::RecDescent: Treating "|" as a new production Parse::RecDescent: Treating "MT" as a subrule match Parse::RecDescent: Treating "{ print "MT: ", $item[1], "\n"; }" as + an action Parse::RecDescent: Treating "| <error" as a new (error) production Parse::RecDescent: Treating "<error>" as an error marker Parse::RecDescent: Treating "MT:" as a rule declaration Parse::RecDescent: Treating "/<MT\d+>/" as a /../ pattern terminal Parse::RecDescent: Treating "Element:" as a rule declaration Parse::RecDescent: Treating "/[^\/\n]+/" as a /../ pattern termina +l Parse::RecDescent: Treating "EOF:" as a rule declaration Parse::RecDescent: Treating "/^\Z/" as a /../ pattern terminal Parse::RecDescent: Treating "EOT:" as a rule declaration Parse::RecDescent: Treating "/\//" as a /../ pattern terminal | File |Trying rule: [File] | | File | |"\n<MT100> This SUC +KS | | |</MT100>\n<MT666> W +HY? | | |<MT066> CAUSE IT DO +ESN'T | | |WORK\n<MT2> SO What + you gonna | | |DO?/NOW\nI dunno\n" | File |Trying production: [Tag EOF] | | File |Trying repeated subrule: [Tag] | | Tag |Trying rule: [Tag] | | Tag |Trying production: [] | | Tag |>>Matched production: []<< | | Tag |>>Matched rule<< (return value: [Tag])| | Tag |(consumed: []) | | File |>>Matched repeated subrule: [Tag]<< (1| | |times) | | File |Trying subrule: [EOF] | | EOF |Trying rule: [EOF] | | EOF |Trying production: [/^\Z/] | | EOF |Trying terminal: [/^\Z/] | | EOF |<<Didn't match terminal>> | | EOF | |"<MT100> This SUCKS | | |</MT100>\n<MT666> W +HY? | | |<MT066> CAUSE IT DO +ESN'T | | |WORK\n<MT2> SO What + you gonna | | |DO?/NOW\nI dunno\n" | EOF |<<Didn't match rule>> | | File |<<Didn't match subrule: [EOF]>> | | File |<<Didn't match rule>> | printing code (31240) to RD_TRACE

In reply to Re: Difficulties defining a grammar for Parse::RecDescent by Anonymous Monk
in thread Difficulties defining a grammar for Parse::RecDescent by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.