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

Re: Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell

by ambrus (Abbot)
on Jan 04, 2006 at 22:20 UTC ( #521037=note: print w/replies, xml ) Need Help??

in reply to Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell

$tok =~ /-?\d+/ only checks whether the token contains an integer, so the token can be an integer and some junk before and after it. If I were you, I'd either use anchors like $tok =~ /^-?\d+$/ or at least use only the integer-looking part: if ($tok =~ /(-?\d+)/) { push @stack, $1; ...

Replies are listed 'Best First'.
Re^2: Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell
by eyepopslikeamosquito (Chancellor) on Jan 05, 2006 at 02:36 UTC

    You are right. My intent was to use /^-?\d+$/ but somehow I "forgot" to insert the anchors. :-( Curiously, when emulating the regex in hand-rolled Haskell code, I somehow "remembered" to insert the anchors. :-) I've updated the Perl code in the root node by inserting the anchors. The Haskell isStrDigit function already checks for all digits (equivalent to using the anchors) and so does not require update. Thanks ambrus.

      This sort of mistake is one of the reasons we're thinking about distinguishing two different levels of pattern match in Perl 6, which we're currently calling "token" matching and "rule" matching, for lack of better names. Rule matching does scanning while token matching doesn't. When a token is matched from within a rule it has to match at the current location, and it's the embedding of the token within the rule match that allows other stuff to match after the token. By itself, a token must match an entire string (maybe with surrounding whitespace). So eventually we should have a way to just ask if the string matches a "num" or "int" pattern of some sort by pretending the token matcher is a subroutine or method of some sort. Perhaps somewhere in the relationship between tokens and rules we also can manage whitespace without scattering modifiers everywhere.
Re^2: Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell
by Anonymous Monk on Jan 04, 2006 at 23:45 UTC
    $x = "12plus some garbage"; $y = "5+-*&^%$#@!"; $sixty = $x * $y; print "$sixty\n"

      Yes, but not for strings like "12.99999e-2" or "somejunk42".

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://521037]
[choroba]: oh wait, the new code doesn't run in 5.14?
[choroba]: so maybe the previous version worked in 5.24, too
[Discipulus]: nope
[choroba]: oh ok
[choroba]: so, each character outside the \0 - \ffff range gets replaced by its name
[Discipulus]: the latest version works in 5.24 and not in 5.14. previous one worked on both but crashed on both with merry rabbit
[Discipulus]: yes: replaced by its name
Discipulus why Win32 must exists?!?!
[choroba]: If you want rabbits and poo, install cygwin
[Discipulus]: no thanks! strawberry flavour is better than poo's one

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-09-19 11:40 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (218 votes). Check out past polls.