chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


Tutorial How My CLI Calculator Works filter_list
Author
Message
RE: How My CLI Calculator Works #8
(12-16-2015, 04:40 AM)Nevermore Wrote: Nice work. I made a oneline calculator challenge on another forum thinking my ruby answer was hot shit, then someone reminded me that eval() existed Tongue

Anyway, you could change your lex function to the below code, because the findall skips over anything that isn't an integer, period, or operator (which would support float input with some tweaking):
Code:
def lex(equation):
    #\d is the same as [0-9]
    return re.findall("\d+|\.|[\+, \-, \*, \/]",equation)

Hey @Nevermore! Good to see you back. Smile
That person who reminded you about eval() was wrong. Eval() can be a big security risk, and it is just not good practice. (kind of like os.system())
Plus a lot can be learned by making your own parsers. xD
This stuff is very applicable to making programming languages! Wink (really cool stuff)
Thanks for the suggestions! Smile As you can probably tell, I'm not great with RE yet. (haven't used it much)

Reply




Messages In This Thread
How My CLI Calculator Works - by m0dem - 12-15-2015, 03:14 PM
RE: How My CLI Calculator Works - by Nil - 12-15-2015, 06:15 PM
RE: How My CLI Calculator Works - by m0dem - 12-15-2015, 07:45 PM
RE: How My CLI Calculator Works - by Nil - 12-15-2015, 08:03 PM
RE: How My CLI Calculator Works - by m0dem - 12-15-2015, 08:22 PM
RE: How My CLI Calculator Works - by Nil - 12-15-2015, 08:34 PM
RE: How My CLI Calculator Works - by Inori - 12-16-2015, 04:40 AM
RE: How My CLI Calculator Works - by m0dem - 12-16-2015, 05:46 AM



Users browsing this thread: 1 Guest(s)