Help with Parse:RecDescent 
Author Message
 Help with Parse:RecDescent

For once my question is simple enough that I can post code:

use Parse::RecDescent;
$grammer = q {
              NUMBER : /[+-]?\d+\.?\d*[afpnumkgt]/     #Match numbers w/units ie. 5u
                     | /[+-]?\d+\.?\d*[eE]?[+-]?\d*/   #Match sci. numbers ie. 10.4e-15
              VARIABLE : /\w+/

              expression : NUMBER
                         | VARIABLE
                         | /\'[^\']+\'/
              assignment : VARIABLE '=' expression
              param : assignment | expression
              { print "Param:\n";
                print "Assignment : $item{assignment}\n";
                $item{assignment}; }

              startrule : param
              };

$debug = 1;
$::RD_TRACE = $debug;
$parser = Parse::RecDescent->new($grammer);
$parser->startrule("a=5u");

The issue here is that in the param macro doesn't perform
the actions that follow UNLESS I remove the "| expression".
When this is commented the assignment item returns "5u",
not "a=5u" as I would expect, even though the rule matched.

Can anyone set me straight?



Sun, 26 Dec 2004 15:36:53 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Need help w/ Parse::RecDescent

2. Help with Parse:RecDescent

3. Need help with Parse::RecDescent grammar

4. Need help with Parse::RecDescent grammar

5. Help: Problem with simple parsing and Parse::RecDescent

6. Text Parsing - Parse::RecDescent or another method?

7. Parsing with Parse::RecDescent

8. Parse::RecDescent and parsing comments

9. Parsing with Parse::RecDescent

10. Parse::RecDescent stops parsing.

11. Parse::RecDescent: need help with actions and return values

12. need help with demo_logic example of Parse::RecDescent

 

 
Powered by phpBB® Forum Software