Remove incorrect comment in read.c
[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>
6d4e1f62
NJ
21
22/* Prevent compilation of static input() function in generated scanner
23 code. This function is never actually used, and GCC 4.3 will emit
24 an error for that. */
25#define YY_NO_INPUT
26
ac13d9d2
ML
27int filter_snarfage = 0;
28int print = 1;
29
30enum t_state {
31 SKIP,
32 MULTILINE,
33 MULTILINE_COOKIE,
62024674 34 COOKIE
ac13d9d2
ML
35};
36
37enum t_state state = SKIP;
38int cookie_was_last = 0;
39
40#define OUT_RAW(type,text) if (print) printf ("(%s . \"%s\")\n", #type, text)
41
42#define OUT_T(type) OUT_RAW (type, yytext)
43#define OUT_S if (print) printf ("%s\n", yytext)
44#define OUT(type) if (print) printf ("%s\n", #type)
45
46#define IS_COOKIE cookie_was_last = 1
47#define IS_NOT_COOKIE cookie_was_last = 0
48
49%}
50
51%%
52
53\/\*(\n|[^*]|\*[^/])*\*\/ { OUT_T (comment); }
54
55({SPACE}*(\\\n)*{SPACE}*)+ ;
56
57({SPACE}*\n*{SPACE}*)+ { OUT(eol); }
58
6d7c6cf4 59#.*\n { OUT(hash); IS_NOT_COOKIE; }
ac13d9d2
ML
60
61{LETTER}({LETTER}|{DIGIT})* { OUT_T (id); IS_NOT_COOKIE; }
62
630[xX]{HEXDIGIT}+{INTQUAL}? { OUT_RAW (int_hex, yytext + 2); IS_NOT_COOKIE; }
640{OCTDIGIT}+{INTQUAL}? { OUT_RAW (int_oct, yytext + 1); IS_NOT_COOKIE; }
65{DIGIT}+{INTQUAL}? { OUT_T (int_dec); IS_NOT_COOKIE; }
66
67L?\'(\\.|[^\\\'])+\' { OUT_T (char); IS_NOT_COOKIE; }
68
69{DIGIT}+{EXPONENT}{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
70{DIGIT}*"."{DIGIT}+({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
71{DIGIT}+"."{DIGIT}*({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
72
73L?\"(\\.|[^\\\"])*\" { OUT_S; IS_NOT_COOKIE; }
74
75"..." { OUT (ellipsis); IS_NOT_COOKIE; }
76
77">>=" { OUT (shift_right_assign); IS_NOT_COOKIE; }
78"<<=" { OUT (shift_left_assign); IS_NOT_COOKIE; }
79"+=" { OUT (add_assign); IS_NOT_COOKIE; }
80"-=" { OUT (sub_assign); IS_NOT_COOKIE; }
81"*=" { OUT (mul-assign); IS_NOT_COOKIE; }
82"/=" { OUT (div_assign); IS_NOT_COOKIE; }
83"%=" { OUT (mod_assign); IS_NOT_COOKIE; }
84"&=" { OUT (logand_assign); IS_NOT_COOKIE; }
85"^=" { OUT (logxor_assign); IS_NOT_COOKIE; }
86"|=" { OUT (logior_assign); IS_NOT_COOKIE; }
87">>" { OUT (right_shift); IS_NOT_COOKIE; }
88"<<" { OUT (left_shift); IS_NOT_COOKIE; }
89"++" { OUT (inc); IS_NOT_COOKIE; }
90"--" { OUT (dec); IS_NOT_COOKIE; }
91"->" { OUT (ptr); IS_NOT_COOKIE; }
92"&&" { OUT (and); IS_NOT_COOKIE; }
93"||" { OUT (or); IS_NOT_COOKIE; }
94"<=" { OUT (le); IS_NOT_COOKIE; }
95">=" { OUT (ge); IS_NOT_COOKIE; }
96"==" { OUT (eq); IS_NOT_COOKIE; }
97"!=" { OUT (ne); IS_NOT_COOKIE; }
98";" { OUT (semicolon); IS_NOT_COOKIE; }
99
100("{"|"<%") {
101 OUT (brace_open);
102 if (filter_snarfage && cookie_was_last && state == COOKIE)
103 state = MULTILINE;
104 IS_NOT_COOKIE; }
105
106("}"|"%>") {
107 OUT (brace_close);
108 if (filter_snarfage && cookie_was_last && state == MULTILINE_COOKIE) {
109 state = SKIP;
110 print = 0;
111 }
112 IS_NOT_COOKIE; }
113
114"," { OUT (comma); IS_NOT_COOKIE; }
115":" { OUT (colon); IS_NOT_COOKIE; }
116"=" { OUT (assign); IS_NOT_COOKIE; }
117"(" { OUT (paren_open); IS_NOT_COOKIE; }
118")" { OUT (paren_close); IS_NOT_COOKIE; }
119("["|"<:") { OUT (bracket_open); IS_NOT_COOKIE; }
120("]"|":>") { OUT (bracket_close); IS_NOT_COOKIE; }
121"." { OUT (dot); IS_NOT_COOKIE; }
122"&" { OUT (amp); IS_NOT_COOKIE; }
123"!" { OUT (bang); IS_NOT_COOKIE; }
124"~" { OUT (tilde); IS_NOT_COOKIE; }
125"-" { OUT (minus); IS_NOT_COOKIE; }
126"+" { OUT (plus); IS_NOT_COOKIE; }
127"*" { OUT (star); IS_NOT_COOKIE; }
128"/" { OUT (slash); IS_NOT_COOKIE; }
129"%" { OUT (percent); IS_NOT_COOKIE; }
130"<" { OUT (lt); IS_NOT_COOKIE; }
131">" { OUT (gt); IS_NOT_COOKIE; }
132
133\^{WS}*\^ {
134 if (filter_snarfage)
135 switch (state) {
136 case SKIP:
137 state = COOKIE;
138 print = 1;
139 OUT (snarf_cookie);
140 break;
141 case MULTILINE:
142 case MULTILINE_COOKIE:
143 state = MULTILINE_COOKIE;
144 OUT (snarf_cookie);
145 break;
146 case COOKIE:
147 state = SKIP;
148 OUT (snarf_cookie);
149 print = 0;
150 break;
151 default:
152 /* whoops */
153 abort ();
154 break;
155 }
156 else
157 OUT (snarf_cookie);
158
159 IS_COOKIE; }
160
161"^" { OUT (caret); IS_NOT_COOKIE; }
162"|" { OUT (pipe); IS_NOT_COOKIE; }
163"?" { OUT (question); IS_NOT_COOKIE; }
164
165. { fprintf (stderr, "*%s", yytext); fflush (stderr); IS_NOT_COOKIE; }
166
167%%
168
169int
170main (int argc, char *argv[])
171{
172 if (argc > 1 && !strcmp (argv[1], "--filter-snarfage")) {
173 filter_snarfage = 1;
174 print = 0;
175 }
176
177 yylex ();
178
179 return EXIT_SUCCESS;
180}
181
182/*
183 Local Variables:
184 c-file-style: "gnu"
185 End:
186*/