wraith-lang/ast.h

160 lines
2.7 KiB
C
Raw Normal View History

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