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