wraith-lang/src/ast.h

181 lines
3.2 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-28 19:49:45 +00:00
AllocExpression,
2021-04-16 07:35:35 +00:00
Assignment,
BinaryExpression,
Comment,
2021-04-24 19:59:30 +00:00
CustomTypeNode,
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,
2021-04-22 07:35:42 +00:00
FunctionModifiers,
2021-04-18 20:14:50 +00:00
FunctionSignature,
2021-04-20 01:18:45 +00:00
FunctionSignatureArguments,
2021-04-16 07:35:35 +00:00
Identifier,
Number,
2021-04-24 19:59:30 +00:00
PrimitiveTypeNode,
ReferenceTypeNode,
2021-04-16 07:35:35 +00:00
Return,
2021-04-21 02:00:18 +00:00
ReturnVoid,
2021-04-18 20:14:50 +00:00
StatementSequence,
2021-04-22 07:35:42 +00:00
StaticModifier,
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-24 19:59:30 +00:00
String
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;
2021-04-24 19:59:30 +00:00
PrimitiveType primitiveType;
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-24 19:59:30 +00:00
uint8_t IsPrimitiveType(Node *typeNode);
Node* MakePrimitiveTypeNode(
2021-04-18 20:14:50 +00:00
PrimitiveType type
2021-04-18 22:29:54 +00:00
);
2021-04-21 06:51:26 +00:00
Node* MakeCustomTypeNode(
2021-04-24 19:59:30 +00:00
char *string
);
Node* MakeReferenceTypeNode(
Node *typeNode
);
Node* MakeTypeNode(
Node *typeNode /* can be primitive, custom, or reference */
2021-04-21 06:51:26 +00:00
);
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-22 07:35:42 +00:00
Node* MakeStaticNode();
Node* MakeFunctionModifiersNode(
Node **pModifierNodes,
uint32_t modifierCount
);
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,
2021-04-22 07:35:42 +00:00
Node* arguments,
Node* modifiersNode
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-28 19:49:45 +00:00
Node* MakeAllocNode(
Node *typeNode
);
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 */