diff options
Diffstat (limited to 'source/state/variable.d')
-rw-r--r-- | source/state/variable.d | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/source/state/variable.d b/source/state/variable.d new file mode 100644 index 0000000..f77e207 --- /dev/null +++ b/source/state/variable.d @@ -0,0 +1,41 @@ +module state.variable; + +import std.variant; + +import state.stack; + +bool handle(string word) { + switch ( word ) { + case "$" : binary_op_variable_bind; return true; + case "@" : unary_op_variable_resolve; return true; + default : return false; + } +} + +bool handle(Token token) { + return token.visit!( + (int ) => false, + (bool ) => false, + (string word) => handle(word) + ); +} + +private { + +Token[string] variables; + +void binary_op_variable_bind() { + string name = stack.pop.get!string; + Token value = stack.pop; + variables[name] = value; +} + +void unary_op_variable_resolve() { + string name = stack.pop.get!string; + + if ( name in variables ) { + stack.push(variables[name]); + } +} + +} |