diff --git a/source/eaxhla.l b/source/eaxhla.l index b406c89..3c3570b 100644 --- a/source/eaxhla.l +++ b/source/eaxhla.l @@ -8,6 +8,9 @@ #define YY_USER_INIT \ string_literal_buffer = malloc(128); + + void yyfree_leftovers(void); + void yyerror(void); %} %option noyywrap @@ -70,21 +73,22 @@ u32{wsnl}+ { return U32; } u64{wsnl}+ { return U64; } -?[[:digit:]]+ { - sscanf(yytext, "%d", &yylval.intval); + yylval.intval = strtol(yytext, NULL, 10); return LITERAL; } 0b[01]+ { + yylval.intval = strtol(yytext, NULL, 2); return LITERAL; } 0x{hex}+ { - sscanf(yytext + 2, "%x", &yylval.intval); + yylval.intval = strtol(yytext + 2, NULL, 16); return LITERAL; } 0x{uhex}+ { - sscanf(yytext + 2, "%X", &yylval.intval); + yylval.intval = strtol(yytext + 2, NULL, 16); return LITERAL; } @@ -95,15 +99,18 @@ u64{wsnl}+ { return U64; } \" { BEGIN INITIAL; yylval.strval = strdup(string_literal_buffer); + puts(string_literal_buffer); return LITERAL; } . { string_litral_buffer_size += yyleng; if (string_litral_buffer_size > string_litral_buffer_capacity) { string_litral_buffer_capacity *= 2; - realloc(string_literal_buffer, string_litral_buffer_capacity); + void * ignore = realloc(string_literal_buffer, string_litral_buffer_capacity); + (void)ignore; } memcpy(string_literal_buffer + string_litral_buffer_size, yytext, yyleng); + puts(string_literal_buffer); } } @@ -153,5 +160,11 @@ void yyfree_leftovers(void) { free(yy_buffer_stack[i]); } + //yy_delete_buffer(b); + + if (yyin) { + fclose(yyin); + } + free(string_literal_buffer); } diff --git a/source/eaxhla.y b/source/eaxhla.y index f30ca8a..0b36c6a 100644 --- a/source/eaxhla.y +++ b/source/eaxhla.y @@ -23,6 +23,8 @@ #include "eaxhla.yy.h" #include "assembler.h" + extern void yyfree_leftovers(void); + void yyerror() { printf("\033[31mError: syntax error at line %d near '%s'.\033[0m\n", yylineno, yytext); yyfree_leftovers(); @@ -31,12 +33,13 @@ extern void set_state(int state); long new_static(int size) { + (void)size; return 0; } %} %union{ - int intval; + long intval; char * strval; static_variable varval; } @@ -58,6 +61,7 @@ %token IDENTIFIER %token LITERAL +%token STRING_LITERAL %token FAST @@ -110,6 +114,7 @@ declaration_section: %empty declaration: origin type IDENTIFIER { $2.name = $3; /* add_var($1); */ free($3); } | origin type IDENTIFIER '=' LITERAL { $2.name = $3; /* add_var($1); */ free($3); } + | origin type IDENTIFIER '=' STRING_LITERAL { $2.name = $3; /* add_var($1); */ free($3); free($5); } ; origin: %empty @@ -144,7 +149,7 @@ loop: TLOOP code END_LOOP if: IF logic THEN code END_IF ; -logic: +logic: %empty /* XXX */ ; call: calltype IDENTIFIER arguments { free($2); } @@ -163,6 +168,6 @@ register: RAX { $$ = R0; } | RBX { $$ = R1; } ; -immediate: LITERAL { printf("%d", yylval.intval); } +immediate: LITERAL ; %%