Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Perl Parsing Based on Supplied Precedence

by wirito (Acolyte)
on Nov 07, 2012 at 09:06 UTC ( #1002646=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Perl Parsing Based on Supplied Precedence
in thread Perl Parsing Based on Supplied Precedence

With boolean operators there is the same issue. '&&' and 'and' operator has higher precedence that '||' and 'or' (check perlop link on my first post). My approach gives accurate results.
Then 'COND1&&COND2||COND3' is the same as '(COND1&&COND2)||COND3':

$ perl parser.pl COND1&&COND2||COND3 ORIG: { '&&' => [ 'COND1', { '||' => [ 'COND2', 'COND3' ] } ] } NEW: { '||' => [ { '&&' => [ 'COND1', 'COND2' ] }, 'COND3' ] }


Comment on Re^3: Perl Parsing Based on Supplied Precedence
Download Code
Re^4: Perl Parsing Based on Supplied Precedence
by protist (Monk) on Nov 07, 2012 at 11:49 UTC

    "&&" and "and" have differing precedences. "and" is lower precedence than "&&". The same goes for "||" and "or"; "or" has lower precedence than "||". "and" actually has lower precedence than "||", as I will demonstrate.

    code with "&&":

    perl -e 'if(0&& 0||1){print"hello\n"}'

    output:

    hello

    code with "and":

    perl -e 'if(0and 0||1){print"hello\n"}'

    (outputs nothing)

      Yes, you are right. I meant to say:
      '&&' and 'and' operator has higher precedence than '||' and 'or' respectively
      English is not my first language as you can notice :)

        Ah. After I saw your precedences in your example below, I was confused because you seemed to understand haha. I will note here that I was not attempting to mirror Perl precedences in my example precedence, only create a precedence for testing purposes. Your precedence list is more Perl-like.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2015-07-04 17:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls