Commit Graph

12 Commits

Author SHA1 Message Date
Vinícius Garcia
59fb48ea6c Add support for assignments on maps, e.g.: a.b = 10 2016-07-11 01:51:33 -03:00
Vinícius Garcia
da1d61092b Add support for assignment on existing variables
Now when resolving a variable's value it is created an rvalue
Token which keeps a reference to the original variable name.

This Token is then qualified to be used on the left side of
assigment operations.

When this is not the case it is converted to a normal Token
so that it can be used for calculations.
2016-07-11 01:51:33 -03:00
Vinícius Garcia
7b7e541d43 Add builtin function support
The builtin functions are defined in the file functions.cpp
Each function receive a Scope* as argument and must return
a packToken type.

The Function class inherits from TokenBase and its constructor
receive 3 arguments:
- A function pointer with signature: packToken (*func)(Scope*)
- The number of named arguments to expect.
- A std::string* list with the arguments name.

The number of named arguments must equal the length of the
string list.

The reason for the only argument be a Scope* is because a function
should also be able to access global variables. This scope is
created so that the arguments are inserted on its most
local TokenMap_t.

After the function execution this TokenMap_t is dellocated.

Builtin functions are now automatically added in the global
TokenMap_t of all scopes by the Scope constructor.
2016-07-09 13:04:47 -03:00
Brandon Amos
9d84f72b04 Use Google code style. Add cpplint and cppcheck to Travis. 2016-06-27 15:01:44 -04:00
Vinícius Garcia
21565f44cb Add static str() function to packToken 2016-06-05 12:50:54 -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
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
03b4e17adc Update packToken to fit strings 2016-04-20 14:28:35 -03:00
Vinícius Garcia
976ef66292 Add copy assignment operator to packToken 2016-04-18 15:36:17 -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
Vinícius Garcia
e88858c1b9 Add first version of the TokenBase* facade: packToken 2016-04-18 05:24:26 -03:00