%code top {
/*
* Parser for C declarations.
- * Copyright © 2011 Nick Bowler
+ * Copyright © 2011-2012, 2021 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
%name-prefix "cdecl__yy"
-%parse-param {yyscan_t scanner}
+%parse-param {void *scanner}
%parse-param {struct cdecl **out}
%lex-param {yyscan_t scanner}
%define api.pure
%locations
%{
+#include <config.h>
#include <assert.h>
#include <stdbool.h>
#include "scan.h"
#include "cdecl.h"
+#include "cdecl-internal.h"
#define FAIL(msg) do { \
yyerror(&yylloc, NULL, NULL, msg); \
}
%code provides {
+void cdecl__free(struct cdecl *);
void cdecl__yyerror(YYLTYPE *, void *, struct cdecl **, const char *);
int cdecl__yyparse(void *scanner, struct cdecl **out);
}
%union {
uintmax_t uintval;
+ unsigned spectype;
_Bool boolval;
char *strval;
struct cdecl_declspec *declspec;
}
}
-void cdecl_free(struct cdecl *decl)
+void cdecl__free(struct cdecl *decl)
{
free_decl(decl);
}
%type <strval> vla_ident
%type <boolval> varargs
-%type <uintval> declspec_simple typespec_simple qualifier_simple
+%type <spectype> declspec_simple typespec_simple qualifier_simple
%type <declspec> declspec_notype declspec_noid typespec_noid typespec
%type <declspec> qualifier qualifiers
%type <declspec> declspecs declspecs_noid
*out = $1;
};
-declaration: declspecs declarators T_SEMICOLON {
+semi: | T_SEMICOLON
+
+declaration: declspecs declarators semi {
$$ = $2;
for (struct cdecl *i = $$; i; i = i->next)
%%
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,
+ });
}