auscompgeek / aucgbot

:robot: auscompgeek's IRC bot written in JS
Mozilla Public License 2.0
8 stars 3 forks source link

calc.js is fugly #7

Closed auscompgeek closed 9 years ago

auscompgeek commented 10 years ago

@plausibility, @ackwell and @cyphar just love my regexps, don't you guys?

probably should implement https://en.wikipedia.org/wiki/Operator-precedence_parser or something

wait, how do I even function

should totally implement RPN at the same time

Useful NCSS notes (thanks Tim!):

Edit: https://en.wikipedia.org/wiki/Shunting-yard_algorithm maybe?

ackwell commented 10 years ago

Op-precedence is actually pretty easy, I recently added it to my language. I used this bit of the LLVM tutorial for reference on my own implementation.

auscompgeek commented 10 years ago

I probably need to learn how to AST first though

inb4 wat you don't know how to AST?

ackwell commented 10 years ago

Read that entire tutorial, it's good. AST needs some getting used to. Oh, I might have NCSS notes as well. Lemme know if you want me to scrounge for them.

sysr-q commented 10 years ago

@auscompgeek, I hate you for reminding me that this exists. I was really hoping I could sleep tonight without having nightmares.

sysr-q commented 10 years ago

However, I'm much more in favor of implementing RPS:

auscompgeek commented 10 years ago

:+1:

Maybe this will finally fix that buggy ** "operator" hack.

cyphar commented 10 years ago

I don't recommend ASTs for something as simple as a calculator. Just use shunting yard to convert from infix to postfix, and then evaluate the postfix. Just look at my project, https://github.com/cyphar/synge, to see what an implementation of this looks like. The shunting is in src/parse.c and the evaluation is in src/eval.c. Ignore the massive amounts of extra features (bignum support, variables, expressions, etc).

ackwell commented 10 years ago

Mn, I forgot about shunting yard. It would be a good choice for this sort of thing.

On 4 June 2014 06:08, Aleksa Sarai notifications@github.com wrote:

I don't recommend ASTs for something as simple as a calculator. Just use shunting yard to convert from infix to postfix, and then evaluate the postfix. Just look at my project, https://github.com/cyphar/synge, to see what an implementation of this looks like. The shunting is in src/parse.c and the evalutation is in src/evaluate.c. Ignore the massive amounts of extra features (bignum support, variables, expressions, etc).

— Reply to this email directly or view it on GitHub https://github.com/auscompgeek/aucgbot/issues/7#issuecomment-45013786.

auscompgeek commented 9 years ago

Well, the bot uses math.js now. I don't feel like actually fixing this any time soon. :P