
Use a plain old struct instead of std::tuple: struct Operator What you need are named parameters to make it clear. And as you can see, you are forced to name your parameters in the comments and to use positional arguments ( std::get). You use an std::tuple to represent the information associated to an operator. You can replaced them by inline functions, or even by lambdas since it seems that you are using C++11. #define PRECEDENCE(c) std::get(operator_info.at(c))

#define IS_LEFT_ASSOCIATIVE(c) std::get(operator_info.at(c)) The following macros are not needed: #define IS_BINARY(c) std::get(operator_info.at(c)) You should either accept numbers beginning with a dot or forbid number ending with a dot. Your function process_number accepts numbers contaning a dot or ending with a dot but does not accept as valid numbers beginning with a dot, which is rather strange. You should have written this instead: while (head != last & std::isdigit(*head)) You should really use one line per statement, and separate your statements by, not by. By the way, please, never do this again: while(head != last & is_numeric(*head)) valid = true, *output++ = *head++

#JAVA SYMBOLIC CALCULATOR SHUNTING YARD CODE#
It makes it easier to extend your code to avoid errors. It's not required, but most of the guidelines will tell you to do so. You should always put curly braces after an if clause. Static const char tokens = after the if): if (head = last) Requires at least an input iterator for Iterator1, and an output iterator for Iterator2īool parse_to_rpn(Iterator1 head, Iterator1 last, Iterator2 output) Head = find_first_of(head, last, symbols_begin, symbols_end) Get next symbol and advance head iterator past itĬhar inline get_symbol(Iterator1& head, Iterator1 last, Iterator2 symbols_begin, Iterator2 symbols_end) While(is_numeric(*++head)) *output++ = *head While(head != last & is_numeric(*head)) valid = true, *output++ = *head++ Pump characters though to output while input is currently a number, and advance head iterator past numberīool inline process_number(Iterator1& head, Iterator1 last, Iterator2& output)

While(head != last & std::isspace(*head)) ++head Void inline skip_space(Iterator& head, Iterator last) I'm well aware that I could make it much easier by using a parser generator, but for now I want to try to hand code it. I have been improving a little implementation of Dijkstra's shunting yard algorithm that currently handles negatives and parentheses correctly (which took a bit of work). I've been trying to expand my programming horizons, and have entered the world of grammars and parsing, which I'm brand new to.
