add mulitple variable declaration, with null default. add call

This commit is contained in:
2025-06-05 04:04:41 +01:00
parent 7b76b0d888
commit 61d8bc61c3
14 changed files with 186 additions and 111 deletions

View File

@@ -108,7 +108,7 @@ int yywrap(void * unused_param) {
. {
GET_STATE
fprintf(stderr, "%s:%u:%u error: unexpected character '%s'\n", state->path, yylineno, COLUMN_NO+1, yytext);
fprintf(stderr, "%s:%zu:%zu error: unexpected character '%s'\n", state->path, state->current_line+1, COLUMN_NO+1, yytext);
exit(1);
}
%%

View File

@@ -13,11 +13,12 @@ void lexer(LexerState state) {
int token;
while ((token = yylex(scanner)) != 0) {
Token *token_struct =
create_token(token, yyget_lineno(scanner), state.current_column + 1,
create_token(token, state.current_line+1, state.current_column + 1,
yyget_text(scanner));
darray_push(state.tokens, token_struct);
free(token_struct);
if (token == TOKEN_NEW_LINE) {
state.current_line += 1;
state.current_column = 0;
} else {
state.current_column += yyget_leng(scanner);

View File

@@ -8,7 +8,8 @@
typedef struct {
const char *path;
FILE *file;
int current_column;
size_t current_line;
size_t current_column;
DArray *tokens;
// add more fields as needed
} LexerState;

View File

@@ -1,6 +1,7 @@
#ifndef TOKEN_H
#define TOKEN_H
#include <stddef.h>
typedef enum {
TOKEN_STRING = 256,
TOKEN_NUMBER,
@@ -76,8 +77,8 @@ typedef enum {
typedef struct {
TokenType type;
int line;
int column;
size_t line;
size_t column;
char *value;
} Token;