Created a tokenizer and the supporting code, currently processes text that is not a string literal.

This commit is contained in:
2025-01-07 23:52:03 -06:00
parent 2c85077031
commit 7e70c6fd19
10 changed files with 351 additions and 12 deletions
+15 -7
View File
@@ -1,11 +1,17 @@
#ifndef TOKEN_H
#define TOKEN_H
enum TokenType {
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
typedef enum {
Empty,
String,
Number,
Symbol,
LineEnd = '\n',
Plus = '+',
Minus = '-',
Star = '*',
@@ -13,23 +19,25 @@ enum TokenType {
Carot = '^',
OpenParen = '(',
CloseParen = ')',
OpenBracket = '[',
CloseBracket = ']',
FileEnd
};
} TokenType;
typedef struct _token {
TokenType Type;
char* Name;
union {
char Operator[8];
char* String;
int Number;
} Value;
int LineNumber;
int ColumnNumber;
int Index;
int Length;
int Resolved;
bool Resolved;
} Token;
Token* TokenCreate(char* name, TokenType type, int lineNumber, int columnNumber, int index, int length, int resolved);
Token* TokenCreate(TokenType type, int lineNumber, int columnNumber, bool resolved);
char* TokenStringify(const Token* token, bool valueOnly);
int StringifyTokenType(TokenType type, char buffer[32]);
#endif