I'm not sure I understand what sort of problem you're having (and the code you posted in the reply above doesn't really help -- maybe you could provide some minimal script that actually runs and prints something?) Anyway, just to check... you said:

... I ran some evals and it seems to be working fine ... what I want to do is take arguments from a command line (.txt) and then parse the file.

When you "ran some evals", how did you do that, exactly? Normally, PRD works on a string that you supply to some particular "rule" defined in your grammar. Apparently, in your "evals", you've just been passing numbers -- these get "stringified" by automatically by perl so that string operations can be performed on them.

In order to pass a string that comes from a file, just read the file contents into a scalar variable, and pass that variable to the parser rule -- e.g.:

my $input_text; { local $/; # turn on slurp mode within this block open( my $input, "<", $ARGV[0] ); $input_text = <$input>; } $parser->my_first_rule( $input_text );
Presumably, your grammar will be set up so that your "first" rule will invoke sub-rules for the various expected components of your input text, or will tokenize the text and do something sensible with each token; e.g. based on the snippet of grammar in your reply above, a "first rule" might be something like:
first_rule : identifier | binops | lbinops | integer | number
But I haven't used PRD or anything like it in many years, so I'm a little fuzzy on how the grammar definition works. There's bound to be more to it... (update: e.g. you will probably need a rule to handle white space, possibly with different rules for different kinds of white space)

In reply to Re: Parsing and Translation pt.2 by graff
in thread Parsing and Translation pt.2 by speedyshady

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.