diff --git a/src/analysis.cpp b/src/analysis.cpp index e3c40be..25ce0d8 100644 --- a/src/analysis.cpp +++ b/src/analysis.cpp @@ -198,23 +198,31 @@ AnalysisResult analyze(Node &ast, Memory &memory) { } } break; case NodeType::Declaration: { - Token token = get(node.children[0]); + Token type_token = get(node.children[0]); + string type_string = get(type_token.data); + + Token token = get(node.children[1]); string identifier = get(token.data); + if (memory.contains(identifier)) throw TypeError("Already defined identifier \""+identifier+"\"", token.pos); - Type type = try_string_to_type(get(token.data), token.pos); + Type type = try_string_to_type(type_string, type_token.pos); memory.declare(identifier, type); return {}; } break; case NodeType::AssignedDeclaration: { - Token token = get(node.children[0]); + Token type_token = get(node.children[0]); + string type_string = get(type_token.data); + + Token token = get(node.children[1]); string identifier = get(token.data); + if (memory.contains(identifier)) throw TypeError("Already defined identifier \""+identifier+"\"", token.pos); - Type type = try_string_to_type(get(token.data), token.pos); + Type type = try_string_to_type(type_string, type_token.pos); memory.declare(identifier, type); get_cast(type, analyze(node.children[2], memory), get_node_pos(node));