Updated the project structure, and modified the Makefile to hopefully be future proof so I can freely make sub-folders in the src/ folder and not have to worry about breaking the Makefile.
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
#ifndef TOKEN_H
|
||||
#define TOKEN_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define TOKENTYPE_MAPPINGS_COUNT 34
|
||||
|
||||
typedef enum {
|
||||
//Single-character tokens
|
||||
LParen, RParen,
|
||||
LBrace, RBrace,
|
||||
Comma,
|
||||
Dot,
|
||||
Minus, Plus,
|
||||
Semicolon,
|
||||
Slash, Star,
|
||||
//One or two character tokens
|
||||
Bang, Bang_Equal,
|
||||
Equal, Equal_Equal,
|
||||
Greater, Greater_Equal,
|
||||
Less, Less_Equal,
|
||||
//Literals
|
||||
Identifier,
|
||||
String,
|
||||
Number,
|
||||
//Keywords
|
||||
AND, CLASS, ELSE, FALSE, FUN,
|
||||
FOR, IF, NIL, OR, PRINT, RETURN,
|
||||
SUPER, THIS, TRUE, VAR, WHILE,
|
||||
|
||||
EndOF
|
||||
} TokenType;
|
||||
|
||||
typedef struct {
|
||||
const char* lexeme;
|
||||
TokenType type;
|
||||
} KeyValuePair;
|
||||
|
||||
typedef struct {
|
||||
TokenType type;
|
||||
const char* lexeme;
|
||||
const void* literal;
|
||||
int line;
|
||||
} Token;
|
||||
|
||||
extern KeyValuePair TokenTypeMappings[TOKENTYPE_MAPPINGS_COUNT];
|
||||
|
||||
//If the first parameter is NULL, the token creation will attempt to infer the lexeme from the TokenType.
|
||||
Token* CreateToken(const char*, void*, int, TokenType);
|
||||
char* GetTokenStringValue(Token*, int*);
|
||||
int GetTokenNumberValue(Token*, double*);
|
||||
void FreeToken(Token*);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user