Here is a small PoC on how to build a calculator with a lexer (re2c) and a parser generator (lemon) in C. It supports the four basic mathematical operations and parentheses.
Thanks to MacVicar for his help.
I'm not sure if it works on other platforms beside Linux, as that's all I have (not!), but hey, feel free to improve it! :-)
calc-0.1
Thanks to MacVicar for his help.
I'm not sure if it works on other platforms beside Linux, as that's all I have (not!), but hey, feel free to improve it! :-)
calc-0.1
"The right way"? The easiest way to do it properly is probably using the Shunting-Yard algorithm to transform it into a Reverse Polish notation, and then use another simple algorithm to compute the value of a RPN expression.
ReplyDeleteIt's thought for those aiming at developing it further and eventually turn it into a scripting language.
ReplyDeleteThe calculator by itself is only an example.
I wrote it with re2c and lemon because there were people complaining on the re2c mailing list that there's no such example.
It seems the link to the source code is no longer valid. :(
ReplyDeleteIt's hard to find lemon/re2c examples, so if you could update the link, it'd be great!
please update the link ?
ReplyDeletecan you fix the broken link ?
ReplyDeletestill broken link
ReplyDeleteI've lost the sources, but I'll try to put together a new version in the coming weeks, whenever I'll find some spare time.
ReplyDeletesources:
ReplyDeletehttp://www.daniweb.com/forums/thread150222.html
Hi,
ReplyDeleteThanks for sharing knowledge.
The link to the "calc-0.1" (http://tools.yap-project.com/counter/click.php?id=6) is broken.
Could you please fix it?
Regards
Z.
fix it fast salary paycheck calculator
ReplyDelete