The expression parser...
The operator precedence expression parser uses two stacks (values and operators) and a precedence lookup table to determine appropriate actions and solve the expression.
"Operator precedence parsing is based on bottom-up shift-reduce parsing. As an expression is parsed, tokens are shifted to a stack. At the appropriate time, the stack is reduced, applying the operator at the top of the stack." - Thomas Niemann
As I already mentioned, I've only implemented an expression parser for integer types. I still need to settle on a final design for the expression parser function. I could make a template out of it but I'll probably end up making a different version of each data type. This may be necessary because of incompatible data types. For example I am including float2, float3, and float4 built in vector data types and while I could add an integer to a float3 I couldn't add a float3 to an integer.
Example code...
It's kind of cool to step through the parsers as they execute a script. This is an example of the kind of code it can handle as of now:
int x = 20;
int y = 4;
int z = (2 * (x - y^2)) / y;
print z;
output: 2
I always wanted to find a tool that'd draw (as in, to a bitmap) out expression trees and/or AST's from compiler parsing. Never managed to find one that I could get for free [smile]
Our lecturer got some sort of sick enjoyment over seeing us cramming a whole program's AST onto a single piece of A4 paper in exam conditions [rolleyes]
Jack