Wrote a basic lexer

This commit is contained in:
2022-08-03 09:35:20 +01:00
parent 3cbf7b13eb
commit 3cad70dddd
12 changed files with 884 additions and 0 deletions

24
source/lexer.h Normal file
View File

@@ -0,0 +1,24 @@
#pragma once
#include "common.h"
#include "token_types.h"
//lexers are bound to a string of code, and return a single token every time scan is called
typedef struct {
char* source;
int start; //start of the token
int current; //current position of the lexer
int line; //track this for error handling
} Lexer;
//tokens are intermediaries between lexers and parsers
typedef struct {
TokenType type;
char* lexeme;
int length;
int line;
} Token;
void initLexer(Lexer* lexer, char* source);
Token scanLexer(Lexer* lexer);