aboutsummaryrefslogtreecommitdiff
path: root/sys/fmtio/doc/lexnum.hlp
blob: 647654b1e9cd214beb7b70efcb7afca09989d324 (plain) (blame)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

.help lexnum 2 "string utilities"
.ih _________________________________________________________________________
NAME
lexnum -- Determine if string is a number
.ih
USAGE
token_type = lexnum (str, ip, nchars)

.ih
PARAMETERS
.ls str
String to be scanned.
.le
.ls ip
Index within the string as which scanning is to start.  Not modified.
.le
.ls nchars
On output, the number of characters in the number, not including any
leading whitespace.
.le
.ih
DESCRIPTION
The character string is scanned to determine if the next token is a
legal number, and if so, the type of number.  The function value identifies
the type of number.  The possible return values, defined in <lexnum.h>,
as as follows:

.nf
	LEX_OCTAL	(+|-)?[0-7]+[bB]
	LEX_DECIMAL	(+|-)?[0-9]+
	LEX_HEX		(+|-)?[0-9a-fA-F]+[xX]
	LEX_REAL	floating, exponential [eEdD], sexagesimal
	LEX_NONNUM	not a number
.fi
.ih
IMPLEMENTATION
Numtype is implemented as a finite state automaton.  Additional documentation
is provided with the source code.
.ih
SEE ALSO
gctod(2), ctotok(2).
.endhelp ___________________________________________________________________



.help states 2 "States of the LEXNUM Finite State Automaton"
.fi


.ks
.nf
start:								(1)
	+-		shift	unop_or_number
	0-7		shift	odhr
	8-9		shift	dhr
	acf		reduce	not_a_number
	ed		reduce	not_a_number
	:		shift	maybe_real_number
	.		shift	maybe_real_fraction
	x		reduce	not_a_number
	b		reduce	not_a_number
	other		reduce	not_a_number
.fi
.ke


.ks
.nf
unop_or_number:		(+|-)					(2)
	+-		revert
	0-7		shift	odhr
	8-9		shift	dhr
	acf		revert
	ed		revert
	:		revert
	.		shift	maybe_real_fraction
	x		revert
	b		revert
	other		revert
.fi
.ke


.ks
.nf
odhr:			(+|-)?[0-7]				(3)
	+-		reduce	decimal_number
	0-7		accept
	8-9		shift	dhr
	acf		shift	h
	ed		shift	maybe_hex_or_rexp
	:		shift	maybe_real_number
	.		shift	real_fraction
	x		reduce	hex_number
	b		shift	octal_or_hex_number
	other		reduce	decimal_number
.fi
.ke


.ks
.nf
dhr:			(+|-)?[0-9]+				(4)
	+-		reduce	decimal_number
	0-7		accept
	8-9		accept
	acf		shift	h
	ed		shift	maybe_hex_or_rexp
	:		shift	maybe_real_number
	.		shift	real_fraction
	x		reduce	hex_number
	b		shift	h
	other		reduce	decimal_number
.fi
.ke


.ks
.nf
maybe_real_fraction:	(+|-)?"."				(5)
	+-		revert
	0-7		shift	real_fraction
	8-9		shift	real_fraction
	acf		revert
	ed		revert
	:		revert
	.		revert
	x		revert
	b		revert
	other		revert
.fi
.ke


.ks
.nf
h:			(+|-)?[0-9]*[a-f]			(6)
	+-		revert
	0-7		accept
	8-9		accept
	acf		accept
	ed		accept
	:		revert
	.		revert
	x		reduce	hex_number
	b		accept
	other		revert
.fi
.ke


.ks
.nf
maybe_hex_or_rexp:	(+|-)?[0-9]+[ed]			(7)
	+-		shift	maybe_rexp
	0-7		shift	hex_or_rexp
	8-9		shift	hex_or_rexp
	acf		shift	h
	ed		shift	h
	:		revert
	.		revert
	x		reduce	hex_number
	b		shift	h
	other		revert
.fi
.ke


.ks
.nf
maybe_real_number:	(+|-)?[0-9]*":"				(8)
	+-		revert
	0-7		shift	r
	8-9		shift	r
	acf		revert
	ed		revert
	:		accept
	.		revert
	x		revert
	b		revert
	other		revert
.fi
.ke


.ks
.nf
octal_or_hex_number:	(+|-)?[0-7]"b"				(9)
	+-		reduce	octal_number
	0-7		shift	h
	8-9		shift	h
	acf		shift	h
	ed		shift	h
	:		reduce	octal_number
	.		reduce	octal_number
	x		reduce	hex_number
	b		shift	h
	other		reduce	octal_number
.fi
.ke


.ks
.nf
real_fraction:		(+|-)?"."[0-9]				(10)
	+-		reduce	real_number
	0-7		accept
	8-9		accept
	acf		reduce	real_number
	ed		shift	rfr_or_rexp
	:		reduce	real_number
	.		reduce	real_number
	x		reduce	real_number
	b		reduce	real_number
	other		reduce	real_number
.fi
.ke


.ks
.nf
rfr_or_rexp:		(+|-)?"."[0-9]+[ed]			(11)
	+-		shift	maybe_rexp
	0-7		shift	rexp
	8-9		shift	rexp
	acf		revert
	ed		revert
	:		revert
	.		revert
	x		revert
	b		revert
	other		revert
.fi
.ke


.ks
.nf
maybe_rexp:		(+|-)?[0-9]+[ed](+|-)			(12)
	+-		revert
	0-7		shift	rexp
	8-9		shift	rexp
	acf		revert
	ed		revert
	:		revert
	.		revert
	x		revert
	b		revert
	other		revert
.fi
.ke


.ks
.nf
hex_or_rexp:		(+|-)?[0-9]+[ed][0-9]			(13)
	+-		reduce	real_number
	0-7		accept
	8-9		accept
	acf		shift	h
	ed		shift	h
	:		reduce	real_number
	.		reduce	real_number
	x		reduce	hex_number
	b		reduce	real_number
	other		reduce	real_number
.fi
.ke


.ks
.nf
r:			(+|-)?[0-9]*":"[0-9]			(14)
	+-		reduce	real_number
	0-7		accept
	8-9		accept
	acf		reduce	real_number
	ed		shift	maybe_rexp
	:		accept
	.		shift	maybe_real_fraction
	x		reduce	real_number
	b		reduce	real_number
	other		reduce	real_number
.fi
.ke


.ks
.nf
rexp:			(+|-)?[0-9]+[ed](+|-)[0-9]		(15)
	+-		reduce	real_number
	0-7		accept
	8-9		accept
	acf		reduce	real_number
	ed		reduce	real_number
	:		reduce	real_number
	.		reduce	real_number
	x		reduce	real_number
	b		reduce	real_number
	other		reduce	real_number
.fi
.ke