File: 009_conditions.go

package info (click to toggle)
re2c 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 50,052 kB
  • sloc: cpp: 32,477; ml: 8,279; sh: 5,265; makefile: 968; haskell: 612; python: 428; ansic: 227; javascript: 111; java: 3
file content (190 lines) | stat: -rw-r--r-- 2,903 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Code generated by re2go, DO NOT EDIT.
//go:generate re2go $INPUT -o $OUTPUT -ci
package main

import "fmt"

const (
	yycinit = iota
	yycbin
	yycdec
	yychex
	yycoct
)


func Lex(str string) int {
	var cursor int
	cond := yycinit
	n := 0

	
{
	var yych byte
	switch (cond) {
	case yycinit:
		goto yyc_init
	case yycbin:
		goto yyc_bin
	case yycdec:
		goto yyc_dec
	case yychex:
		goto yyc_hex
	case yycoct:
		goto yyc_oct
	default:
		panic("internal lexer error")
	}
/* *********************************** */
yyc_init:
	yych = str[cursor]
	switch (yych) {
	case '0':
		goto yy2
	case '1','2','3','4','5','6','7','8','9':
		goto yy4
	default:
		goto yy1
	}
yy1:
	cursor += 1
	{ return -1 }
yy2:
	cursor += 1
	yych = str[cursor]
	switch (yych) {
	case 'B':
		fallthrough
	case 'b':
		goto yy5
	case 'X':
		fallthrough
	case 'x':
		goto yy6
	default:
		goto yy3
	}
yy3:
	cond = yycoct
	goto yyc_oct
yy4:
	cursor += 1
	cursor += -1
	cond = yycdec
	goto yyc_dec
yy5:
	cursor += 1
	cond = yycbin
	goto yyc_bin
yy6:
	cursor += 1
	cond = yychex
	goto yyc_hex
/* *********************************** */
yyc_bin:
	yych = str[cursor]
	switch (yych) {
	case 0x00:
		goto yy8
	case '0','1':
		goto yy10
	default:
		goto yy9
	}
yy8:
	cursor += 1
	{ return n }
yy9:
	cursor += 1
	{ return -1 }
yy10:
	cursor += 1
	{ n = n*2 + int(str[cursor-1] - '0'); goto yyc_bin; }
/* *********************************** */
yyc_dec:
	yych = str[cursor]
	switch (yych) {
	case 0x00:
		goto yy12
	case '0','1','2','3','4','5','6','7','8','9':
		goto yy14
	default:
		goto yy13
	}
yy12:
	cursor += 1
	{ return n }
yy13:
	cursor += 1
	{ return -1 }
yy14:
	cursor += 1
	{ n = n*10 + int(str[cursor-1] - '0'); goto yyc_dec; }
/* *********************************** */
yyc_hex:
	yych = str[cursor]
	switch (yych) {
	case 0x00:
		goto yy16
	case '0','1','2','3','4','5','6','7','8','9':
		goto yy18
	case 'A','B','C','D','E','F':
		goto yy19
	case 'a','b','c','d','e','f':
		goto yy20
	default:
		goto yy17
	}
yy16:
	cursor += 1
	{ return n }
yy17:
	cursor += 1
	{ return -1 }
yy18:
	cursor += 1
	{ n = n*16 + int(str[cursor-1] - '0'); goto yyc_hex; }
yy19:
	cursor += 1
	{ n = n*16 + int(str[cursor-1] - 'A') + 10; goto yyc_hex; }
yy20:
	cursor += 1
	{ n = n*16 + int(str[cursor-1] - 'a') + 10; goto yyc_hex; }
/* *********************************** */
yyc_oct:
	yych = str[cursor]
	switch (yych) {
	case 0x00:
		goto yy22
	case '0','1','2','3','4','5','6','7':
		goto yy24
	default:
		goto yy23
	}
yy22:
	cursor += 1
	{ return n }
yy23:
	cursor += 1
	{ return -1 }
yy24:
	cursor += 1
	{ n = n*8 + int(str[cursor-1] - '0'); goto yyc_oct; }
}

}

func test(str string, num int) {
	if res := Lex(str); res != num {
		panic(fmt.Sprintf("failed %s: expected %d, got %d", str, num, res))
	}
}

func main() {
	test("123\000", 123)
	test("0b101\000", 5)
	test("0x10Ff\000", 4096 + 255)
	test("0112\000", 74)
	test("0\000", 0)
	test("\000", -1)
}