block: don't put spaces around :
[ironout.git] / c.l
blob8b7ebddd7261cd10bcfbfa823f48339b32d52398
1 D                       [0-9]
2 L                       [a-zA-Z_]
3 H                       [a-fA-F0-9]
4 E                       [Ee][+-]?{D}+
5 FS                      (f|F|l|L)
6 IS                      (u|U|l|L)*
8 %{
9 #include <stdio.h>
10 #include <string.h>
11 #include "parse.h"
13 static void count();
14 static void ignore();
15 static int check_type();
19 "/*"([^\*]|\*[^/])*"*/" { ignore(); }
20 "//"[^\n]*              { ignore(); }
21 "_Bool"                 { count(); return BOOL; }
22 "_Complex"              { count(); return COMPLEX; }
23 "_Imaginary"            { count(); return IMAGINARY; }
24 "auto"                  { count(); return AUTO; }
25 "break"                 { count(); return BREAK; }
26 "case"                  { count(); return CASE; }
27 "char"                  { count(); return CHAR; }
28 "const"                 { count(); return CONST; }
29 "continue"              { count(); return CONTINUE; }
30 "default"               { count(); return DEFAULT; }
31 "do"                    { count(); return DO; }
32 "double"                { count(); return DOUBLE; }
33 "else"                  { count(); return ELSE; }
34 "enum"                  { count(); return ENUM; }
35 "extern"                { count(); return EXTERN; }
36 "float"                 { count(); return FLOAT; }
37 "for"                   { count(); return FOR; }
38 "goto"                  { count(); return GOTO; }
39 "if"                    { count(); return IF; }
40 "inline"                { count(); return INLINE; }
41 "int"                   { count(); return INT; }
42 "long"                  { count(); return LONG; }
43 "register"              { count(); return REGISTER; }
44 "restrict"              { count(); return RESTRICT; }
45 "return"                { count(); return RETURN; }
46 "short"                 { count(); return SHORT; }
47 "signed"                { count(); return SIGNED; }
48 "sizeof"                { count(); return SIZEOF; }
49 "static"                { count(); return STATIC; }
50 "struct"                { count(); return STRUCT; }
51 "switch"                { count(); return SWITCH; }
52 "typedef"               { count(); return TYPEDEF; }
53 "union"                 { count(); return UNION; }
54 "unsigned"              { count(); return UNSIGNED; }
55 "void"                  { count(); return VOID; }
56 "volatile"              { count(); return VOLATILE; }
57 "while"                 { count(); return WHILE; }
59 {L}({L}|{D})*           { count(); return check_type(); }
61 0[xX]{H}+{IS}?          { count(); return CONSTANT; }
62 0{D}+{IS}?              { count(); return CONSTANT; }
63 {D}+{IS}?               { count(); return CONSTANT; }
64 '(\\.|[^\\'])+'         { count(); return CONSTANT; }
66 {D}+{E}{FS}?            { count(); return CONSTANT; }
67 {D}*"."{D}+({E})?{FS}?  { count(); return CONSTANT; }
68 {D}+"."{D}*({E})?{FS}?  { count(); return CONSTANT; }
70 \"(\\.|[^\\"])*\"       { count(); return STRING_LITERAL; }
71 #([^\n]|\\\n)+          { count(); return MACRO; }
73 ">>="                   { count(); return RIGHT_ASSIGN; }
74 "<<="                   { count(); return LEFT_ASSIGN; }
75 "+="                    { count(); return ADD_ASSIGN; }
76 "-="                    { count(); return SUB_ASSIGN; }
77 "*="                    { count(); return MUL_ASSIGN; }
78 "/="                    { count(); return DIV_ASSIGN; }
79 "%="                    { count(); return MOD_ASSIGN; }
80 "&="                    { count(); return AND_ASSIGN; }
81 "^="                    { count(); return XOR_ASSIGN; }
82 "|="                    { count(); return OR_ASSIGN; }
83 ">>"                    { count(); return RIGHT_OP; }
84 "<<"                    { count(); return LEFT_OP; }
85 "++"                    { count(); return INC_OP; }
86 "--"                    { count(); return DEC_OP; }
87 "->"                    { count(); return PTR_OP; }
88 "&&"                    { count(); return AND_OP; }
89 "||"                    { count(); return OR_OP; }
90 "<="                    { count(); return LE_OP; }
91 ">="                    { count(); return GE_OP; }
92 "=="                    { count(); return EQ_OP; }
93 "!="                    { count(); return NE_OP; }
94 ";"                     { count(); return ';'; }
95 "{"                     { count(); return '{'; }
96 "}"                     { count(); return '}'; }
97 ","                     { count(); return ','; }
98 ":"                     { count(); return ':'; }
99 "="                     { count(); return '='; }
100 "("                     { count(); return '('; }
101 ")"                     { count(); return ')'; }
102 "["                     { count(); return '['; }
103 "]"                     { count(); return ']'; }
104 "."                     { count(); return '.'; }
105 "&"                     { count(); return '&'; }
106 "!"                     { count(); return '!'; }
107 "~"                     { count(); return '~'; }
108 "-"                     { count(); return '-'; }
109 "+"                     { count(); return '+'; }
110 "*"                     { count(); return '*'; }
111 "/"                     { count(); return '/'; }
112 "%"                     { count(); return '%'; }
113 "<"                     { count(); return '<'; }
114 ">"                     { count(); return '>'; }
115 "^"                     { count(); return '^'; }
116 "|"                     { count(); return '|'; }
117 "?"                     { count(); return '?'; }
119 [ \t\v\n\f]             { ignore(); }
120 .                       { ignore(); }
124 int yywrap()
126         return 1;
129 #define MAXTOKLEN       4 * 1024
131 long token_offset = 0;
132 static char token_str[MAXTOKLEN];
133 static char *cur_filename = NULL;
135 static void count()
137         yylloc.start = token_offset;
138         token_offset += strlen(yytext);
139         strcpy(token_str, yytext);
140         yylval = token_str;
141         yylloc.end = token_offset;
144 static void ignore()
146         token_offset += strlen(yytext);
149 static int check_type()
151         return typedef_name(cur_filename, yytext, yylloc.start) ?
152                 TYPE_NAME : IDENTIFIER;
155 void reset_tokenizer(char *filename)
157         token_offset = 0;
158         cur_filename = filename;