Commit Graph

23 Commits

Author SHA1 Message Date
Brandon Amos
a6216ecf5d Remove trailing newlines and spaces.
\cc @VinGarcia
2016-02-26 17:50:20 -05:00
Vinícius Garcia
3f80b27bdc Make it accept variable names with numbers, e.g. a1 2016-02-26 01:59:21 -03:00
Vinícius Garcia
9750682c9c Modify calculate() for lazy variable evaluation
Now it is possible to precompile an expression without
binding all its variable values. And bind them only
when the expression will be evaluated.

This way different evaluations of a single expression
may have different sets of variables.

This method optimizes the case when you need to re-evaluate
a single equation several times in different contexts.
2016-02-26 01:24:57 -03:00
Vinícius Garcia
ef5b5d2f22 Add non static functions: compile() and eval()
With this commit the class can now be instantiated.
It now has a constructor and a destructor.

The Compile function will read an expression,
produce an RPN, and save it on this->RPN.

Eval will evaluate this->RPN only when asked for.

The calculator::str() function was added to simplify
the debugging process.
2016-02-26 01:15:08 -03:00
Vinícius Garcia
af9cc8b07e Define opPrecedence as static class member
It was done for better modularization:
1. Now it does not have to be rebuilt everytime calculate runs.
2. Now it can be added as an optional default argument of
   `toRPN()` function, simplifying it's calls.
2016-02-25 23:35:02 -03:00
redpois0n
1e30ea140e Update shunting-yard.cpp 2015-07-23 21:10:36 +02:00
redpois0n
36ff7f8fef Update shunting-yard.cpp 2015-07-23 21:04:51 +02:00
Brandon Amos
271d435078 Formatting and header. 2015-01-28 18:51:31 -05:00
veroight
369c1b588d add "^" op 2015-01-28 23:06:50 +00:00
Brandon Amos
9cbaf00a51 Update README. Fix bug with unary operators/operator parsing. 2013-06-21 14:41:14 -07:00
Brandon Amos
9174a0571b Add support for unary operators. 2013-06-21 14:34:49 -07:00
Brandon Amos
f21cf3d1aa Update comments. Refactors to eliminate the ShuntingYard class. 2013-06-21 14:12:55 -07:00
Brandon Amos
eea9c17dd0 Small changes. 2013-06-21 10:57:24 -07:00
Brandon Amos
021b10d6f8 Improve error checking. 2013-06-21 10:51:21 -07:00
Brandon Amos
a272eaeaeb Replace RPNExpression with std::queue. 2013-06-21 10:41:07 -07:00
Brandon Amos
1d7e56285d Small-scale code refactors, improvements, and comments. 2013-06-21 10:30:40 -07:00
Brandon Amos
652e347e98 Tweak README. Fix imports. 2013-06-11 06:34:01 -07:00
Brandon Amos
c048bb8108 Add test cases and Makefile. 2013-06-11 06:25:37 -07:00
Brandon Amos
a78f382615 Add support for variables with a string->double map. 2013-06-11 00:17:10 -07:00
Brandon Amos
1a0e28ef64 Make calculate static and fix operator precedence. 2013-06-11 00:16:38 -07:00
Brandon Amos
a28552dfd4 Remove tabs. 2013-06-07 21:31:16 -07:00
Brandon Amos
add2da70de Tweak the Shunting-yard algorithm and add support for bitshifts. 2013-06-07 03:55:05 -07:00
Brandon Amos
2cc5d6af39 Initial import of shunting-yard algorithm. 2013-06-07 02:39:26 -07:00