diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp index fc7f9a1..2a9a7b6 100644 --- a/src/headers/parsing/Parser.hpp +++ b/src/headers/parsing/Parser.hpp @@ -117,23 +117,23 @@ namespace Parser { } } } - const component_ptr& previous = parseTree.at(parseTree.size() - 1); - if (current.toktype == LPAR) { + if (not parseTree.empty()) { try { - dynamic_cast(*previous).ParseTree::operator=(parse(subTokens)); - } catch (const bad_cast&) { - parsingError(current, "Unexpected parenthesis"); - } - } else if (current.toktype == LBRACE) { - const type_info& previous_id = previous->getId(); - if (previous_id == typeid(Function)) { - dynamic_cast(*previous).ParseTree::operator=(parse(subTokens)); - } else if (previous_id == typeid(Class)) { - dynamic_cast(*previous).body = parse(subTokens); - } - } else parseTree << parse(subTokens); - i = distance(lexed.begin(), closingCharacter); - break; + const component_ptr& previous = parseTree.at(parseTree.size() - 1); + if (current.toktype == LPAR) { + dynamic_cast(*previous).ParseTree::operator=(parse(subTokens)); + } else if (current.toktype == LBRACE) { + const type_info& previous_id = previous->getId(); + if (previous_id == typeid(Function)) { + dynamic_cast(*previous).ParseTree::operator=(parse(subTokens)); + } else if (previous_id == typeid(Class)) { + dynamic_cast(*previous).body = parse(subTokens); + } + } else parseTree << parse(subTokens); + i = distance(lexed.begin(), closingCharacter); + break; + } catch (const out_of_range&) {} catch (const bad_cast&) {} + } } default: parsingError(current, " \u27F5 Unexpected character", true); }