Closed auscompgeek closed 9 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.
I probably need to learn how to AST first though
inb4 wat you don't know how to AST?
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.
@auscompgeek, I hate you for reminding me that this exists. I was really hoping I could sleep tonight without having nightmares.
However, I'm much more in favor of implementing RPS:
:+1:
Maybe this will finally fix that buggy **
"operator" hack.
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).
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.
Well, the bot uses math.js now. I don't feel like actually fixing this any time soon. :P
@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?