Improved syntax for functions

Added logging system for AST nodes as well.
This commit is contained in:
Pasha Bibko
2025-04-24 21:34:30 +01:00
parent 099e543e95
commit 321a7fea18
8 changed files with 74 additions and 27 deletions

View File

@@ -81,6 +81,8 @@ namespace LX
OPEN_BRACE, CLOSE_BRACE,
OPEN_PAREN, CLOSE_PAREN,
COMMA,
// Operators //
ADD, SUB, MUL, DIV,

View File

@@ -27,7 +27,6 @@ namespace LX::AST
{
// General Nodes //
IDENTIFIER,
NUMBER_LITERAL,
OPERATION,
@@ -48,6 +47,9 @@ namespace LX::AST
// Function for generating LLVN IR (Intermediate representation) //
virtual llvm::Value* GenIR(InfoLLVM& LLVM) = 0;
// Function to log the node to a file //
virtual void Log(std::ofstream* log, unsigned depth) = 0;
// Function for generating C/C++ code (Currently not implemented) //
//virtual void GenC() = 0;

View File

@@ -178,9 +178,11 @@ int main(int argc, char** argv)
LX::PrintStringAsColor("Error: ", LX::Color::LIGHT_RED);
std::cout << "Invalid character found in ";
LX::PrintStringAsColor(inpPath.filename().string(), LX::Color::WHITE);
std::cout << ":\n";
std::cout << " {";
LX::PrintStringAsColor(std::string(1, e.invalid), LX::Color::LIGHT_RED);
std::cout << "}:\n";
std::cout << "Line: " << std::setw(lineNumberWidthInConsole) << e.line << " | " << line << "\n";
std::cout << " " << std::setw(lineNumberWidthInConsole) << "" << " | " << std::setw(e.col);
std::cout << " " << std::setw(lineNumberWidthInConsole) << "" << " | " << std::setw(e.col + 1);
LX::PrintStringAsColor("^", LX::Color::LIGHT_RED);
std::cout << "\n";
@@ -215,7 +217,7 @@ int main(int argc, char** argv)
// Prints the code with the error to the console //
std::string errorSquiggle(e.got.length, '~');
std::cout << "Line: " << std::setw(lineNumberWidthInConsole) << e.got.line << " | " << line << "\n";
std::cout << " " << std::setw(lineNumberWidthInConsole) << "" << " | " << std::setw(e.got.column) << "";
std::cout << " " << std::setw(lineNumberWidthInConsole) << "" << " | " << std::setw(e.got.column + 1) << "";
LX::PrintStringAsColor(errorSquiggle, LX::Color::LIGHT_RED);
std::cout << "\n";