57 lines
2.0 KiB
C
57 lines
2.0 KiB
C
|
|
#ifndef SOLSNODE_H
|
||
|
|
#define SOLSNODE_H
|
||
|
|
|
||
|
|
#include <stdarg.h>
|
||
|
|
|
||
|
|
#include "../include/error.h"
|
||
|
|
|
||
|
|
#include "../lexer/SolsType.h"
|
||
|
|
#include "../lexer/SolsLiteral.h"
|
||
|
|
|
||
|
|
typedef enum SolsNodeType {
|
||
|
|
SNT_IDENTIFIER, SNT_LITERAL, SNT_TYPE, SNT_CODE_BLOCK, SNT_OP_ADD, SNT_OP_SUB, SNT_OP_MUL, SNT_OP_DIV, SNT_OP_ADDTO, SNT_OP_SUBTO, SNT_OP_MULTO, SNT_OP_DIVTO, SNT_OP_INCREMENT, SNT_OP_DECREMENT, SNT_OP_SET, SNT_OP_GREATER, SNT_OP_LESSER, SNT_OP_EQUAL, SNT_OP_INEQUAL, SNT_OP_EQGREATER, SNT_OP_EQLESSER, SNT_DEF, SNT_STRUCT, SNT_PUTS, SNT_IF, SNT_WHILE, SNT_NEW, SNT_GROUND, SNT_ROOT
|
||
|
|
} SolsNodeType;
|
||
|
|
|
||
|
|
struct SolsNode;
|
||
|
|
|
||
|
|
// Represents an AST node.
|
||
|
|
// Most node types use the .type and .children fields, however some nodes require storing
|
||
|
|
// more data, inside the .as union.
|
||
|
|
// Those tokens are:
|
||
|
|
// SNT_LITERAL: A literal value. Uses field .as.literal
|
||
|
|
// SNT_TYPE: A type descriptor. Uses field .as.type
|
||
|
|
// SNT_IDENTIFIER: An identifier. Uses field .as.idName
|
||
|
|
// SNT_GROUND: Ground code embedded inside Solstice. Uses field .as.inlineGround
|
||
|
|
typedef struct SolsNode {
|
||
|
|
SolsNodeType type;
|
||
|
|
union {
|
||
|
|
SolsLiteral literal;
|
||
|
|
SolsType type;
|
||
|
|
char* idName;
|
||
|
|
char* inlineGround;
|
||
|
|
} as;
|
||
|
|
struct {
|
||
|
|
size_t count;
|
||
|
|
size_t capacity;
|
||
|
|
struct SolsNode* at;
|
||
|
|
} children;
|
||
|
|
} SolsNode;
|
||
|
|
|
||
|
|
Result(SolsNode, charptr);
|
||
|
|
|
||
|
|
// Creates a SolsNode. If the type passed in is SNT_LITERAL, SNT_TYPE, SNT_IDENTIFIER or
|
||
|
|
// SNT_KW_GROUND, the function expects another argument, corresponding to the data type
|
||
|
|
// the token holds. See the SolsNode struct for more information.
|
||
|
|
// Returns:
|
||
|
|
// Success: The created SolsNode
|
||
|
|
// Failure: char* detailing what went wrong (usually memory failure)
|
||
|
|
ResultType(SolsNode, charptr) createSolsNode(SolsNodeType type, ...);
|
||
|
|
|
||
|
|
// Adds a child to a SolsNode.
|
||
|
|
// Returns:
|
||
|
|
// Success: Nothing
|
||
|
|
// Failure: char* detailing what went wrong (usually memory failure)
|
||
|
|
ResultType(Nothing, charptr) addChildToSolsNode(SolsNode* parent, SolsNode child);
|
||
|
|
|
||
|
|
#endif
|