Hi all,
I'm trying to implement a toy version of Basic using Parse::RecDescent as my first attempt at an interpreter. I can't figure out how to implement a goto. Damian Conway's provided plenty of documentation, and I've looked at merlyn's article... If someone could beat me over the head with the solution I would be most grateful.

Here's what I've got so far (edited to illustrate my problem):
use Parse::RecDescent; $RD_HINT++; $RD_WARN++; #$RD_TRACE++; my $grammar = q{ Start: Expression(s) /\Z/ Expression: LineNum Print | LineNum Goto | <error> Print: /print/i /\"/ /[\s\w]+/ /\"/ { print "$item[3]\n"; } Goto: /goto/i LineNum { print "Seen a goto line $item[2]\n"; # How do I seek back to line $item[2] of # the input? } LineNum: /\d+/ }; my $parser = new Parse::RecDescent($grammar); undef $/; my $text = <>; $parser->Start($text);

Thanks in advance.

In reply to Goto with Parse::RecDescent by bent

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.