]> git.draconx.ca Git - cdecl99.git/blob - src/scan.l
Add a function to turn a typemap into a string.
[cdecl99.git] / src / scan.l
1 %top{
2 /*
3  *  Scanner for C declarations.
4  *  Copyright © 2011 Nick Bowler
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20  #include "parse.h"
21 }
22
23 %option noyywrap bison-locations
24
25 %{
26 #define lex_error(msg) do { \
27         yyerror(yylloc, NULL, (msg)); \
28         return T_LEX_ERROR; \
29 } while(0)
30 %}
31
32 IDENT [_[:alpha:]][_[:alnum:]]*
33
34 %%
35
36 ";" return T_SEMICOLON;
37 "*" return T_ASTERISK;
38 "(" return T_LPAREN;
39 ")" return T_RPAREN;
40 "[" return T_LBRACKET;
41 "]" return T_RBRACKET;
42 "," return T_COMMA;
43
44 "typedef"  return T_TYPEDEF;
45 "extern"   return T_EXTERN;
46 "static"   return T_STATIC;
47 "auto"     return T_AUTO;
48 "register" return T_REGISTER;
49
50 "restrict" return T_RESTRICT;
51 "volatile" return T_VOLATILE;
52 "const"    return T_CONST;
53
54 "inline"   return T_INLINE;
55
56 "void"     return T_VOID;
57 "char"     return T_CHAR;
58 "short"    return T_SHORT;
59 "int"      return T_INT;
60 "long"     return T_LONG;
61 "float"    return T_FLOAT;
62 "double"   return T_DOUBLE;
63 "signed"   return T_SIGNED;
64 "unsigned" return T_UNSIGNED;
65 "_Bool"    return T_BOOL;
66 "_Complex" return T_COMPLEX;
67
68 "struct"   return T_STRUCT;
69 "union"    return T_UNION;
70 "enum"     return T_ENUM;
71
72 {IDENT} {
73         yylval->strval = malloc(yyleng+1);
74         if (!yylval->strval)
75                 lex_error("failed to allocate memory");
76
77         strcpy(yylval->strval, yytext);
78         return T_IDENT;
79 }
80
81 [[:space:]]+
82 . {
83         char buf[] = "syntax error, unexpected #";
84         *strchr(buf, '#') = *yytext;
85         lex_error(buf);
86 }