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

@@ -1,17 +1,43 @@
#include <AST.h>
namespace LX
{
std::string ToString(std::unique_ptr<AST::Node>& node)
{
if (node == nullptr) { return "NULL Node"; }
#include <fstream>
switch (node->m_Type)
namespace LX::AST
{
void Node::Log(std::ofstream* log, unsigned depth)
{
(*log) << std::string(depth, '\t') << "NULL node";
}
void NumberLiteral::Log(std::ofstream* log, unsigned depth)
{
(*log) << std::string(depth, '\t');
(*log) << "Number: " << m_Number << "\n";
}
void Operation::Log(std::ofstream* log, unsigned depth)
{
(*log) << std::string(depth, '\t');
(*log) << "Operation {" << ToString(m_Operand) << "}:\n";
(*log) << std::string(depth + 1, '\t') << "LHS:\n";
m_Lhs.get()->Log(log, depth + 2);
(*log) << std::string(depth + 1, '\t') << "RHS:\n";
m_Rhs.get()->Log(log, depth + 2);
}
void ReturnStatement::Log(std::ofstream* log, unsigned depth)
{
(*log) << std::string(depth, '\t');
if (m_Val == nullptr)
{
case AST::Node::IDENTIFIER: return "IDENTIFIER";
case AST::Node::OPERATION: return "OPERATION";
case AST::Node::RETURN_STATEMENT: return "return";
case AST::Node::NUMBER_LITERAL: return "number";
(*log) << "Return\n";
}
else
{
(*log) << "Return:\n";
m_Val->Log(log, depth + 1);
}
}
}