fancier errors
This commit is contained in:
5
Makefile
5
Makefile
@ -66,7 +66,10 @@ bootstrap:
|
||||
|
||||
test: ${OUT}
|
||||
#fcpp -C -LL debug/xop.eax > debug/xop.eax.pp
|
||||
${WRAP} ./${OUT} debug/xop.eax
|
||||
#${WRAP} ./${OUT} debug/xop.eax
|
||||
${WRAP} ./${OUT} debug/artimetrics.eax
|
||||
@echo " --- ERROR TESTING BEGINS BELOW ---"
|
||||
debug/error_test.sh
|
||||
|
||||
clean:
|
||||
-rm ${OUT} ${OBJECT} ${GENOBJECT} ${GENSOURCE}
|
||||
|
5
debug/error_test.sh
Executable file
5
debug/error_test.sh
Executable file
@ -0,0 +1,5 @@
|
||||
./eaxhla debug/unclosed_program.eax
|
||||
./eaxhla debug/unknown_instruction.eax
|
||||
./eaxhla debug/multi_error.eax
|
||||
./eaxhla debug/unclosed_comment.eax
|
||||
./eaxhla debug/unclosed_artimetric.eax
|
11
debug/multi_error.eax
Normal file
11
debug/multi_error.eax
Normal file
@ -0,0 +1,11 @@
|
||||
program main
|
||||
k8 kek
|
||||
begin
|
||||
wigglecall func
|
||||
xor $rsp $rsp
|
||||
xor $rsp $rsp
|
||||
poke $rsp
|
||||
xor $rsp $rsp
|
||||
xor $rsp $rsp
|
||||
xor $rsp $rsp
|
||||
end program
|
3
debug/unclosed_artimetric.eax
Normal file
3
debug/unclosed_artimetric.eax
Normal file
@ -0,0 +1,3 @@
|
||||
program a
|
||||
begin
|
||||
[
|
4
debug/unclosed_comment.eax
Normal file
4
debug/unclosed_comment.eax
Normal file
@ -0,0 +1,4 @@
|
||||
/*
|
||||
reeeeeeee
|
||||
reeeeeeeee
|
||||
reeeeee
|
4
debug/unclosed_program.eax
Normal file
4
debug/unclosed_program.eax
Normal file
@ -0,0 +1,4 @@
|
||||
unix
|
||||
program main
|
||||
exit 1
|
||||
end rpogram
|
8
debug/unknown_instruction.eax
Normal file
8
debug/unknown_instruction.eax
Normal file
@ -0,0 +1,8 @@
|
||||
procedure a
|
||||
nop
|
||||
end procedure
|
||||
|
||||
unix
|
||||
program main
|
||||
wigglecall a
|
||||
end program
|
@ -11,7 +11,7 @@
|
||||
string_literal_buffer = malloc(128);
|
||||
|
||||
void yyfree_leftovers(void);
|
||||
void yyerror(void);
|
||||
void yyerror(const char * errmsg);
|
||||
%}
|
||||
%option noyywrap
|
||||
|
||||
@ -23,7 +23,7 @@ uhex [0123456789ABCDEF]
|
||||
|
||||
%x IN_COMMENT IN_MULTILINE_COMMENT
|
||||
%x IN_STRING
|
||||
%x IN_END
|
||||
%x IN_END IN_UNKNOWN_END
|
||||
%x IN_ARTIMETRIC_BLOCK
|
||||
|
||||
%option nodefault
|
||||
@ -111,11 +111,15 @@ loop { BEGIN INITIAL; return END_LOOP; }
|
||||
if { BEGIN INITIAL; return END_IF; }
|
||||
machine { BEGIN INITIAL; return END_MACHINE; }
|
||||
{wsnl} { ; }
|
||||
. { yyerror(); }
|
||||
. { yyless(0); BEGIN IN_UNKNOWN_END; }
|
||||
}
|
||||
|
||||
<IN_UNKNOWN_END>{
|
||||
.* { yyerror("unknown end sequence"); BEGIN INITIAL; return 0; }
|
||||
}
|
||||
|
||||
<IN_STRING>{
|
||||
/* XXX: escapes */
|
||||
/* XXX: escapes; multiline strings will die */
|
||||
\" {
|
||||
BEGIN INITIAL;
|
||||
yylval.strval = strdup(string_literal_buffer);
|
||||
@ -136,11 +140,13 @@ machine { BEGIN INITIAL; return END_MACHINE; }
|
||||
<IN_COMMENT>{
|
||||
\n { BEGIN INITIAL; }
|
||||
.* { ; }
|
||||
<<EOF>> { yytext = strdup("<EOF>"); yyerror("unterminated comment"); yyterminate(); }
|
||||
}
|
||||
|
||||
<IN_MULTILINE_COMMENT>{
|
||||
\*\/ { BEGIN INITIAL; }
|
||||
.|\n { ; }
|
||||
<<EOF>> { yytext = strdup("<EOF>"); yyerror("unterminated comment"); yyterminate(); }
|
||||
}
|
||||
|
||||
<INITIAL,IN_ARTIMETRIC_BLOCK>{
|
||||
@ -163,12 +169,13 @@ machine { BEGIN INITIAL; return END_MACHINE; }
|
||||
yylval.intval = strtol(yytext + 2, NULL, 16);
|
||||
return LITERAL;
|
||||
}
|
||||
<<EOF>> { yytext = strdup("<EOF>"); yyerror("unterminated artimetric block"); yyterminate(); }
|
||||
}
|
||||
|
||||
{identifier} { yylval.strval = strdup(yytext); return IDENTIFIER; }
|
||||
{identifier}: { yylval.strval = strdup(yytext); return LABEL; }
|
||||
|
||||
. { yyerror(); }
|
||||
. { yyerror("scanner jammed"); }
|
||||
|
||||
%%
|
||||
|
||||
|
@ -26,10 +26,15 @@
|
||||
#include "assembler.h"
|
||||
|
||||
extern void yyfree_leftovers(void);
|
||||
extern char * yyfilename;
|
||||
|
||||
void yyerror() {
|
||||
printf("\033[31mError: syntax error at line %d near '%s'.\033[0m\n", yylineno, yytext);
|
||||
yyfree_leftovers();
|
||||
void yyerror(const char * errmsg) {
|
||||
printf("\033[1m%s:%d:\033[0m \033[31mError\033[0m: %s near \033[1m'%s'\033[0m.\n",
|
||||
yyfilename,
|
||||
yylineno,
|
||||
errmsg,
|
||||
yytext
|
||||
);
|
||||
}
|
||||
|
||||
long new_static(int size) {
|
||||
@ -38,6 +43,8 @@
|
||||
}
|
||||
%}
|
||||
|
||||
// %define parse.error detailed
|
||||
|
||||
%union{
|
||||
long intval;
|
||||
char * strval;
|
||||
@ -121,6 +128,7 @@ function_specifier: %empty
|
||||
|
||||
declaration_section: %empty
|
||||
| declaration declaration_section
|
||||
| error declaration_section { yyerrok; }
|
||||
;
|
||||
|
||||
declaration: origin type IDENTIFIER { $2.name = $3; /* add_var($1); */ free($3); }
|
||||
@ -143,6 +151,7 @@ type: S8 { $$ = (static_variable){ .is_signed = 1, .size = 8, .address = new
|
||||
;
|
||||
|
||||
code: %empty
|
||||
| error code { yyerrok; }
|
||||
| loop code
|
||||
| if code
|
||||
| call code
|
||||
@ -239,7 +248,7 @@ immediate: LITERAL
|
||||
artimetric_block: '[' artimetric_expression ']' { $$ = $2; }
|
||||
;
|
||||
|
||||
artimetric_expression: %empty { yyerror(); }
|
||||
artimetric_expression: %empty { YYERROR; }
|
||||
| artimetric_operand
|
||||
| artimetric_expression '+' artimetric_operand { $$ = $1 + $3; }
|
||||
| artimetric_expression '-' artimetric_operand { $$ = $1 - $3; }
|
||||
@ -257,3 +266,5 @@ exit: EXIT immediate
|
||||
| EXIT IDENTIFIER
|
||||
;
|
||||
%%
|
||||
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
extern void yyfree_leftovers(void);
|
||||
|
||||
char * yyfilename;
|
||||
|
||||
signed main(int argc, char * argv[]) {
|
||||
if (argc < 2) {
|
||||
printf("%s: <file>\n", argv[0]);
|
||||
@ -14,7 +16,9 @@ signed main(int argc, char * argv[]) {
|
||||
yydebug = 1;
|
||||
#endif
|
||||
|
||||
yyin = fopen(argv[1], "r");
|
||||
yyfilename = argv[1];
|
||||
|
||||
yyin = fopen(yyfilename, "r");
|
||||
yyparse();
|
||||
|
||||
yyfree_leftovers();
|
||||
|
Reference in New Issue
Block a user