format
This commit is contained in:
parent
931d14f35f
commit
e65557d40d
1 changed files with 8 additions and 7 deletions
15
lexer.c
15
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, ¤t_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, ¤t_index);
|
||||
tokens[tokens_index] = *token;
|
||||
tokens_index++;
|
||||
|
|
Loading…
Reference in a new issue