aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/lexer.c8
-rwxr-xr-xsrc/main.c2
2 files changed, 8 insertions, 2 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 6e8c08d..3d9f538 100755
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <stdio.h>
lexer_t* lexer_init(char* content) {
lexer_t* lexer = calloc(1, sizeof(struct LEXER_STRUC));
@@ -39,6 +40,9 @@ token_t* lexer_get_next_token(lexer_t* lexer) {
lexer_pass(lexer);
}
+ if (isalnum(lexer->c))
+ return lexer_get_id(lexer);
+
switch (lexer->c) {
case '"': return lexer_get_string(lexer); break;
case '=': return lexer_next_token(
@@ -133,6 +137,8 @@ token_t* lexer_get_id(lexer_t* lexer) {
lexer_next(lexer);
}
+ lexer_next(lexer);
+
return token_init(TOKEN_ID, str_so_far);
}
@@ -143,7 +149,7 @@ token_t* lexer_next_token(lexer_t* lexer, token_t* token) {
}
char* lexer_get_c_as_string(lexer_t* lexer) {
- char* str = calloc(1, sizeof(char));
+ char* str = calloc(2, sizeof(char));
str[0] = lexer->c;
str[1] = '\0';
diff --git a/src/main.c b/src/main.c
index 45ee0c6..e8c6a9d 100755
--- a/src/main.c
+++ b/src/main.c
@@ -3,7 +3,7 @@
int main(int argc, char* argv[]) {
lexer_t* lexer = lexer_init(
- "[nice & simple]\nlet it = \"Hello, World!\";\nsay it;\n"
+ "Let it = \"Hello, World!\";\nsay it;"
);
printf("\n=== INPUT =======\n%s\n=== END INPUT ===\n", lexer->content);