Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The good news: I applied your technique and it seems to work! The new grammar will parse everything the old one did and the new syntax too.

The bad news: it's incredibly slow! The test suite which used to run in a few seconds now takes so long that I have to kill it on the complex grammar test.

Here's the grammar I'm using now:

expression : logical_expr /^\$/ { \$return = \$item[1]; } logical_expr : comparison_expr logical_op logical_expr { [ \$item[2][0], \$item[2][1], \$item[1], \$item[3] ] +} | comparison_expr { \$item[1] } comparison_expr : math_expr comparison_op comparison_expr { [ \$item[2][0], \$item[2][1], \$item[1], \$item[3] + ] } | math_expr { \$item[1] } math_expr : paren_expr math_op math_expr { [ \$item[2][0], \$item[2][1], \$item[1], \$item[3] + ] } | paren_expr { \$item[1] } paren_expr : '(' logical_expr ')' { \$item[2] } | atom logical_op : /\\|\\||or|&&|and/ { [ ${\BIN_OP}, \$item[1] ] } comparison_op : /le|ge|eq|ne|lt|gt/ { [ ${\BIN_OP}, \$item[1] ] } | />=?|<=?|!=|==/ { [ ${\BIN_OP}, \$item[1] ] } math_op : /[-+*\\/\%]/ { [ ${\BIN_OP}, \$item[1] ] } atom : function_call | var | literal function_call : function_name '(' args ')' { [ ${\FUNCTION_CALL}, \$item[1], \$item[3] ] } | function_name ...'(' logical_expr { [ ${\FUNCTION_CALL}, \$item[1], [ \$item[3] ] ] } | function_name '(' ')' { [ ${\FUNCTION_CALL}, \$item[1] ] } function_name : /[A-Za-z_][A-Za-z0-9_]*/ { \$item[1] } args : <leftop: logical_expr ',' logical_expr> var : /[A-Za-z_][A-Za-z0-9_]*/ { \\\$item[1] } literal : /-?\\d*\\.\\d+/ { \$item[1] } | /-?\\d+/ { \$item[1] } | <perl_quotelike> { \$item[1][2] }

Any ideas what might be going wrong?

-sam


In reply to Re^2: Left-associative binary operators in Parse::RecDescent by samtregar
in thread Left-associative binary operators in Parse::RecDescent by samtregar

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-03-28 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found