slr

S Lang Runtime
git clone https://codeberg.org/night0721/slr
Log | Files | Refs | README | LICENSE

commit e65557d40df45f27caa8177cd31f88c5f0611eec
parent 931d14f35fdf2bcee913bcdeeb497aaa14242ad8
Author: night0721 <[email protected]>
Date:   Sat, 18 May 2024 19:07:13 +0100

format

Diffstat:
Mlexer.c | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/lexer.c b/lexer.c @@ -5,14 +5,15 @@ #include "lexer.h" -Token *lexer(char *buf){ +Token *lexer(char *buf) +{ char *current = strdup(buf); int current_index = 0, tokens_index = 0; Token *tokens = malloc(sizeof(Token) * 1024); - while(current[current_index] != '\0'){ + while(current[current_index] != '\0') { Token *token = NULL; - if(current[current_index] == ';'){ + if(current[current_index] == ';') { token = malloc(sizeof(Token)); char *value = malloc(2 * sizeof(char)); value[0] = current[current_index]; @@ -22,7 +23,7 @@ Token *lexer(char *buf){ tokens[tokens_index] = *token; tokens_index++; printf("FOUND SEMICOLON\n"); - } else if(current[current_index] == '('){ + } else if(current[current_index] == '(') { token = malloc(sizeof(Token)); char *value = malloc(2 * sizeof(char)); value[0] = current[current_index]; @@ -32,7 +33,7 @@ Token *lexer(char *buf){ tokens[tokens_index] = *token; tokens_index++; printf("FOUND OPEN PAREN\n"); - } else if(current[current_index] == ')'){ + } else if(current[current_index] == ')') { token = malloc(sizeof(Token)); char *value = malloc(2 * sizeof(char)); value[0] = current[current_index]; @@ -42,12 +43,12 @@ Token *lexer(char *buf){ tokens[tokens_index] = *token; tokens_index++; printf("FOUND CLOSE PAREN\n"); - } else if(isdigit(current[current_index])){ + } else if(isdigit(current[current_index])) { token = generate_number(current, &current_index); tokens[tokens_index] = *token; tokens_index++; current_index--; - } else if(isalpha(current[current_index])){ + } else if(isalpha(current[current_index])) { token = generate_keyword(current, &current_index); tokens[tokens_index] = *token; tokens_index++;