From: LeonardoBizzoni Date: Fri, 6 Sep 2024 14:27:16 +0000 (+0200) Subject: Fixed typos and error in lexer EOF checks X-Git-Url: http://git.leonardobizzoni.com/?a=commitdiff_plain;h=b7a48c465ee63ea12578471efad97e3fc7e03829;p=LBPL Fixed typos and error in lexer EOF checks --- diff --git a/main.lbpl b/main.lbpl index d182846..46c8dbe 100644 --- a/main.lbpl +++ b/main.lbpl @@ -1,15 +1,15 @@ fn fib(n) { - return fibIter(n, 0, 1); -} - -fn fibIter(n, curr, next) { - if (n == 0) { - return curr; - } else if (n == 1) { - return next; - } else { - return fibIter(n - 1, next, curr + next); + fn fibIter(n, curr, next) { + if (n == 0) { + return curr; + } else if (n == 1) { + return next; + } else { + return fibIter(n - 1, next, curr + next); + } } + + return fibIter(n, 0, 1); } class Prova { @@ -34,4 +34,4 @@ println(a.var1); a.var1 = 210; println(a.var1); -a.runtime(); \ No newline at end of file +a.runtime(); diff --git a/src/AST-generation/lexer.cpp b/src/AST-generation/lexer.cpp index 8696a38..57c3c6d 100755 --- a/src/AST-generation/lexer.cpp +++ b/src/AST-generation/lexer.cpp @@ -121,7 +121,7 @@ std::shared_ptr getNextToken(Source &file) { char *lexeme = 0; char new_ch = 0; - while (file.stream.eof() && file.stream.peek() != '"') { + while (file.stream.peek() != EOF && file.stream.peek() != '"') { if (file.stream.peek() == '\\') { file.advance(); @@ -157,7 +157,7 @@ std::shared_ptr getNextToken(Source &file) { lexeme[len - 1] = new_ch; } - if (file.stream.eof()) { + if (file.stream.peek() == EOF) { return MAKE_TOKEN(TokenType::Error, "Unterminated string."); } else { file.advance(); @@ -256,7 +256,7 @@ TokenType isIdentifierOrKeyword(const char *lexeme, size_t len) { if (len > 1) { switch (lexeme[1]) { case 'l': - return checkKeyword(lexeme, len, 2, "ass", TokenType::Break); + return checkKeyword(lexeme, len, 2, "ass", TokenType::Class); case 'o': return checkKeyword(lexeme, len, 2, "ntinue", TokenType::Continue); } diff --git a/src/AST-generation/parser.cpp b/src/AST-generation/parser.cpp index 239f921..b4e43f0 100755 --- a/src/AST-generation/parser.cpp +++ b/src/AST-generation/parser.cpp @@ -1,12 +1,14 @@ #include "parser.hpp" #include "syntax_error.hpp" +#include #include #include #include #include #include #include +#include std::vector> Parser::parse() { std::vector> stmts; @@ -279,7 +281,7 @@ std::unique_ptr Parser::expression() { if (match(TokenType::Break)) { return std::make_unique(current->line, current->column, current->filename); - } else if (match(TokenType::Break)) { + } else if (match(TokenType::Continue)) { return std::make_unique(current->line, current->column, current->filename); } diff --git a/src/interpretation/builtin_methods.hpp b/src/interpretation/builtin_methods.hpp index 0ded93d..9e5e930 100644 --- a/src/interpretation/builtin_methods.hpp +++ b/src/interpretation/builtin_methods.hpp @@ -11,7 +11,7 @@ class LBPLPrintln : public LBPLCallable { public: LBPLPrintln() {} - int arity() override { return 1; }; + constexpr int arity() override { return 1; }; Value call(Interpreter *, std::vector &args) override { if (std::holds_alternative(args[0])) { @@ -34,7 +34,7 @@ class LBPLClock : public LBPLCallable { public: LBPLClock() {} - int arity() override { return 0; }; + constexpr int arity() override { return 0; }; Value call(Interpreter *, std::vector &args) override { return std::chrono::duration_cast( diff --git a/src/interpretation/interpreter.cpp b/src/interpretation/interpreter.cpp index 53ecdd3..096c4be 100644 --- a/src/interpretation/interpreter.cpp +++ b/src/interpretation/interpreter.cpp @@ -1,9 +1,9 @@ #include "interpreter.hpp" +#include "runtime_error.hpp" #include "types/LBPLClass.hpp" #include "types/LBPLFunction.hpp" #include "types/LBPLInstance.hpp" #include "types/LBPLTypes.hpp" -#include "runtime_error.hpp" #include #include