Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^3: Operator Precedence Parser

by Anonymous Monk
on Jun 19, 2014 at 22:38 UTC ( #1090520=note: print w/replies, xml ) Need Help??

in reply to Re^2: Operator Precedence Parser
in thread Operator Precedence Parser

Very nice code, much simpler & shorter than I expected. I tried to add an = (Perl or C internal-to-expression assignment) to the operators, though, lowest precedence & right-associative:

'='=> {prec=> 5,assoc=>'R',exec=>sub { print "DEBUG $_[0]=$_[1]\n"; $_[1]; }, function=>'asg'},

I added it to the operator pattern:

if (/\G\s*(\*\*|[=+\-*\/%\\])/gc)

and kind of defined the LHS variable


but it fails because Function::evaluate tries to coerce the value, which I set to the variable name, into a number:

return $code->(map 0+$_,@{$self->{arguments}});

I think I have a workaround, but it looks like '=' is a special case because the LHS variable should not be evaluated before calling the assignment function.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090520]
Corion joins another telephone call :-/
[Discipulus]: also The Life and Opinions of the Tomcat Murr
[Discipulus]: I dunno if i can read Dumas in french.. must try some chapter to see
erix . o O( "what fools the french are, Jeeves" )
[choroba]: Also some Достое́вс кий
[Discipulus]: mmh windows understand something like: cd c:\\\\path\\\\to weird..

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2017-05-24 08:08 GMT
Find Nodes?
    Voting Booth?