1 /* Generated by re2c */
2 #line 1 "ctx_s.re"
3 // re2c $INPUT -o $OUTPUT -s
4 #include <cstring>
5 #include <iostream>
6
7 struct Scanner
8 {
ScannerScanner9 Scanner(char *txt)
10 : cur(txt), lim(txt + strlen(txt))
11 {
12 }
13
14 char *cur;
15 char *lim;
16 char *ptr;
17 char *ctx;
18 char *tok;
19 };
20
21 #define YYCTYPE char
22 #define YYCURSOR s.cur
23 #define YYLIMIT s.lim
24 #define YYMARKER s.ptr
25 #define YYCTXMARKER s.ctx
26 #define YYFILL(n)
27
28 enum What
29 {
30 UNEXPECTED,
31 KEYWORD,
32 NUMBER,
33 EOI
34 };
35
36 char * tokens[] = { "UNEXPECTED", "KEYWORD", "NUMBER", "EOI" };
37
38
scan(Scanner & s)39 int scan(Scanner &s)
40 {
41 YYCTYPE *cursor = s.cur;
42
43 if(cursor == s.lim)
44 return EOI;
45
46 std:
47 s.tok = cursor;
48
49
50 #line 51 "ctx_s.c"
51 {
52 YYCTYPE yych;
53 if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
54 yych = *YYCURSOR;
55 if (yych <= ' ') {
56 if (yych <= 0x08) goto yy2;
57 if (yych <= '\n') goto yy4;
58 if (yych >= ' ') goto yy4;
59 } else {
60 if (yych <= '9') {
61 if (yych >= '0') goto yy6;
62 } else {
63 if (yych <= '`') goto yy2;
64 if (yych <= 'b') goto yy9;
65 }
66 }
67 yy2:
68 ++YYCURSOR;
69 yy3:
70 #line 61 "ctx_s.re"
71 {
72 return UNEXPECTED;
73 }
74 #line 75 "ctx_s.c"
75 yy4:
76 ++YYCURSOR;
77 #line 54 "ctx_s.re"
78 {
79 if(s.cur == s.lim)
80 return EOI;
81 cursor = s.cur;
82 goto std;
83 }
84 #line 85 "ctx_s.c"
85 yy6:
86 ++YYCURSOR;
87 if (YYLIMIT <= YYCURSOR) YYFILL(1);
88 yych = *YYCURSOR;
89 if (yych <= '/') goto yy8;
90 if (yych <= '9') goto yy6;
91 yy8:
92 #line 51 "ctx_s.re"
93 { return NUMBER; }
94 #line 95 "ctx_s.c"
95 yy9:
96 yych = *++YYCURSOR;
97 if (yych <= '/') goto yy3;
98 if (yych == '1') {
99 YYCTXMARKER = YYCURSOR;
100 goto yy13;
101 }
102 if (yych >= ':') goto yy3;
103 YYCTXMARKER = YYCURSOR;
104 yy10:
105 ++YYCURSOR;
106 if (YYLIMIT <= YYCURSOR) YYFILL(1);
107 yych = *YYCURSOR;
108 if (yych <= '/') goto yy12;
109 if (yych <= '9') goto yy10;
110 yy12:
111 YYCURSOR = YYCTXMARKER;
112 #line 50 "ctx_s.re"
113 { return KEYWORD; }
114 #line 115 "ctx_s.c"
115 yy13:
116 yych = *++YYCURSOR;
117 if (yych <= '/') goto yy14;
118 if (yych <= '9') goto yy10;
119 yy14:
120 YYCURSOR -= 1;
121 #line 49 "ctx_s.re"
122 { return KEYWORD; }
123 #line 124 "ctx_s.c"
124 }
125 #line 64 "ctx_s.re"
126
127 }
128
129 #line 130 "ctx_s.c"
130 #define YYMAXFILL 3
131 #line 67 "ctx_s.re"
132
133
main(int,char **)134 int main(int,char**)
135 {
136 Scanner s("a77 a1 b8 b1");
137
138 int t, n = 0;
139 while ((t = scan(s)) != EOI)
140 {
141 std::cout << (++n) << ": " << tokens[t] << " = \""; std::cout.write(s.tok, s.cur-s.tok); std::cout << "\"" << std::endl;
142 }
143 }
144