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"
|
#include "lexer.h"
|
||||||
|
|
||||||
Token *lexer(char *buf){
|
Token *lexer(char *buf)
|
||||||
|
{
|
||||||
char *current = strdup(buf);
|
char *current = strdup(buf);
|
||||||
int current_index = 0, tokens_index = 0;
|
int current_index = 0, tokens_index = 0;
|
||||||
|
|
||||||
Token *tokens = malloc(sizeof(Token) * 1024);
|
Token *tokens = malloc(sizeof(Token) * 1024);
|
||||||
while(current[current_index] != '\0'){
|
while(current[current_index] != '\0') {
|
||||||
Token *token = NULL;
|
Token *token = NULL;
|
||||||
if(current[current_index] == ';'){
|
if(current[current_index] == ';') {
|
||||||
token = malloc(sizeof(Token));
|
token = malloc(sizeof(Token));
|
||||||
char *value = malloc(2 * sizeof(char));
|
char *value = malloc(2 * sizeof(char));
|
||||||
value[0] = current[current_index];
|
value[0] = current[current_index];
|
||||||
|
@ -22,7 +23,7 @@ Token *lexer(char *buf){
|
||||||
tokens[tokens_index] = *token;
|
tokens[tokens_index] = *token;
|
||||||
tokens_index++;
|
tokens_index++;
|
||||||
printf("FOUND SEMICOLON\n");
|
printf("FOUND SEMICOLON\n");
|
||||||
} else if(current[current_index] == '('){
|
} else if(current[current_index] == '(') {
|
||||||
token = malloc(sizeof(Token));
|
token = malloc(sizeof(Token));
|
||||||
char *value = malloc(2 * sizeof(char));
|
char *value = malloc(2 * sizeof(char));
|
||||||
value[0] = current[current_index];
|
value[0] = current[current_index];
|
||||||
|
@ -32,7 +33,7 @@ Token *lexer(char *buf){
|
||||||
tokens[tokens_index] = *token;
|
tokens[tokens_index] = *token;
|
||||||
tokens_index++;
|
tokens_index++;
|
||||||
printf("FOUND OPEN PAREN\n");
|
printf("FOUND OPEN PAREN\n");
|
||||||
} else if(current[current_index] == ')'){
|
} else if(current[current_index] == ')') {
|
||||||
token = malloc(sizeof(Token));
|
token = malloc(sizeof(Token));
|
||||||
char *value = malloc(2 * sizeof(char));
|
char *value = malloc(2 * sizeof(char));
|
||||||
value[0] = current[current_index];
|
value[0] = current[current_index];
|
||||||
|
@ -42,12 +43,12 @@ Token *lexer(char *buf){
|
||||||
tokens[tokens_index] = *token;
|
tokens[tokens_index] = *token;
|
||||||
tokens_index++;
|
tokens_index++;
|
||||||
printf("FOUND CLOSE PAREN\n");
|
printf("FOUND CLOSE PAREN\n");
|
||||||
} else if(isdigit(current[current_index])){
|
} else if(isdigit(current[current_index])) {
|
||||||
token = generate_number(current, ¤t_index);
|
token = generate_number(current, ¤t_index);
|
||||||
tokens[tokens_index] = *token;
|
tokens[tokens_index] = *token;
|
||||||
tokens_index++;
|
tokens_index++;
|
||||||
current_index--;
|
current_index--;
|
||||||
} else if(isalpha(current[current_index])){
|
} else if(isalpha(current[current_index])) {
|
||||||
token = generate_keyword(current, ¤t_index);
|
token = generate_keyword(current, ¤t_index);
|
||||||
tokens[tokens_index] = *token;
|
tokens[tokens_index] = *token;
|
||||||
tokens_index++;
|
tokens_index++;
|
||||||
|
|
Loading…
Reference in a new issue