wraith-lang/ast.h

160 lines
2.7 KiB
C

#ifndef WRAITH_AST_H
#define WRAITH_AST_H
#include <stdint.h>
typedef enum
{
AccessExpression,
Assignment,
BinaryExpression,
Comment,
Declaration,
DeclarationSequence,
Expression,
ForLoop,
FunctionArgumentSequence,
FunctionCallExpression,
FunctionDeclaration,
FunctionSignature,
FunctionSignatureArguments,
Identifier,
Number,
Return,
ReturnVoid,
StatementSequence,
StringLiteral,
StructDeclaration,
Type,
UnaryExpression
} SyntaxKind;
typedef enum
{
Negate
} UnaryOperator;
typedef enum
{
Add,
Subtract,
Multiply
} BinaryOperator;
typedef enum
{
Void,
Bool,
Int,
UInt,
Float,
Double,
String,
CustomType
} PrimitiveType;
typedef union
{
UnaryOperator unaryOperator;
BinaryOperator binaryOperator;
} Operator;
typedef struct Node
{
SyntaxKind syntaxKind;
struct Node **children;
uint32_t childCount;
union
{
UnaryOperator unaryOperator;
BinaryOperator binaryOperator;
} operator;
union
{
char *string;
uint64_t number;
} value;
PrimitiveType type;
} Node;
char* strdup (const char* s);
const char* SyntaxKindString(SyntaxKind syntaxKind);
Node* MakeTypeNode(
PrimitiveType type
);
Node* MakeCustomTypeNode(
Node *identifierNode
);
Node* MakeIdentifierNode(
const char *id
);
Node* MakeNumberNode(
const char *numberString
);
Node* MakeStringNode(
const char *string
);
Node* MakeUnaryNode(
UnaryOperator operator,
Node *child
);
Node* MakeBinaryNode(
BinaryOperator operator,
Node *left,
Node *right
);
Node* MakeDeclarationNode(
Node* typeNode,
Node* identifierNode
);
Node* MakeAssignmentNode(
Node *left,
Node *right
);
Node* MakeStatementSequenceNode(
Node** pNodes,
uint32_t nodeCount
);
Node* MakeReturnStatementNode(
Node *expressionNode
);
Node* MakeReturnVoidStatementNode();
Node* MakeFunctionSignatureArgumentsNode(
Node **pArgumentNodes,
uint32_t argumentCount
);
Node* MakeFunctionSignatureNode(
Node *identifierNode,
Node* typeNode,
Node* arguments
);
Node* MakeFunctionDeclarationNode(
Node* functionSignatureNode,
Node* functionBodyNode
);
Node* MakeStructDeclarationNode(
Node *identifierNode,
Node *declarationSequenceNode
);
Node* MakeDeclarationSequenceNode(
Node **pNodes,
uint32_t nodeCount
);
Node *MakeFunctionArgumentSequenceNode(
Node **pArgumentNodes,
uint32_t argumentCount
);
Node* MakeFunctionCallExpressionNode(
Node *identifierNode,
Node *argumentSequenceNode
);
Node* MakeAccessExpressionNode(
Node *accessee,
Node *accessor
);
void PrintTree(Node *node, uint32_t tabCount);
#endif /* WRAITH_AST_H */