Vinícius Garcia
1d8dd499ff
Refactor Scope passing for cleanness and efficience
...
Every time a function was called a new copy of a Scope()
was made, now everything is passed by reference to avoid that
problem.
2016-06-03 21:35:06 -03:00
Vinícius Garcia
33ee3450d7
Add check for operator existence on handle_op()
...
Now calling: "calculator c("a.[10]") will throw as expected.
(it used to cause a segmentation fault)
2016-06-03 21:35:06 -03:00
Vinícius Garcia
e8edb28fd8
Add syntax error check on calcultor::toRPN()
...
Now if the expression is like:
- "10 + + -2" or "10 + 2 + +"
A syntax_error is thrown.
2016-06-03 21:35:06 -03:00
Vinícius Garcia
e24a6651fc
Update calculator::str() to use packToken::str()
2016-06-03 21:35:06 -03:00
Brandon Amos
99abdb9967
Merge pull request #18 from VinGarcia/simplify
...
Add Scope concept, and fix some bugs
2016-06-02 17:45:25 -04:00
Vinícius Garcia
ef15c667a1
Fix assignment/copy segmentation fault
2016-06-02 12:57:28 -03:00
Vinícius Garcia
8bc48c01e0
Add 2 utility functions to packToken
...
The functions are:
- bool packToken::asBool()
- packToken::operator TokenBase*()
2016-06-02 12:57:28 -03:00
Vinícius Garcia
9f6971d0f1
Add default Scope argument to calculators constructor
2016-06-02 12:57:28 -03:00
Vinícius Garcia
60583c22fe
Fix memory leak problem
2016-06-02 12:57:28 -03:00
Vinícius Garcia
90ba6bd0ff
Add the Scope concept and the Scope Class
...
Now instead of passing only maps of variables (TokenMap_t*)
to calculator instances you can keep record a Scope hierarchy.
The scope class works as a stack of TokenMap_t*.
When searching for a variable, it searches the
stack on a top-down order and stops as soon as it finds
a match for the search key.
The old API was not modified, everything still works as before,
because the Scope class constructor accepts a TokenMap_t*, so
you can insert a TokenMap_t* anywhere you could use an Scope instance.
2016-06-02 12:57:28 -03:00
Brandon Amos
529fcbe94c
Merge pull request #17 from VinGarcia/simplify
...
Add MAP type and subscript operator: `[]`
2016-04-26 13:09:55 -04:00
Vinícius Garcia
7e178895be
Add operator "." for the MAP type
2016-04-25 16:07:57 -03:00
Vinícius Garcia
3d302ae01b
Fix opPrecedence to follow C++ standart
...
Before this commit the opPrecendence was wrongly following
the C standart instead of C++'s, now its fixed.
Source url: http://en.cppreference.com/w/cpp/language/operator_precedence
2016-04-25 15:36:42 -03:00
Vinícius Garcia
4605387411
Add subscript operator to packToken to simplify MAP access
2016-04-25 12:24:54 -03:00
Vinícius Garcia
36866d0af6
Adapt packToken to work with the MAP type
2016-04-25 11:50:49 -03:00
Vinícius Garcia
95ee8f23ba
Add the MAP type and the subscript operator: []
...
This operator is a little more than a simple operator,
because it also works as a bracket.
2016-04-25 11:43:59 -03:00
Vinícius Garcia
03b4e17adc
Update packToken to fit strings
2016-04-20 14:28:35 -03:00
Vinícius Garcia
16f220fb32
Update assert function to work with any type of Token
2016-04-20 14:21:05 -03:00
Vinícius Garcia
ebdaaa13a7
Add quoted string literals, e.g.: "str" or 'str'
2016-04-20 13:05:05 -03:00
Vinícius Garcia
229420f205
Fix bug on string == and != operators
2016-04-20 13:04:17 -03:00
Brandon Amos
07b9bf086f
Merge pull request #16 from VinGarcia/simplify
...
Add packToken as a facade for TokenBase*
2016-04-18 15:00:47 -04:00
Vinícius Garcia
dac07bc163
Add string and numeral operations
...
Add operations:
- number + string
- string + number
2016-04-18 15:37:21 -03:00
Vinícius Garcia
030cd2b859
Add string type and string operations
...
Add operations:
- str + str
- str == str
- str != str
2016-04-18 15:37:21 -03:00
Vinícius Garcia
976ef66292
Add copy assignment operator to packToken
2016-04-18 15:36:17 -03:00
Vinícius Garcia
7a345c341a
Add Vinícius Garcia as co-author on shunting-yard.h
2016-04-18 15:19:53 -03:00
Vinícius Garcia
0bb17555b7
Replace the token map value class for the packToken type
...
This change allow to the user of the `TokenMap_t` to:
- Implicit instantiate a BaseToken* from a double.
- Explicit (and safely) convert a BaseToken* to a double.
- Make use of `cout << map["var"]`
- Make use of a serialization function `str()`
The packToken class is not intended to be used on the internals
of the calculate and compile functions, because it would add
some unnecessary function calls everytime a Token is accessed,
but it is useful to simplify the Token access for the API user.
2016-04-18 15:03:41 -03:00
Brandon Amos
ccf4a52d4b
Merge pull request #14 from VinGarcia/simplify
...
Add multi-type support
2016-04-18 08:13:56 -04:00
Vinícius Garcia
e88858c1b9
Add first version of the TokenBase* facade: packToken
2016-04-18 05:24:26 -03:00
Vinícius Garcia
a9bb8ccad3
Merge master with multiple types operations support branch
2016-04-18 03:56:23 -03:00
Vinícius Garcia
e60c156eae
Change calculate and eval return types to TokenBase*
...
Now it is possible to write expression with multiple
variable types.
As of now there are no operator rules to deal with
variables types other than double. But it is now
easy to add these rules.
2016-04-18 02:30:18 -03:00
Vinícius Garcia
f739417c70
Remove DEBUG prints, since TokenBase* can't be printed
2016-04-18 02:14:27 -03:00
Vinícius Garcia
139fd06ae3
Change TokenMap_t to map TokenBase* instead of doubles
2016-04-18 02:11:03 -03:00
Vinícius Garcia
b805d46114
Add typedef OppMap_t for the OpPrecedence map
2016-04-18 01:24:37 -03:00
Vinícius Garcia
79de668225
Add typedef TokenMap_t for the variable map
2016-04-18 01:16:46 -03:00
Vinícius Garcia
a83a25067a
Prepare calculate function to work with non double types
...
Now the evaluation stack contains TokenBase* instead of doubles.
The return type is still double, but it will change on the future
to TokenBase* as well.
The objective is to allow operations using multiple variable
types like:
- Maps
- Strings
- Booleans
Example of an expected expression: "result = 10.0 + m["v" + ID]"
2016-04-18 01:01:10 -03:00
Brandon Amos
a8007bafa6
Fix opPrecedence argument and parameter name conflicts.
2016-03-22 15:57:53 -04:00
Brandon Amos
4481a234a2
README: Link to @awsteiner's o2scl.
2016-03-22 15:57:26 -04:00
Vinícius Garcia
032ae759ff
Add assert_throws and assert_not_throw to test-*.cpp
2016-03-10 17:17:05 -03:00
Vinícius Garcia
bfd60ff166
Force Makefile to recompile all *.o on any .h change
2016-03-08 00:37:21 -03:00
Brandon Amos
5639d9ebf2
Merge pull request #13 from VinGarcia/master
...
Add c style boolean operators and update README.md
2016-02-29 10:59:27 -05:00
Vinícius Garcia
3f1adf454b
Update README.md
2016-02-29 05:44:42 -03:00
Vinícius Garcia
913e6725d8
Add boolean operators
2016-02-29 05:44:42 -03:00
Vinícius Garcia
3ef8c0a0ef
Adapt opPrecedence to match C++ reference
...
Now the precedence number of each operator match
those in [cppreference website][url].
This way it's easier for us to replicate C++ default
precedence order.
[url]: http://en.cppreference.com/w/c/language/operator_precedence
2016-02-29 05:44:42 -03:00
Brandon Amos
ec0029e343
Merge pull request #12 from VinGarcia/master
...
Replace dynamic_cast for static_cast for speed
2016-02-27 16:14:58 -05:00
Vinícius Garcia
cfd5808e36
Replace dynamic_cast for static_cast for speed
2016-02-27 17:57:43 -03:00
Brandon Amos
22b3e71623
Add stdexcept for domain_error.
2016-02-26 20:51:28 -05:00
Brandon Amos
19b56e6629
Add Travis badge to the README.
2016-02-26 17:57:37 -05:00
Brandon Amos
d905c2f172
Makefile: run->test
2016-02-26 17:56:04 -05:00
Brandon Amos
e0322417f8
Update .travis.yml
2016-02-26 17:55:59 -05:00
Brandon Amos
a6216ecf5d
Remove trailing newlines and spaces.
...
\cc @VinGarcia
2016-02-26 17:50:20 -05:00