X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/08ac16e49d67a40f0f8127cf43f8a166626615dc..1b9e87d8cac4e24034cb4d8f5c42824bac507772:/src/parse.y diff --git a/src/parse.y b/src/parse.y index 8764159..9c644da 100644 --- a/src/parse.y +++ b/src/parse.y @@ -18,7 +18,8 @@ */ } -%parse-param {yyscan_t scanner} +%name-prefix "cdecl__yy" +%parse-param {void *scanner} %parse-param {struct cdecl **out} %lex-param {yyscan_t scanner} %define api.pure @@ -26,10 +27,12 @@ %locations %{ +#include #include #include #include "scan.h" +#include "error.h" #include "cdecl.h" #define FAIL(msg) do { \ @@ -54,8 +57,9 @@ } %code provides { -void yyerror(YYLTYPE *, void *, struct cdecl **, const char *); -int yyparse(void *scanner, struct cdecl **out); +void cdecl__free(struct cdecl *); +void cdecl__yyerror(YYLTYPE *, void *, struct cdecl **, const char *); +int cdecl__yyparse(void *scanner, struct cdecl **out); } %union { @@ -129,7 +133,7 @@ static void free_decl(struct cdecl *x) } } -void cdecl_free(struct cdecl *decl) +void cdecl__free(struct cdecl *decl) { free_decl(decl); } @@ -232,7 +236,9 @@ input: T_ENGLISH english { *out = $1; }; -declaration: declspecs declarators T_SEMICOLON { +semi: | T_SEMICOLON + +declaration: declspecs declarators semi { $$ = $2; for (struct cdecl *i = $$; i; i = i->next) @@ -449,7 +455,7 @@ type_qual_specs: { $$ = NULL; } | type_qual_spec type_qual_specs { post_specs: qualifiers typespec type_qual_specs { $$ = $2; $$->next = $1; - for (struct cdecl_declspec *s = $1; s; s = s->next) { + for (struct cdecl_declspec *s = $$; s; s = s->next) { if (!s->next) { s->next = $3; break; @@ -574,11 +580,13 @@ english_vla: T_IDENT | { %% void -yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, - const char *err) +yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err) { if (strstr(err, "T_LEX_ERROR")) return; - fprintf(stderr, "%s\n", err); + cdecl__set_error(&(const struct cdecl_error){ + .code = CDECL_ENOPARSE, + .str = err, + }); }