-
Notifications
You must be signed in to change notification settings - Fork 0
Libroll
libroll is the brain of roll. It is a dynamic library to pass roll expressions into, returning the result of it's calculation. It currently provides the following functions
Return Type | Function | Comment |
---|---|---|
double | iRoll(const char* input) | Passes the output of iRoll_str() into pRoll() and returns the result. |
const char* | iRoll_str(const char* input) | Converts input from Infix into RPN notation(more detail below). |
double | pRoll(const char* input) | Processes an RPN Roll expression and returns the result. |
iroll (short for Infix roll ) First, it tokenizes the expression, then it parses the translated expression into a string buffer using the Shunting-Yard Algotrithm before returning said buffer.
proll (short for polish roll ) is the actual interpreter behind roll and libroll.
It interprets an expression in Reverse polish notation using a Stack of double type floating point numbers as internal memory and can also interpret several assembly-like instructions, allowing conditional branching and the creation of loops.
For more information on this, see Operators.
First, it converts the input into a series of Tokens. These represent the program's instruction memory. Then it attempts to interpret each Token as a number input before checking it against all defined operators. When the internal Instruction pointer reaches outside the bounds of instruction memory (either automatically by incrementing or manually by a "J" call) it will halt the program and return the stack memory's top value.