(take_uvec): Make BASE pointer non-const.
[bpt/guile.git] / libguile / c-tokenize.lex
CommitLineData
ac13d9d2 1%option noyywrap
e80bea70 2%option nounput
ac13d9d2
ML
3%pointer
4
5EOL \n
6SPACE [ \t\v\f]
7WS [ \t\v\n\f]
8DIGIT [0-9]
9LETTER [a-zA-Z_]
10OCTDIGIT [0-7]
11HEXDIGIT [a-fA-F0-9]
12EXPONENT [Ee][+-]?{DIGIT}+
13FLOQUAL (f|F|l|L)
14INTQUAL (l|L|ll|LL|lL|Ll|u|U)
15
16%{
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
e80bea70 21
7e59d9d4
MD
22int yylex(void);
23
24int yyget_lineno (void);
25FILE *yyget_in (void);
26FILE *yyget_out (void);
27int yyget_leng (void);
28char *yyget_text (void);
29void yyset_lineno (int line_number);
30void yyset_in (FILE * in_str);
31void yyset_out (FILE * out_str);
32int yyget_debug (void);
33void yyset_debug (int bdebug);
34int yylex_destroy (void);
35
ac13d9d2
ML
36int filter_snarfage = 0;
37int print = 1;
38
39enum t_state {
40 SKIP,
41 MULTILINE,
42 MULTILINE_COOKIE,
62024674 43 COOKIE
ac13d9d2
ML
44};
45
46enum t_state state = SKIP;
47int cookie_was_last = 0;
48
49#define OUT_RAW(type,text) if (print) printf ("(%s . \"%s\")\n", #type, text)
50
51#define OUT_T(type) OUT_RAW (type, yytext)
52#define OUT_S if (print) printf ("%s\n", yytext)
53#define OUT(type) if (print) printf ("%s\n", #type)
54
55#define IS_COOKIE cookie_was_last = 1
56#define IS_NOT_COOKIE cookie_was_last = 0
57
58%}
59
60%%
61
62\/\*(\n|[^*]|\*[^/])*\*\/ { OUT_T (comment); }
63
64({SPACE}*(\\\n)*{SPACE}*)+ ;
65
66({SPACE}*\n*{SPACE}*)+ { OUT(eol); }
67
6d7c6cf4 68#.*\n { OUT(hash); IS_NOT_COOKIE; }
ac13d9d2
ML
69
70{LETTER}({LETTER}|{DIGIT})* { OUT_T (id); IS_NOT_COOKIE; }
71
720[xX]{HEXDIGIT}+{INTQUAL}? { OUT_RAW (int_hex, yytext + 2); IS_NOT_COOKIE; }
730{OCTDIGIT}+{INTQUAL}? { OUT_RAW (int_oct, yytext + 1); IS_NOT_COOKIE; }
74{DIGIT}+{INTQUAL}? { OUT_T (int_dec); IS_NOT_COOKIE; }
75
76L?\'(\\.|[^\\\'])+\' { OUT_T (char); IS_NOT_COOKIE; }
77
78{DIGIT}+{EXPONENT}{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
79{DIGIT}*"."{DIGIT}+({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
80{DIGIT}+"."{DIGIT}*({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
81
82L?\"(\\.|[^\\\"])*\" { OUT_S; IS_NOT_COOKIE; }
83
84"..." { OUT (ellipsis); IS_NOT_COOKIE; }
85
86">>=" { OUT (shift_right_assign); IS_NOT_COOKIE; }
87"<<=" { OUT (shift_left_assign); IS_NOT_COOKIE; }
88"+=" { OUT (add_assign); IS_NOT_COOKIE; }
89"-=" { OUT (sub_assign); IS_NOT_COOKIE; }
90"*=" { OUT (mul-assign); IS_NOT_COOKIE; }
91"/=" { OUT (div_assign); IS_NOT_COOKIE; }
92"%=" { OUT (mod_assign); IS_NOT_COOKIE; }
93"&=" { OUT (logand_assign); IS_NOT_COOKIE; }
94"^=" { OUT (logxor_assign); IS_NOT_COOKIE; }
95"|=" { OUT (logior_assign); IS_NOT_COOKIE; }
96">>" { OUT (right_shift); IS_NOT_COOKIE; }
97"<<" { OUT (left_shift); IS_NOT_COOKIE; }
98"++" { OUT (inc); IS_NOT_COOKIE; }
99"--" { OUT (dec); IS_NOT_COOKIE; }
100"->" { OUT (ptr); IS_NOT_COOKIE; }
101"&&" { OUT (and); IS_NOT_COOKIE; }
102"||" { OUT (or); IS_NOT_COOKIE; }
103"<=" { OUT (le); IS_NOT_COOKIE; }
104">=" { OUT (ge); IS_NOT_COOKIE; }
105"==" { OUT (eq); IS_NOT_COOKIE; }
106"!=" { OUT (ne); IS_NOT_COOKIE; }
107";" { OUT (semicolon); IS_NOT_COOKIE; }
108
109("{"|"<%") {
110 OUT (brace_open);
111 if (filter_snarfage && cookie_was_last && state == COOKIE)
112 state = MULTILINE;
113 IS_NOT_COOKIE; }
114
115("}"|"%>") {
116 OUT (brace_close);
117 if (filter_snarfage && cookie_was_last && state == MULTILINE_COOKIE) {
118 state = SKIP;
119 print = 0;
120 }
121 IS_NOT_COOKIE; }
122
123"," { OUT (comma); IS_NOT_COOKIE; }
124":" { OUT (colon); IS_NOT_COOKIE; }
125"=" { OUT (assign); IS_NOT_COOKIE; }
126"(" { OUT (paren_open); IS_NOT_COOKIE; }
127")" { OUT (paren_close); IS_NOT_COOKIE; }
128("["|"<:") { OUT (bracket_open); IS_NOT_COOKIE; }
129("]"|":>") { OUT (bracket_close); IS_NOT_COOKIE; }
130"." { OUT (dot); IS_NOT_COOKIE; }
131"&" { OUT (amp); IS_NOT_COOKIE; }
132"!" { OUT (bang); IS_NOT_COOKIE; }
133"~" { OUT (tilde); IS_NOT_COOKIE; }
134"-" { OUT (minus); IS_NOT_COOKIE; }
135"+" { OUT (plus); IS_NOT_COOKIE; }
136"*" { OUT (star); IS_NOT_COOKIE; }
137"/" { OUT (slash); IS_NOT_COOKIE; }
138"%" { OUT (percent); IS_NOT_COOKIE; }
139"<" { OUT (lt); IS_NOT_COOKIE; }
140">" { OUT (gt); IS_NOT_COOKIE; }
141
142\^{WS}*\^ {
143 if (filter_snarfage)
144 switch (state) {
145 case SKIP:
146 state = COOKIE;
147 print = 1;
148 OUT (snarf_cookie);
149 break;
150 case MULTILINE:
151 case MULTILINE_COOKIE:
152 state = MULTILINE_COOKIE;
153 OUT (snarf_cookie);
154 break;
155 case COOKIE:
156 state = SKIP;
157 OUT (snarf_cookie);
158 print = 0;
159 break;
160 default:
161 /* whoops */
162 abort ();
163 break;
164 }
165 else
166 OUT (snarf_cookie);
167
168 IS_COOKIE; }
169
170"^" { OUT (caret); IS_NOT_COOKIE; }
171"|" { OUT (pipe); IS_NOT_COOKIE; }
172"?" { OUT (question); IS_NOT_COOKIE; }
173
174. { fprintf (stderr, "*%s", yytext); fflush (stderr); IS_NOT_COOKIE; }
175
176%%
177
178int
179main (int argc, char *argv[])
180{
181 if (argc > 1 && !strcmp (argv[1], "--filter-snarfage")) {
182 filter_snarfage = 1;
183 print = 0;
184 }
185
186 yylex ();
187
188 return EXIT_SUCCESS;
189}
190
191/*
192 Local Variables:
193 c-file-style: "gnu"
194 End:
195*/