diff --git a/src/tools/ainedit/asm_lexer.l b/src/tools/ainedit/asm_lexer.l index 9c58bb0..a22ca41 100644 --- a/src/tools/ainedit/asm_lexer.l +++ b/src/tools/ainedit/asm_lexer.l @@ -28,6 +28,9 @@ char string_buf[65536]; char *string_buf_ptr; +unsigned long asm_line = 1; +extern void yyerror(const char *s); + %} %option noyywrap @@ -39,8 +42,8 @@ id_char [^ \t\r\n:;\"] %% [ \t] ; -;[^\n]*\n return NEWLINE; -\n return NEWLINE; +;[^\n]*\n asm_line++; return NEWLINE; +\n asm_line++; return NEWLINE; [a-zA-Z0-9_-]+: yylval.string = make_string(yytext, yyleng-1); return LABEL; ({id_char}|:)*{id_char}+ yylval.string = make_string(yytext, yyleng); return IDENTIFIER; @@ -55,7 +58,7 @@ id_char [^ \t\r\n:;\"] return IDENTIFIER; } - \n ERROR("Unterminated string literal"); + \n yyerror("Unterminated string literal"); \\n *string_buf_ptr++ = '\n'; \\t *string_buf_ptr++ = '\t'; @@ -72,4 +75,6 @@ id_char [^ \t\r\n:;\"] } } +. return INVALID_TOKEN; + %% diff --git a/src/tools/ainedit/asm_parser.y b/src/tools/ainedit/asm_parser.y index 1afc7d6..43bb94a 100644 --- a/src/tools/ainedit/asm_parser.y +++ b/src/tools/ainedit/asm_parser.y @@ -37,7 +37,15 @@ #include "system4/string.h" extern int yylex(); -void yyerror(const char *s) { ERROR("%s", s); } +extern unsigned long asm_line; + +#define PARSE_ERROR(fmt, ...) \ + sys_error("ERROR: At line %d: " fmt "\n", asm_line-1, ##__VA_ARGS__) + +void yyerror(const char *s) +{ + sys_error("ERROR: At line %d: %s\n", asm_line, s); +} static uint32_t instr_ptr; @@ -63,7 +71,7 @@ static struct parse_instruction *make_instruction(struct string *name, parse_arg // check opcode const struct instruction *info = asm_get_instruction(name->text); if (!info) - ERROR("Invalid instruction: %s", name->text); + PARSE_ERROR("Invalid instruction: %s", name->text); // check argument count size_t nr_args = args ? kv_size(*args) : 0; if (nr_args != (size_t)info->nr_args) { @@ -72,8 +80,8 @@ static struct parse_instruction *make_instruction(struct string *name, parse_arg fprintf(stderr, " %s", kv_A(*args, i)->text); } fprintf(stderr, "'\n"); - ERROR("Wrong number of arguments for instruction '%s' (expected %d; got %lu)", - name->text, info->nr_args, nr_args); + PARSE_ERROR("Wrong number of arguments for instruction '%s' (expected %d; got %lu)", + name->text, info->nr_args, nr_args); } // NOTE: argument values checked on second pass @@ -112,7 +120,7 @@ static void push_label(char *name) %} %token IDENTIFIER LABEL -%token NEWLINE +%token NEWLINE INVALID_TOKEN %type lines %type line diff --git a/src/tools/ainedit/text_lexer.l b/src/tools/ainedit/text_lexer.l index 52511c6..4da6556 100644 --- a/src/tools/ainedit/text_lexer.l +++ b/src/tools/ainedit/text_lexer.l @@ -28,6 +28,9 @@ char string_buf[65536]; char *string_buf_ptr; +unsigned long text_line = 1; +extern void text_error(const char *s); + %} %option noyywrap @@ -38,8 +41,8 @@ char *string_buf_ptr; %% [ \t] ; -;[^\n]*\n return NEWLINE; -\n return NEWLINE; +;[^\n]*\n text_line++; return NEWLINE; +\n text_line++; return NEWLINE; \[ return LBRACKET; \] return RBRACKET; = return EQUAL; @@ -59,7 +62,7 @@ s return STRINGS; return STRING; } - \n ERROR("Unterminated string literal"); + \n text_error("Unterminated string literal"); \\n *string_buf_ptr++ = '\n'; \\t *string_buf_ptr++ = '\t'; @@ -76,4 +79,6 @@ s return STRINGS; } } +. return INVALID_TOKEN; + %% diff --git a/src/tools/ainedit/text_parser.y b/src/tools/ainedit/text_parser.y index adccc42..ff3c446 100644 --- a/src/tools/ainedit/text_parser.y +++ b/src/tools/ainedit/text_parser.y @@ -30,7 +30,12 @@ #include "system4/string.h" extern int text_lex(); -void text_error(const char *s) { ERROR("%s", s); } +extern unsigned long text_line; + +void text_error(const char *s) +{ + sys_error("ERROR: At line %lu: %s\n", text_line, s); +} static assignment_list *make_program(void) { @@ -55,7 +60,7 @@ static struct text_assignment *make_assignment(int type, int index, struct strin %} -%token NEWLINE LBRACKET RBRACKET EQUAL MESSAGES STRINGS +%token NEWLINE LBRACKET RBRACKET EQUAL MESSAGES STRINGS INVALID_TOKEN %token NUMBER %token STRING diff --git a/src/tools/ex/ex_lexer.l b/src/tools/ex/ex_lexer.l index 44bac0a..de3f6bf 100644 --- a/src/tools/ex/ex_lexer.l +++ b/src/tools/ex/ex_lexer.l @@ -41,6 +41,7 @@ struct string *make_string_from_utf8(const char *str, size_t len) } unsigned long yex_line = 1; +extern void yex_error(const char *s); %} @@ -90,7 +91,7 @@ tree return TREE; return CONST_STRING; } - \n ERROR("Unterminated string literal"); + \n yex_error("Unterminated string literal"); \\n *string_buf_ptr++ = '\n'; \\t *string_buf_ptr++ = '\t'; diff --git a/src/tools/ex/ex_parser.y b/src/tools/ex/ex_parser.y index 7a12712..20f80fd 100644 --- a/src/tools/ex/ex_parser.y +++ b/src/tools/ex/ex_parser.y @@ -43,7 +43,11 @@ extern int yex_lex(); extern unsigned long yex_line; -void yex_error(const char *s) { ERROR("at line %lu: %s", yex_line, s); } + +void yex_error(const char *s) +{ + sys_error("ERROR: at line %lu: %s\n", yex_line, s); +} %}