... 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.:
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: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 );
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)first_rule : identifier | binops | lbinops | integer | number
In reply to Re: Parsing and Translation pt.2
by graff
in thread Parsing and Translation pt.2
by speedyshady
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |