diff --git a/.gitignore b/.gitignore index ba6fde8..5d43dbb 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ obj/ *.ll *.obj *.exe -log +log.txt # Ignore user specific options # diff --git a/Common/src/Logger.cpp b/Common/src/Logger.cpp index d01d985..7ca4983 100644 --- a/Common/src/Logger.cpp +++ b/Common/src/Logger.cpp @@ -14,7 +14,7 @@ namespace LX static std::ofstream actualLog; // Opens the log file and assigns it to the log pointer // - actualLog.open("log"); + actualLog.open("log.txt"); s_LogFile = &actualLog; // Assigns the priority // diff --git a/Parser/src/Parser.cpp b/Parser/src/Parser.cpp index 7b25161..67d33be 100644 --- a/Parser/src/Parser.cpp +++ b/Parser/src/Parser.cpp @@ -79,31 +79,29 @@ namespace LX // Handles operations, if it is not currently at an operation goes to ParsePrimary // static std::unique_ptr ParseOperation(ParserInfo& p) { - // Checks if the next token is an operator // - // TODO: Add more than just add // - if (p.index + 1 < p.len) [[likely]] + // Calls down the call stack to either get the left hand side or the node // + std::unique_ptr lhs = ParsePrimary(p); + + // If the next token is an operator it means the previously parsed data is the left side of the equation // + if (IsTwoSidedOperator(p.tokens[p.index].type)) { - if (IsTwoSidedOperator(p.tokens[p.index + 1].type)) - { - // Parses the left hand side of the operation // - std::unique_ptr lhs = ParsePrimary(p); - ThrowIf(lhs == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p); + // Parses the left hand side of the operation // + ThrowIf(lhs == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p); - // Stores the operator to pass into the AST node // - Token::TokenType op = p.tokens[p.index].type; - p.index++; + // Stores the operator to pass into the AST node // + Token::TokenType op = p.tokens[p.index].type; + p.index++; - // Parses the right hand of the operation // - std::unique_ptr rhs = ParseOperation(p); - ThrowIf(rhs == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p); + // Parses the right hand of the operation // + std::unique_ptr rhs = ParseOperation(p); + ThrowIf(rhs == nullptr, Token::UNDEFINED, p.tokens[p.index - 1], "value", p); - // Returns an AST node as all of the components combined together // - return std::make_unique(std::move(lhs), op, std::move(rhs)); - } + // Returns an AST node as all of the components combined together // + return std::make_unique(std::move(lhs), op, std::move(rhs)); } - // Else goes down the call stack // - return ParsePrimary(p); + // Else it returns the parsed value // + return lhs; } // Handles return statements, if not calls ParseOperation // diff --git a/example/main.lx b/example/main.lx index b71591a..d71ea6a 100644 --- a/example/main.lx +++ b/example/main.lx @@ -7,7 +7,5 @@ func main() { int c = add(1, 2) - # Test int - return c }