3 * Scanner for C declarations.
4 * Copyright © 2011 Nick Bowler
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 %option noyywrap bison-locations
26 #define lex_error(msg) do { \
27 yyerror(yylloc, NULL, (msg)); \
32 IDENT [_[:alpha:]][_[:alnum:]]*
33 INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
37 ";" return T_SEMICOLON;
38 "*" return T_ASTERISK;
41 "[" return T_LBRACKET;
42 "]" return T_RBRACKET;
45 "typedef" return T_TYPEDEF;
46 "extern" return T_EXTERN;
47 "static" return T_STATIC;
49 "register" return T_REGISTER;
51 "restrict" return T_RESTRICT;
52 "volatile" return T_VOLATILE;
53 "const" return T_CONST;
55 "inline" return T_INLINE;
59 "short" return T_SHORT;
62 "float" return T_FLOAT;
63 "double" return T_DOUBLE;
64 "signed" return T_SIGNED;
65 "unsigned" return T_UNSIGNED;
66 "_Bool" return T_BOOL;
67 "_Complex" return T_COMPLEX;
69 "struct" return T_STRUCT;
70 "union" return T_UNION;
77 yylval->uintval = strtoumax(yytext, &end, 0);
79 lex_error("integer constant out of range");
81 lex_error("invalid integer constant");
87 yylval->strval = malloc(yyleng+1);
89 lex_error("failed to allocate memory");
91 strcpy(yylval->strval, yytext);
97 char buf[] = "syntax error, unexpected #";
98 *strchr(buf, '#') = *yytext;