Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Breaking The Rules II

by tsee (Curate)
on Jul 02, 2007 at 15:16 UTC ( #624473=note: print w/ replies, xml ) Need Help??


in reply to Breaking The Rules II

Quite interesting!

On a side note: When I wrote Math::Symbolic::Parser(::Yapp), I stumbled upon a similar essay at http://egparser.sourceforge.net/ . The author focuses more on the performance aspects of the available parsers or rather parser generators, but he also talks about the amount of work required to get going.

Cheers,
Steffen


Comment on Re: Breaking The Rules II
Re^2: Breaking The Rules II
by tsee (Curate) on Jul 05, 2007 at 09:55 UTC

    I forgot to mention how you'd actually use that specific "wheel" to evaluate expressions. I know it's not the point of this meditation to just use the existing tools, but comparison might still be sensible.

    #!/usr/bin/perl use strict; use warnings; use Math::Symbolic; my $parser = Math::Symbolic::Parser->new(); while (1) { print "\n> "; my $line = <STDIN>; my $tree = $parser->parse($line); print("Parse error.\n"), next if not defined $tree; print "Entered: $tree\n"; my $result = $tree->value(); print("Evaluation error.\n"), next if not defined $result; print "Result: $result\n"; }

    The output would look like this:

    > 3*4.2e3+5^(3.1+2) Entered: (3 * 4.2e3) + (5 ^ (3.1 + 2)) Result: 16270.6841971501 > a*b+c Entered: (a * b) + c Evaluation error.

    That last bit shows that the parser is actually intended to be used with variables, too. So it's not a parse error but an evaluation error.

    Switching to using the YAPP based parser is rather straightforward, too. Just add "implementation => 'Yapp'" to the call to the constructor.

    Cheers,
    Steffen

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-10-20 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (93 votes), past polls