From 43aa33d69f51e2d82871e6b5abacd59fce30f80a Mon Sep 17 00:00:00 2001 From: binrapt Date: Sat, 3 Oct 2009 06:27:23 +0200 Subject: [PATCH] Working on the class code --- frith/symbol.hpp | 1 + interpreter/interpreter.cpp | 36 +++++++++++------------------------- symbol.cpp | 6 ++++++ 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/frith/symbol.hpp b/frith/symbol.hpp index 9df418c..50d210c 100644 --- a/frith/symbol.hpp +++ b/frith/symbol.hpp @@ -42,6 +42,7 @@ namespace frith symbol_tree_node(); + bool exists(std::string const & name); bool find_entity(std::string const & name, symbol_tree_node * & entity_scope_output, symbol_tree_entity * & entity_output); }; } diff --git a/interpreter/interpreter.cpp b/interpreter/interpreter.cpp index c0a31cc..b9220c5 100644 --- a/interpreter/interpreter.cpp +++ b/interpreter/interpreter.cpp @@ -27,37 +27,23 @@ namespace frith return true; } - bool interpreter::parse_class(std::string & error_message) + match_result::type interpreter::read_class() { - bool class_error(std::string const & message) - { - error_message = error(error_prefix + message, error_message); - return false; - } + std::vector lexemes = lines[line_offset].lexemes; + if(!(lexemes.size() == 2 && lexemes[0].type == lexeme_type::lexeme_type_class_operator && lexemes[1].type == lexeme_type::lexeme_type_name)) + return match_result::no_match; + + std::string const & name = *lexemes[1].string; - std::string const error_prefix = "Class operator error: "; - line_of_code & current_line = lines[line_offset]; - if(current_line.lexemes.size() != 2) - { - error_message = error(error_prefix + "Invalid token count for a class operator", error_message); - return false; - } - lexeme & name_lexeme = current_line.lexemes[1]; - if(name_lexeme.type != lexeme_type_name) - { - error_message = error(error_prefix + "The second lexeme must be a name", error_message); - return false; - } - std::string const & class_name = *name_lexeme.string; frith::symbol_tree_node * node; frith::symbol_tree_entity * entity; - if(current_node->find_entity(class_name, node, entity)) + if(current_node->exists(name, node, entity)) { + error_message = error("Name \"" + name + "\" has already been used by another function or class in the current scope"); + return match_result::error; } - } - match_result::type interpreter::read_class() - { + } match_result::type interpreter::read_function(function & current_function) @@ -118,7 +104,7 @@ namespace frith if(!current_lexer.parse()) return false; - current_node = 0; + current_node = &target_module.symbols; indentation_level = 0; in_a_class = false; diff --git a/symbol.cpp b/symbol.cpp index 812565c..441053d 100644 --- a/symbol.cpp +++ b/symbol.cpp @@ -7,6 +7,12 @@ namespace frith { } + bool symbol_tree_node::exists(std::string const & name) + { + scope_entities::iterator iterator = entities.find(name); + return iterator != entities.end(); + } + bool symbol_tree_node::find_entity(std::string const & name, symbol_tree_node * & entity_scope_output, symbol_tree_entity * & entity_output) { scope_entities::iterator iterator = entities.find(name); -- 2.11.4.GIT