Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Can I get some rules help with PARSE::RECDESCENT

by ikegami (Patriarch)
on Mar 09, 2018 at 18:09 UTC ( [id://1210585]=note: print w/replies, xml ) Need Help??


in reply to Can I get some rules help with PARSE::RECDESCENT

Your desired output makes no sense.

syntax error at a.pl line 5, near "{" Can't find string terminator "'" anywhere before EOF at a.pl line 9.

The (first) fundamental bit you are missing is a definition of what you want to get from the parser. If you don't even know what you want, how can you hope to write a parser that produces it!

Replies are listed 'Best First'.
Re^2: Can I get some rules help with PARSE::RECDESCENT
by DevM (Initiate) on Mar 12, 2018 at 18:08 UTC

    ikegami, thank you for your response. I will try to answer your questions.

    I am sorry my code did not work for you. I diffed it against the code on my system and it is working for me. I can offer no explanation for this behavior.

    I apologize for not being more forthcoming with my requirements. I had hoped that the example I provided would be enough. This is essentially an “order of operations” problem. The three operations I have are And, Or, and Not. And I basically want to build a tree that will let me handle the terms in order based on the precedence provided by parenthesis with the And and Or at the same level and Not being a little higher. (I know Not is not in my original code, but I was starting small) Take the below generic statement.

    (term1) and (term2) and ((term3) or (term4)) and not (term5))

    I would like to boil this down into an array I can traverse bottom up getting to the innermost terms first.

    So first resolve term3 or term 4

    Then resolve the results vs. not term5

    Then resolve the results vs term 2 and term 1

    I figured traversing a tree structure would be the fastest way to do this but I am open to suggestions.

      You said this is your desired output:

      $VAR1 = { { 'cvtype=\'problem\'' } { and } { problem_description match \'*\' } };

      Your desired output makes no sense. It doesn't even compile.

      syntax error at a.pl line 5, near "{" Can't find string terminator "'" anywhere before EOF at a.pl line 9.

      Please fix.


      I would like to boil this down into an array

      Really? An array of what? Parsers normally produce trees.

        My apologies.

        My studies led me to believe that the presentation of a Tree in PERL is actually a Multi-dimensional array. Where the bottom of the tree is actually the furthest out array elements. Kind of turns a tree on it's side. If I am wrong that put's a whole new spin on what I am trying to do.

        Thank You

        DevM

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210585]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found