The interpreter holds 1 global scope, if you try to access a non declared value it *should* crash.

This commit is contained in:
fsan 2021-10-06 12:25:11 -03:00
parent 347a98bd70
commit d7c3ab9b4b
1 changed files with 2 additions and 2 deletions

View File

@ -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);