The interpreter holds 1 global scope, if you try to access a non declared value it *should* crash.
This commit is contained in:
parent
347a98bd70
commit
d7c3ab9b4b
|
@ -5,7 +5,7 @@ interpreter::evalSTM(struct token stm) {
|
|||
switch (stm.tok_type) {
|
||||
case token::STM_ASSIGN:
|
||||
table[stm.value] = evalEXP(*stm.rvalue);
|
||||
std::cout << stm.value << " igual a " << table[stm.value] << '\n';
|
||||
std::cout << stm.value << " igual a " << table.at(stm.value) << '\n';
|
||||
break;
|
||||
case token::STM_COMPOUND:
|
||||
evalSTM(*stm.lvalue);
|
||||
|
@ -25,7 +25,7 @@ interpreter::evalEXP(struct token exp) {
|
|||
return std::stoi(exp.value);
|
||||
break;
|
||||
case token::EXP_ID:
|
||||
return table[exp.value];
|
||||
return table.at(exp.value);
|
||||
break;
|
||||
case token::EXP_OPERATION:
|
||||
if(exp.value == "+") return evalEXP(*exp.lvalue) + evalEXP(*exp.rvalue);
|
||||
|
|
Loading…
Reference in New Issue