Bob/headers/Statement.h
Bobby Lucero 7c57a9a111 Implement functions, closures, standard library, and comprehensive number system
- Add function declarations, calls, and return statements
- Implement lexical scoping with Environment class and closures
- Convert print from statement to standard library function
- Add assert() function to standard library for testing
- Add time() function for microsecond precision benchmarking
- Create StdLib class and BuiltinFunction wrapper for standard library
- Implement first-class functions and higher-order functions
- Add function parameter support (tested up to 100 parameters)
- Support alphanumeric identifiers in variable and function names
- Add underscore support in variable names and identifiers
- Implement string + number and number + string concatenation
- Add boolean + string and string + boolean concatenation
- Support string multiplication (string * number)
- Fix decimal truncation issue by using std::stod for all number parsing
- Add comprehensive number formatting with proper precision handling
- Support huge numbers (epoch timestamps) without integer overflow
- Clean number display (no trailing zeros on integers)
- Add basic error handling with program termination on errors
- Add comprehensive test suite covering all features
- Add escape sequence support (\n, \t, \", \\)
- Add comprehensive documentation and language reference
- Update development roadmap with completed features
2025-07-30 17:51:48 -04:00

97 lines
2.4 KiB
C++

#pragma once
#include "helperFunctions/ShortHands.h"
#include "TypeWrapper.h"
#include "Expression.h"
struct ExpressionStmt;
struct VarStmt;
struct BlockStmt;
struct FunctionStmt;
struct ReturnStmt;
struct StmtVisitor
{
virtual void visitBlockStmt(sptr(BlockStmt) stmt) = 0;
virtual void visitExpressionStmt(sptr(ExpressionStmt) stmt) = 0;
virtual void visitVarStmt(sptr(VarStmt) stmt) = 0;
virtual void visitFunctionStmt(sptr(FunctionStmt) stmt) = 0;
virtual void visitReturnStmt(sptr(ReturnStmt) stmt) = 0;
};
struct Stmt
{
const sptr(Expr) expression;
virtual void accept(StmtVisitor* visitor) = 0;
virtual ~Stmt(){};
};
struct BlockStmt : Stmt, public std::enable_shared_from_this<BlockStmt>
{
const std::vector<sptr(Stmt)> statements;
explicit BlockStmt(std::vector<sptr(Stmt)> statements) : statements(statements)
{
}
void accept(StmtVisitor* visitor) override
{
visitor->visitBlockStmt(shared_from_this());
}
};
struct ExpressionStmt : Stmt, public std::enable_shared_from_this<ExpressionStmt>
{
const sptr(Expr) expression;
explicit ExpressionStmt(sptr(Expr) expression) : expression(expression)
{
}
void accept(StmtVisitor* visitor) override
{
visitor->visitExpressionStmt(shared_from_this());
}
};
struct VarStmt : Stmt, public std::enable_shared_from_this<VarStmt>
{
Token name;
const sptr(Expr) initializer;
VarStmt(Token name, sptr(Expr) initializer) : name(name), initializer(initializer)
{
}
void accept(StmtVisitor* visitor) override
{
visitor->visitVarStmt(shared_from_this());
}
};
struct FunctionStmt : Stmt, public std::enable_shared_from_this<FunctionStmt>
{
const Token name;
const std::vector<Token> params;
const std::vector<sptr(Stmt)> body;
FunctionStmt(Token name, std::vector<Token> params, std::vector<sptr(Stmt)> body)
: name(name), params(params), body(body) {}
void accept(StmtVisitor* visitor) override
{
visitor->visitFunctionStmt(shared_from_this());
}
};
struct ReturnStmt : Stmt, public std::enable_shared_from_this<ReturnStmt>
{
const Token keyword;
const sptr(Expr) value;
ReturnStmt(Token keyword, sptr(Expr) value) : keyword(keyword), value(value) {}
void accept(StmtVisitor* visitor) override
{
visitor->visitReturnStmt(shared_from_this());
}
};