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