abacus icon indicating copy to clipboard operation
abacus copied to clipboard

Support Polish Notation

Open ghost opened this issue 5 years ago • 5 comments

Supporting Polish Notation would be a cool addition to this library in my opinion. Or a polish notation evaluation library may be a idea for another math library? But I dont know how something like this would be done. Just throwing the idea out here.

https://en.wikipedia.org/wiki/Polish_notation

Thanks for reading my issue!

ghost avatar Oct 20 '20 16:10 ghost

I think it could be implemented as another parse function, like parse_polish or so. The resulting AST would be the same (as it's elixir AST anyway).

narrowtux avatar Oct 20 '20 17:10 narrowtux

I think it could be implemented as another parse function, like parse_polish or so. The resulting AST would be the same (as it's elixir AST anyway).

Do you like the idea of having this in your library? Or would it be something that would be at application level? Update: I think I am going to create add-on library for fun and call it PolishAbacus or smth like this. It would would have a function that would parse to a syntax tree that could be used with eval etc

ghost avatar Oct 20 '20 17:10 ghost

I'll gladly accept a PR that adds a second function to parse a different syntax into the same internal representation (the AST). If you need any pointers, feel free to ask. I think writing your own parser is an excellent excercise.

narrowtux avatar Oct 20 '20 19:10 narrowtux

You can probably get away with copying and then modifying this file: https://github.com/narrowtux/abacus/blob/master/src/math_term_parser.yrl

This is in erlangs yecc language: https://erlang.org/doc/man/yecc.html

When it's compiled, a module named :math_term_parser will be available.

narrowtux avatar Oct 20 '20 19:10 narrowtux

Thanks, I will try it out and send a PR! :)

ghost avatar Oct 20 '20 20:10 ghost