aboutsummaryrefslogtreecommitdiff
path: root/src/compiler/lexer/lexer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/lexer/lexer.h')
-rw-r--r--src/compiler/lexer/lexer.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/compiler/lexer/lexer.h b/src/compiler/lexer/lexer.h
new file mode 100644
index 0000000..7d60101
--- /dev/null
+++ b/src/compiler/lexer/lexer.h
@@ -0,0 +1,66 @@
+#pragma once
+
+#include <stddef.h>
+#include <utils/memory/memory.h>
+#include <utils/types.h>
+
+typedef enum Token {
+ TOKEN_NONE = 0,
+ TOKEN_IDENTIFIER,
+ TOKEN_KEYWORD_PRINT,
+ TOKEN_NUMBER,
+ TOKEN_STRING,
+ TOKEN_OPERATOR,
+ TOKEN_OPERATOR_PARENTHESES_OPEN,
+ TOKEN_OPERATOR_PARENTHESES_CLOSE,
+ TOKEN_OPERATOR_CURLY_BRACKET_OPEN,
+ TOKEN_OPERATOR_CURLY_BRACKET_CLOSE,
+ TOKEN_OPERATOR_ASSIGN,
+ TOKEN_OPERATOR_EQUAL,
+ TOKEN_OPERATOR_COLON,
+ TOKEN_OPERATOR_EOL,
+ TOKEN_SYMBOL,
+ TOKEN_PARSED,
+} Token;
+
+extern const char *TOKEN_STRINGS[];
+
+typedef struct Node {
+ char const *strBegin;
+ char const *strEnd;
+ Token token;
+ void *parsedNode;
+} Node;
+
+typedef struct Nodes {
+ Node *nodes;
+ size_t size;
+} Nodes;
+
+extern void printNodes(Nodes nodes);
+
+extern void deleteNodes(Nodes nodes);
+
+extern Nodes lexer(char const *restrict str);
+
+extern void push_if_not_empty(Node **restrict nodes,
+ size_t *restrict nodes_size,
+ size_t *restrict nodes_inserted,
+ Node *restrict node, char const *restrict str,
+ int i, Token token);
+extern void push_clear_without_check(Node **restrict nodes,
+ size_t *restrict nodes_size,
+ size_t *restrict nodes_inserted,
+ Node *node, char const *restrict str,
+ int i, Token token);
+
+extern bool isSpace(char c);
+extern bool isIdentifier(char c);
+extern bool isIdentifierSymbol(char c);
+extern bool isNumber(char c);
+extern bool isString(char c);
+extern bool isOperator(char c);
+extern bool isSymbol(char c);
+
+extern Token getKeyword(char const *strBegin, char const *strEnd);
+extern Token getOperator(char const *strBegin, char const *strEnd);