Fix variables tests
This commit is contained in:
parent
9af941bc2e
commit
0033c4b814
@ -209,7 +209,7 @@ AnalysisResult analyze(Node &ast, Memory &memory) {
|
|||||||
Token token = get<Token>(node.children[1]);
|
Token token = get<Token>(node.children[1]);
|
||||||
string identifier = get<string>(token.data);
|
string identifier = get<string>(token.data);
|
||||||
|
|
||||||
if (memory.contains(identifier))
|
if (memory.contains_top(identifier))
|
||||||
throw RuntimeError("Already defined identifier \""+identifier+"\"", token.pos);
|
throw RuntimeError("Already defined identifier \""+identifier+"\"", token.pos);
|
||||||
|
|
||||||
Type type = try_string_to_type(type_string, type_token.pos);
|
Type type = try_string_to_type(type_string, type_token.pos);
|
||||||
@ -224,7 +224,7 @@ AnalysisResult analyze(Node &ast, Memory &memory) {
|
|||||||
Token token = get<Token>(node.children[1]);
|
Token token = get<Token>(node.children[1]);
|
||||||
string identifier = get<string>(token.data);
|
string identifier = get<string>(token.data);
|
||||||
|
|
||||||
if (memory.contains(identifier))
|
if (memory.contains_top(identifier))
|
||||||
throw TypeError("Already defined identifier \""+identifier+"\"", token.pos);
|
throw TypeError("Already defined identifier \""+identifier+"\"", token.pos);
|
||||||
|
|
||||||
Type type = try_string_to_type(type_string, type_token.pos);
|
Type type = try_string_to_type(type_string, type_token.pos);
|
||||||
|
@ -3,12 +3,14 @@
|
|||||||
#include "../src/include/memory.h"
|
#include "../src/include/memory.h"
|
||||||
#include "../src/include/tokenize.h"
|
#include "../src/include/tokenize.h"
|
||||||
#include "../src/include/parser.h"
|
#include "../src/include/parser.h"
|
||||||
|
#include "../src/include/analysis.h"
|
||||||
#include "../src/include/interpreter.h"
|
#include "../src/include/interpreter.h"
|
||||||
|
|
||||||
EvalResult execute(string s) {
|
EvalResult execute(string s) {
|
||||||
Memory memory;;
|
Memory memory;;
|
||||||
vector<Token> tokens = tokenize({ s });
|
vector<Token> tokens = tokenize({ s });
|
||||||
Node ast = parse(tokens);
|
Node ast = parse(tokens);
|
||||||
|
analyze(ast, memory);
|
||||||
EvalResult res = eval(ast, memory);
|
EvalResult res = eval(ast, memory);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user