From 8a8737c84b590044aa6ba76d6ea9cde73357355e Mon Sep 17 00:00:00 2001 From: Wiktor Kubski Date: Mon, 18 Nov 2024 20:56:05 +0000 Subject: [PATCH] Fix function declaration --- README.md | 7 ------- interpreter/main.cpp | 2 +- interpreter/src/Interpreter.cpp | 2 +- interpreter/src/Interpreter.h | 2 +- interpreter/src/Lexer.cpp | 20 ++++++++++++++------ interpreter/src/Lexer.h | 2 ++ 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5ae9d59..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,7 +0,0 @@ -## Dependencies -- GLEW (OpenGL Extension Wrangler Library) - Version 2.1.0 -- GLFW (OpenGL Framework) - Version 3.3 -- GLM (OpenGL Mathematics) - Version 0.9.9.7 -- lodepng - Version 20160124 - -*to be upgraded* diff --git a/interpreter/main.cpp b/interpreter/main.cpp index eaabb75..5960925 100644 --- a/interpreter/main.cpp +++ b/interpreter/main.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) interpreter.registerBuiltInMethod("rotateRight()"); interpreter.registerBuiltInMethod("push()"); - std::shared_ptr tree = interpreter.buildTree(input); + std::shared_ptr tree = interpreter.buildTree(); st::SymbolTable& stRef = interpreter.symbolTable(); SymbolTableBuilder stb; diff --git a/interpreter/src/Interpreter.cpp b/interpreter/src/Interpreter.cpp index 440c5b0..0671d59 100644 --- a/interpreter/src/Interpreter.cpp +++ b/interpreter/src/Interpreter.cpp @@ -618,7 +618,7 @@ std::vector Interpreter::getSequence() return symbolTable().sequence(); } -std::shared_ptr Interpreter::buildTree(const std::string& text) +std::shared_ptr Interpreter::buildTree() { return _parser.parse(); } diff --git a/interpreter/src/Interpreter.h b/interpreter/src/Interpreter.h index e80df93..3f6418e 100644 --- a/interpreter/src/Interpreter.h +++ b/interpreter/src/Interpreter.h @@ -132,7 +132,7 @@ class Interpreter std::vector getSequence(); - std::shared_ptr buildTree(const std::string& text); + std::shared_ptr buildTree(); std::shared_ptr interpret(std::shared_ptr tree); diff --git a/interpreter/src/Lexer.cpp b/interpreter/src/Lexer.cpp index 50d2005..d2accc8 100644 --- a/interpreter/src/Lexer.cpp +++ b/interpreter/src/Lexer.cpp @@ -160,15 +160,23 @@ char Lexer::peekNextChar() return this->_text[this->_pos + 1]; } -std::map Lexer::getReservedKeywords() +bool Lexer::isBuiltInFunction(const std::string& result) { - if (_builtInMethods.empty()) { - std::cout << "chuj bombki szczelyl" << std::endl; - } for (const auto& fun : _builtInMethods) { - std::cout << fun << std::endl; + std::string function = fun; + function.pop_back(); + function.pop_back(); + + if (result == function) { + return true; + } } + return false; +} + +std::map Lexer::getReservedKeywords() +{ std::map RESERVED_KEYWORDS{ {"START", Token("START", TokenType::START) }, {"END", Token("END", TokenType::END) }, @@ -197,7 +205,7 @@ Token Lexer::id() advance(); } - if (_currentChar == '(' && peekNextChar() == ')') { + if (_currentChar == '(' && peekNextChar() == ')' && isBuiltInFunction(result)) { result += "()"; advance(); advance(); diff --git a/interpreter/src/Lexer.h b/interpreter/src/Lexer.h index fba033f..9f67eb8 100644 --- a/interpreter/src/Lexer.h +++ b/interpreter/src/Lexer.h @@ -51,6 +51,8 @@ class Lexer int16_t getParsingLine() { return _parsingLine; } int16_t getParsingPosition() { return _parsingPosition; } + bool isBuiltInFunction(const std::string& result); + std::map getReservedKeywords(); private: