I have managed to write several interpreters including
- Tokenizing
- Parsing, including more complicated expressions such as
((x+y)*z)/2
- Building bytecode from syntax trees
- Actual bytecode execution
What I didn't manage: Implementation of dictionaries/lists/arrays
.
I always got stuck with getting multiple values into one variable.
My value structure (used for all values passed around, including variables) looks like this, for example:
class Value
{
public:
ValueType type;
int integerValue;
string stringValue;
}
Works fine with integers and strings, but how could I implement arrays?
(From now on with array
I mean arrays in my experimental language, not in C++)
How can I fit the array concept into the Value class above? Is it possible?
How should I make arrays able to be passed around just as you could pass around integers and strings in my language, using the class above?
Accessing array elements or memory allocation wouldn't be the problem, I just don't know how to store them.