vc3/asm/lex.h
2025-04-02 17:00:43 +02:00

56 lines
947 B
C

#pragma once
#include "report.h"
#include <stdbool.h>
#include <stddef.h>
typedef enum {
TT_Err,
TT_Eof,
TT_Ident,
TT_Int,
TT_Binary,
TT_Hex,
TT_Char,
TT_Str,
TT_Newline = '\n',
TT_DoubleLt,
TT_DoubleGt,
TT_Pipe = '|',
TT_Hat = '^',
TT_Ampersand = '&',
TT_Plus = '+',
TT_Minus = '-',
TT_Asterisk = '*',
TT_Slash = '/',
TT_Percent = '%',
TT_LParen = '(',
TT_RParen = ')',
TT_LBracket = '[',
TT_RBracket = ']',
TT_Dot = '.',
TT_Comma = ',',
TT_Colon = ':',
TT_Exclamation = '!',
} TokTy;
typedef struct {
TokTy ty;
Loc loc;
size_t len;
} Tok;
typedef struct {
const char* filename;
const char* text;
size_t text_len;
size_t idx;
int line;
int col;
char ch;
bool error_occured;
} Lexer;
void lexer_construct(Lexer* lexer, const char* filename, const char* text);
Tok lexer_next(Lexer* lexer);