xref: /freebsd/contrib/bc/src/data.c (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 /*
2  * *****************************************************************************
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  *
6  * Copyright (c) 2018-2021 Gavin D. Howard and contributors.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * * Redistributions of source code must retain the above copyright notice, this
12  *   list of conditions and the following disclaimer.
13  *
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  *   this list of conditions and the following disclaimer in the documentation
16  *   and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * *****************************************************************************
31  *
32  * Constant data for bc.
33  *
34  */
35 
36 #include <args.h>
37 #include <lex.h>
38 #include <parse.h>
39 #include <bc.h>
40 #include <dc.h>
41 #include <num.h>
42 #include <rand.h>
43 #include <program.h>
44 #include <vm.h>
45 
46 #if !BC_ENABLE_LIBRARY
47 
48 #if BC_ENABLED
49 const char bc_sig_msg[] = "\ninterrupt (type \"quit\" to exit)\n";
50 const uchar bc_sig_msg_len = (uchar) (sizeof(bc_sig_msg) - 1);
51 #endif // BC_ENABLED
52 #if DC_ENABLED
53 const char dc_sig_msg[] = "\ninterrupt (type \"q\" to exit)\n";
54 const uchar dc_sig_msg_len = (uchar) (sizeof(dc_sig_msg) - 1);
55 #endif // DC_ENABLED
56 
57 const char bc_copyright[] =
58 	"Copyright (c) 2018-2021 Gavin D. Howard and contributors\n"
59 	"Report bugs at: https://git.yzena.com/gavin/bc\n\n"
60 	"This is free software with ABSOLUTELY NO WARRANTY.\n";
61 
62 const char* const bc_err_func_header = "Function:";
63 const char* const bc_err_line = ":%zu";
64 
65 const char *bc_errs[] = {
66 	"Math error:",
67 	"Parse error:",
68 	"Runtime error:",
69 	"Fatal error:",
70 #if BC_ENABLED
71 	"Warning:",
72 #endif // BC_ENABLED
73 };
74 
75 const uchar bc_err_ids[] = {
76 
77 	BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH, BC_ERR_IDX_MATH,
78 
79 	BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL,
80 	BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL, BC_ERR_IDX_FATAL,
81 
82 	BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
83 	BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
84 	BC_ERR_IDX_EXEC, BC_ERR_IDX_EXEC,
85 
86 	BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
87 	BC_ERR_IDX_PARSE,
88 #if BC_ENABLED
89 	BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
90 	BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
91 	BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
92 
93 	BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
94 	BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
95 	BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE, BC_ERR_IDX_PARSE,
96 	BC_ERR_IDX_PARSE,
97 #endif // BC_ENABLED
98 
99 };
100 
101 const char* const bc_err_msgs[] = {
102 
103 	"negative number",
104 	"non-integer number",
105 	"overflow: number cannot fit",
106 	"divide by 0",
107 
108 	"memory allocation failed",
109 	"I/O error",
110 	"cannot open file: %s",
111 	"file is not ASCII: %s",
112 	"path is a directory: %s",
113 	"bad command-line option: \"%s\"",
114 	"option requires an argument: '%c' (\"%s\")",
115 	"option takes no arguments: '%c' (\"%s\")",
116 
117 	"bad ibase: must be [%lu, %lu]",
118 	"bad obase: must be [%lu, %lu]",
119 	"bad scale: must be [%lu, %lu]",
120 	"bad read() expression",
121 	"read() call inside of a read() call",
122 	"variable or array element is the wrong type",
123 #if DC_ENABLED
124 	"stack has too few elements",
125 #else // DC_ENABLED
126 	NULL,
127 #endif // DC_ENABLED
128 #if BC_ENABLED
129 	"wrong number of parameters; need %zu, have %zu",
130 	"undefined function: %s()",
131 	"cannot use a void value in an expression",
132 #else
133 	NULL, NULL, NULL,
134 #endif // BC_ENABLED
135 
136 	"end of file",
137 	"bad character '%c'",
138 	"string end cannot be found",
139 	"comment end cannot be found",
140 	"bad token",
141 #if BC_ENABLED
142 	"bad expression",
143 	"empty expression",
144 	"bad print statement",
145 	"bad function definition",
146 	("bad assignment: left side must be scale, ibase, "
147 		"obase, seed, last, var, or array element"),
148 	"no auto variable found",
149 	"function parameter or auto \"%s%s\" already exists",
150 	"block end cannot be found",
151 	"cannot return a value from void function: %s()",
152 	"var cannot be a reference: %s",
153 
154 	"POSIX does not allow names longer than 1 character: %s",
155 	"POSIX does not allow '#' script comments",
156 	"POSIX does not allow the following keyword: %s",
157 	"POSIX does not allow a period ('.') as a shortcut for the last result",
158 	"POSIX requires parentheses around return expressions",
159 	"POSIX does not allow the following operator: %s",
160 	"POSIX does not allow comparison operators outside if statements or loops",
161 	"POSIX requires 0 or 1 comparison operators per condition",
162 	"POSIX requires all 3 parts of a for loop to be non-empty",
163 #if BC_ENABLE_EXTRA_MATH
164 	"POSIX does not allow exponential notation",
165 #else
166 	NULL,
167 #endif // BC_ENABLE_EXTRA_MATH
168 	"POSIX does not allow array references as function parameters",
169 	"POSIX does not allow void functions",
170 	"POSIX requires the left brace be on the same line as the function header",
171 #endif // BC_ENABLED
172 
173 };
174 
175 #if BC_ENABLE_HISTORY
176 const BcFlushType bc_flush_none = BC_FLUSH_NO_EXTRAS_NO_CLEAR;
177 const BcFlushType bc_flush_err = BC_FLUSH_NO_EXTRAS_CLEAR;
178 const BcFlushType bc_flush_save = BC_FLUSH_SAVE_EXTRAS_CLEAR;
179 #endif // BC_ENABLE_HISTORY
180 
181 #if BC_ENABLE_HISTORY
182 const char *bc_history_bad_terms[] = { "dumb", "cons25", "emacs", NULL };
183 
184 const char bc_history_tab[] = "        ";
185 const size_t bc_history_tab_len = sizeof(bc_history_tab) - 1;
186 
187 // These are listed in ascending order for efficiency.
188 const uint32_t bc_history_wchars[][2] = {
189 	{ 0x1100, 0x115F },
190 	{ 0x231A, 0x231B },
191 	{ 0x2329, 0x232A },
192 	{ 0x23E9, 0x23EC },
193 	{ 0x23F0, 0x23F0 },
194 	{ 0x23F3, 0x23F3 },
195 	{ 0x25FD, 0x25FE },
196 	{ 0x2614, 0x2615 },
197 	{ 0x2648, 0x2653 },
198 	{ 0x267F, 0x267F },
199 	{ 0x2693, 0x2693 },
200 	{ 0x26A1, 0x26A1 },
201 	{ 0x26AA, 0x26AB },
202 	{ 0x26BD, 0x26BE },
203 	{ 0x26C4, 0x26C5 },
204 	{ 0x26CE, 0x26CE },
205 	{ 0x26D4, 0x26D4 },
206 	{ 0x26EA, 0x26EA },
207 	{ 0x26F2, 0x26F3 },
208 	{ 0x26F5, 0x26F5 },
209 	{ 0x26FA, 0x26FA },
210 	{ 0x26FD, 0x26FD },
211 	{ 0x2705, 0x2705 },
212 	{ 0x270A, 0x270B },
213 	{ 0x2728, 0x2728 },
214 	{ 0x274C, 0x274C },
215 	{ 0x274E, 0x274E },
216 	{ 0x2753, 0x2755 },
217 	{ 0x2757, 0x2757 },
218 	{ 0x2795, 0x2797 },
219 	{ 0x27B0, 0x27B0 },
220 	{ 0x27BF, 0x27BF },
221 	{ 0x2B1B, 0x2B1C },
222 	{ 0x2B50, 0x2B50 },
223 	{ 0x2B55, 0x2B55 },
224 	{ 0x2E80, 0x2E99 },
225 	{ 0x2E9B, 0x2EF3 },
226 	{ 0x2F00, 0x2FD5 },
227 	{ 0x2FF0, 0x2FFB },
228 	{ 0x3001, 0x303E },
229 	{ 0x3041, 0x3096 },
230 	{ 0x3099, 0x30FF },
231 	{ 0x3105, 0x312D },
232 	{ 0x3131, 0x318E },
233 	{ 0x3190, 0x31BA },
234 	{ 0x31C0, 0x31E3 },
235 	{ 0x31F0, 0x321E },
236 	{ 0x3220, 0x3247 },
237 	{ 0x3250, 0x32FE },
238 	{ 0x3300, 0x4DBF },
239 	{ 0x4E00, 0xA48C },
240 	{ 0xA490, 0xA4C6 },
241 	{ 0xA960, 0xA97C },
242 	{ 0xAC00, 0xD7A3 },
243 	{ 0xF900, 0xFAFF },
244 	{ 0xFE10, 0xFE19 },
245 	{ 0xFE30, 0xFE52 },
246 	{ 0xFE54, 0xFE66 },
247 	{ 0xFE68, 0xFE6B },
248 	{ 0x16FE0, 0x16FE0 },
249 	{ 0x17000, 0x187EC },
250 	{ 0x18800, 0x18AF2 },
251 	{ 0x1B000, 0x1B001 },
252 	{ 0x1F004, 0x1F004 },
253 	{ 0x1F0CF, 0x1F0CF },
254 	{ 0x1F18E, 0x1F18E },
255 	{ 0x1F191, 0x1F19A },
256 	{ 0x1F200, 0x1F202 },
257 	{ 0x1F210, 0x1F23B },
258 	{ 0x1F240, 0x1F248 },
259 	{ 0x1F250, 0x1F251 },
260 	{ 0x1F300, 0x1F320 },
261 	{ 0x1F32D, 0x1F335 },
262 	{ 0x1F337, 0x1F37C },
263 	{ 0x1F37E, 0x1F393 },
264 	{ 0x1F3A0, 0x1F3CA },
265 	{ 0x1F3CF, 0x1F3D3 },
266 	{ 0x1F3E0, 0x1F3F0 },
267 	{ 0x1F3F4, 0x1F3F4 },
268 	{ 0x1F3F8, 0x1F43E },
269 	{ 0x1F440, 0x1F440 },
270 	{ 0x1F442, 0x1F4FC },
271 	{ 0x1F4FF, 0x1F53D },
272 	{ 0x1F54B, 0x1F54E },
273 	{ 0x1F550, 0x1F567 },
274 	{ 0x1F57A, 0x1F57A },
275 	{ 0x1F595, 0x1F596 },
276 	{ 0x1F5A4, 0x1F5A4 },
277 	{ 0x1F5FB, 0x1F64F },
278 	{ 0x1F680, 0x1F6C5 },
279 	{ 0x1F6CC, 0x1F6CC },
280 	{ 0x1F6D0, 0x1F6D2 },
281 	{ 0x1F6EB, 0x1F6EC },
282 	{ 0x1F6F4, 0x1F6F6 },
283 	{ 0x1F910, 0x1F91E },
284 	{ 0x1F920, 0x1F927 },
285 	{ 0x1F930, 0x1F930 },
286 	{ 0x1F933, 0x1F93E },
287 	{ 0x1F940, 0x1F94B },
288 	{ 0x1F950, 0x1F95E },
289 	{ 0x1F980, 0x1F991 },
290 	{ 0x1F9C0, 0x1F9C0 },
291 	{ 0x20000, 0x2FFFD },
292 	{ 0x30000, 0x3FFFD },
293 };
294 
295 const size_t bc_history_wchars_len =
296 	sizeof(bc_history_wchars) / sizeof(bc_history_wchars[0]);
297 
298 // These are listed in ascending order for efficiency.
299 const uint32_t bc_history_combo_chars[] = {
300 	0x0300,0x0301,0x0302,0x0303,0x0304,0x0305,0x0306,0x0307,
301 	0x0308,0x0309,0x030A,0x030B,0x030C,0x030D,0x030E,0x030F,
302 	0x0310,0x0311,0x0312,0x0313,0x0314,0x0315,0x0316,0x0317,
303 	0x0318,0x0319,0x031A,0x031B,0x031C,0x031D,0x031E,0x031F,
304 	0x0320,0x0321,0x0322,0x0323,0x0324,0x0325,0x0326,0x0327,
305 	0x0328,0x0329,0x032A,0x032B,0x032C,0x032D,0x032E,0x032F,
306 	0x0330,0x0331,0x0332,0x0333,0x0334,0x0335,0x0336,0x0337,
307 	0x0338,0x0339,0x033A,0x033B,0x033C,0x033D,0x033E,0x033F,
308 	0x0340,0x0341,0x0342,0x0343,0x0344,0x0345,0x0346,0x0347,
309 	0x0348,0x0349,0x034A,0x034B,0x034C,0x034D,0x034E,0x034F,
310 	0x0350,0x0351,0x0352,0x0353,0x0354,0x0355,0x0356,0x0357,
311 	0x0358,0x0359,0x035A,0x035B,0x035C,0x035D,0x035E,0x035F,
312 	0x0360,0x0361,0x0362,0x0363,0x0364,0x0365,0x0366,0x0367,
313 	0x0368,0x0369,0x036A,0x036B,0x036C,0x036D,0x036E,0x036F,
314 	0x0483,0x0484,0x0485,0x0486,0x0487,0x0591,0x0592,0x0593,
315 	0x0594,0x0595,0x0596,0x0597,0x0598,0x0599,0x059A,0x059B,
316 	0x059C,0x059D,0x059E,0x059F,0x05A0,0x05A1,0x05A2,0x05A3,
317 	0x05A4,0x05A5,0x05A6,0x05A7,0x05A8,0x05A9,0x05AA,0x05AB,
318 	0x05AC,0x05AD,0x05AE,0x05AF,0x05B0,0x05B1,0x05B2,0x05B3,
319 	0x05B4,0x05B5,0x05B6,0x05B7,0x05B8,0x05B9,0x05BA,0x05BB,
320 	0x05BC,0x05BD,0x05BF,0x05C1,0x05C2,0x05C4,0x05C5,0x05C7,
321 	0x0610,0x0611,0x0612,0x0613,0x0614,0x0615,0x0616,0x0617,
322 	0x0618,0x0619,0x061A,0x064B,0x064C,0x064D,0x064E,0x064F,
323 	0x0650,0x0651,0x0652,0x0653,0x0654,0x0655,0x0656,0x0657,
324 	0x0658,0x0659,0x065A,0x065B,0x065C,0x065D,0x065E,0x065F,
325 	0x0670,0x06D6,0x06D7,0x06D8,0x06D9,0x06DA,0x06DB,0x06DC,
326 	0x06DF,0x06E0,0x06E1,0x06E2,0x06E3,0x06E4,0x06E7,0x06E8,
327 	0x06EA,0x06EB,0x06EC,0x06ED,0x0711,0x0730,0x0731,0x0732,
328 	0x0733,0x0734,0x0735,0x0736,0x0737,0x0738,0x0739,0x073A,
329 	0x073B,0x073C,0x073D,0x073E,0x073F,0x0740,0x0741,0x0742,
330 	0x0743,0x0744,0x0745,0x0746,0x0747,0x0748,0x0749,0x074A,
331 	0x07A6,0x07A7,0x07A8,0x07A9,0x07AA,0x07AB,0x07AC,0x07AD,
332 	0x07AE,0x07AF,0x07B0,0x07EB,0x07EC,0x07ED,0x07EE,0x07EF,
333 	0x07F0,0x07F1,0x07F2,0x07F3,0x0816,0x0817,0x0818,0x0819,
334 	0x081B,0x081C,0x081D,0x081E,0x081F,0x0820,0x0821,0x0822,
335 	0x0823,0x0825,0x0826,0x0827,0x0829,0x082A,0x082B,0x082C,
336 	0x082D,0x0859,0x085A,0x085B,0x08D4,0x08D5,0x08D6,0x08D7,
337 	0x08D8,0x08D9,0x08DA,0x08DB,0x08DC,0x08DD,0x08DE,0x08DF,
338 	0x08E0,0x08E1,0x08E3,0x08E4,0x08E5,0x08E6,0x08E7,0x08E8,
339 	0x08E9,0x08EA,0x08EB,0x08EC,0x08ED,0x08EE,0x08EF,0x08F0,
340 	0x08F1,0x08F2,0x08F3,0x08F4,0x08F5,0x08F6,0x08F7,0x08F8,
341 	0x08F9,0x08FA,0x08FB,0x08FC,0x08FD,0x08FE,0x08FF,0x0900,
342 	0x0901,0x0902,0x093A,0x093C,0x0941,0x0942,0x0943,0x0944,
343 	0x0945,0x0946,0x0947,0x0948,0x094D,0x0951,0x0952,0x0953,
344 	0x0954,0x0955,0x0956,0x0957,0x0962,0x0963,0x0981,0x09BC,
345 	0x09C1,0x09C2,0x09C3,0x09C4,0x09CD,0x09E2,0x09E3,0x0A01,
346 	0x0A02,0x0A3C,0x0A41,0x0A42,0x0A47,0x0A48,0x0A4B,0x0A4C,
347 	0x0A4D,0x0A51,0x0A70,0x0A71,0x0A75,0x0A81,0x0A82,0x0ABC,
348 	0x0AC1,0x0AC2,0x0AC3,0x0AC4,0x0AC5,0x0AC7,0x0AC8,0x0ACD,
349 	0x0AE2,0x0AE3,0x0B01,0x0B3C,0x0B3F,0x0B41,0x0B42,0x0B43,
350 	0x0B44,0x0B4D,0x0B56,0x0B62,0x0B63,0x0B82,0x0BC0,0x0BCD,
351 	0x0C00,0x0C3E,0x0C3F,0x0C40,0x0C46,0x0C47,0x0C48,0x0C4A,
352 	0x0C4B,0x0C4C,0x0C4D,0x0C55,0x0C56,0x0C62,0x0C63,0x0C81,
353 	0x0CBC,0x0CBF,0x0CC6,0x0CCC,0x0CCD,0x0CE2,0x0CE3,0x0D01,
354 	0x0D41,0x0D42,0x0D43,0x0D44,0x0D4D,0x0D62,0x0D63,0x0DCA,
355 	0x0DD2,0x0DD3,0x0DD4,0x0DD6,0x0E31,0x0E34,0x0E35,0x0E36,
356 	0x0E37,0x0E38,0x0E39,0x0E3A,0x0E47,0x0E48,0x0E49,0x0E4A,
357 	0x0E4B,0x0E4C,0x0E4D,0x0E4E,0x0EB1,0x0EB4,0x0EB5,0x0EB6,
358 	0x0EB7,0x0EB8,0x0EB9,0x0EBB,0x0EBC,0x0EC8,0x0EC9,0x0ECA,
359 	0x0ECB,0x0ECC,0x0ECD,0x0F18,0x0F19,0x0F35,0x0F37,0x0F39,
360 	0x0F71,0x0F72,0x0F73,0x0F74,0x0F75,0x0F76,0x0F77,0x0F78,
361 	0x0F79,0x0F7A,0x0F7B,0x0F7C,0x0F7D,0x0F7E,0x0F80,0x0F81,
362 	0x0F82,0x0F83,0x0F84,0x0F86,0x0F87,0x0F8D,0x0F8E,0x0F8F,
363 	0x0F90,0x0F91,0x0F92,0x0F93,0x0F94,0x0F95,0x0F96,0x0F97,
364 	0x0F99,0x0F9A,0x0F9B,0x0F9C,0x0F9D,0x0F9E,0x0F9F,0x0FA0,
365 	0x0FA1,0x0FA2,0x0FA3,0x0FA4,0x0FA5,0x0FA6,0x0FA7,0x0FA8,
366 	0x0FA9,0x0FAA,0x0FAB,0x0FAC,0x0FAD,0x0FAE,0x0FAF,0x0FB0,
367 	0x0FB1,0x0FB2,0x0FB3,0x0FB4,0x0FB5,0x0FB6,0x0FB7,0x0FB8,
368 	0x0FB9,0x0FBA,0x0FBB,0x0FBC,0x0FC6,0x102D,0x102E,0x102F,
369 	0x1030,0x1032,0x1033,0x1034,0x1035,0x1036,0x1037,0x1039,
370 	0x103A,0x103D,0x103E,0x1058,0x1059,0x105E,0x105F,0x1060,
371 	0x1071,0x1072,0x1073,0x1074,0x1082,0x1085,0x1086,0x108D,
372 	0x109D,0x135D,0x135E,0x135F,0x1712,0x1713,0x1714,0x1732,
373 	0x1733,0x1734,0x1752,0x1753,0x1772,0x1773,0x17B4,0x17B5,
374 	0x17B7,0x17B8,0x17B9,0x17BA,0x17BB,0x17BC,0x17BD,0x17C6,
375 	0x17C9,0x17CA,0x17CB,0x17CC,0x17CD,0x17CE,0x17CF,0x17D0,
376 	0x17D1,0x17D2,0x17D3,0x17DD,0x180B,0x180C,0x180D,0x1885,
377 	0x1886,0x18A9,0x1920,0x1921,0x1922,0x1927,0x1928,0x1932,
378 	0x1939,0x193A,0x193B,0x1A17,0x1A18,0x1A1B,0x1A56,0x1A58,
379 	0x1A59,0x1A5A,0x1A5B,0x1A5C,0x1A5D,0x1A5E,0x1A60,0x1A62,
380 	0x1A65,0x1A66,0x1A67,0x1A68,0x1A69,0x1A6A,0x1A6B,0x1A6C,
381 	0x1A73,0x1A74,0x1A75,0x1A76,0x1A77,0x1A78,0x1A79,0x1A7A,
382 	0x1A7B,0x1A7C,0x1A7F,0x1AB0,0x1AB1,0x1AB2,0x1AB3,0x1AB4,
383 	0x1AB5,0x1AB6,0x1AB7,0x1AB8,0x1AB9,0x1ABA,0x1ABB,0x1ABC,
384 	0x1ABD,0x1B00,0x1B01,0x1B02,0x1B03,0x1B34,0x1B36,0x1B37,
385 	0x1B38,0x1B39,0x1B3A,0x1B3C,0x1B42,0x1B6B,0x1B6C,0x1B6D,
386 	0x1B6E,0x1B6F,0x1B70,0x1B71,0x1B72,0x1B73,0x1B80,0x1B81,
387 	0x1BA2,0x1BA3,0x1BA4,0x1BA5,0x1BA8,0x1BA9,0x1BAB,0x1BAC,
388 	0x1BAD,0x1BE6,0x1BE8,0x1BE9,0x1BED,0x1BEF,0x1BF0,0x1BF1,
389 	0x1C2C,0x1C2D,0x1C2E,0x1C2F,0x1C30,0x1C31,0x1C32,0x1C33,
390 	0x1C36,0x1C37,0x1CD0,0x1CD1,0x1CD2,0x1CD4,0x1CD5,0x1CD6,
391 	0x1CD7,0x1CD8,0x1CD9,0x1CDA,0x1CDB,0x1CDC,0x1CDD,0x1CDE,
392 	0x1CDF,0x1CE0,0x1CE2,0x1CE3,0x1CE4,0x1CE5,0x1CE6,0x1CE7,
393 	0x1CE8,0x1CED,0x1CF4,0x1CF8,0x1CF9,0x1DC0,0x1DC1,0x1DC2,
394 	0x1DC3,0x1DC4,0x1DC5,0x1DC6,0x1DC7,0x1DC8,0x1DC9,0x1DCA,
395 	0x1DCB,0x1DCC,0x1DCD,0x1DCE,0x1DCF,0x1DD0,0x1DD1,0x1DD2,
396 	0x1DD3,0x1DD4,0x1DD5,0x1DD6,0x1DD7,0x1DD8,0x1DD9,0x1DDA,
397 	0x1DDB,0x1DDC,0x1DDD,0x1DDE,0x1DDF,0x1DE0,0x1DE1,0x1DE2,
398 	0x1DE3,0x1DE4,0x1DE5,0x1DE6,0x1DE7,0x1DE8,0x1DE9,0x1DEA,
399 	0x1DEB,0x1DEC,0x1DED,0x1DEE,0x1DEF,0x1DF0,0x1DF1,0x1DF2,
400 	0x1DF3,0x1DF4,0x1DF5,0x1DFB,0x1DFC,0x1DFD,0x1DFE,0x1DFF,
401 	0x20D0,0x20D1,0x20D2,0x20D3,0x20D4,0x20D5,0x20D6,0x20D7,
402 	0x20D8,0x20D9,0x20DA,0x20DB,0x20DC,0x20E1,0x20E5,0x20E6,
403 	0x20E7,0x20E8,0x20E9,0x20EA,0x20EB,0x20EC,0x20ED,0x20EE,
404 	0x20EF,0x20F0,0x2CEF,0x2CF0,0x2CF1,0x2D7F,0x2DE0,0x2DE1,
405 	0x2DE2,0x2DE3,0x2DE4,0x2DE5,0x2DE6,0x2DE7,0x2DE8,0x2DE9,
406 	0x2DEA,0x2DEB,0x2DEC,0x2DED,0x2DEE,0x2DEF,0x2DF0,0x2DF1,
407 	0x2DF2,0x2DF3,0x2DF4,0x2DF5,0x2DF6,0x2DF7,0x2DF8,0x2DF9,
408 	0x2DFA,0x2DFB,0x2DFC,0x2DFD,0x2DFE,0x2DFF,0x302A,0x302B,
409 	0x302C,0x302D,0x3099,0x309A,0xA66F,0xA674,0xA675,0xA676,
410 	0xA677,0xA678,0xA679,0xA67A,0xA67B,0xA67C,0xA67D,0xA69E,
411 	0xA69F,0xA6F0,0xA6F1,0xA802,0xA806,0xA80B,0xA825,0xA826,
412 	0xA8C4,0xA8C5,0xA8E0,0xA8E1,0xA8E2,0xA8E3,0xA8E4,0xA8E5,
413 	0xA8E6,0xA8E7,0xA8E8,0xA8E9,0xA8EA,0xA8EB,0xA8EC,0xA8ED,
414 	0xA8EE,0xA8EF,0xA8F0,0xA8F1,0xA926,0xA927,0xA928,0xA929,
415 	0xA92A,0xA92B,0xA92C,0xA92D,0xA947,0xA948,0xA949,0xA94A,
416 	0xA94B,0xA94C,0xA94D,0xA94E,0xA94F,0xA950,0xA951,0xA980,
417 	0xA981,0xA982,0xA9B3,0xA9B6,0xA9B7,0xA9B8,0xA9B9,0xA9BC,
418 	0xA9E5,0xAA29,0xAA2A,0xAA2B,0xAA2C,0xAA2D,0xAA2E,0xAA31,
419 	0xAA32,0xAA35,0xAA36,0xAA43,0xAA4C,0xAA7C,0xAAB0,0xAAB2,
420 	0xAAB3,0xAAB4,0xAAB7,0xAAB8,0xAABE,0xAABF,0xAAC1,0xAAEC,
421 	0xAAED,0xAAF6,0xABE5,0xABE8,0xABED,0xFB1E,0xFE00,0xFE01,
422 	0xFE02,0xFE03,0xFE04,0xFE05,0xFE06,0xFE07,0xFE08,0xFE09,
423 	0xFE0A,0xFE0B,0xFE0C,0xFE0D,0xFE0E,0xFE0F,0xFE20,0xFE21,
424 	0xFE22,0xFE23,0xFE24,0xFE25,0xFE26,0xFE27,0xFE28,0xFE29,
425 	0xFE2A,0xFE2B,0xFE2C,0xFE2D,0xFE2E,0xFE2F,
426 	0x101FD,0x102E0,0x10376,0x10377,0x10378,0x10379,0x1037A,0x10A01,
427 	0x10A02,0x10A03,0x10A05,0x10A06,0x10A0C,0x10A0D,0x10A0E,0x10A0F,
428 	0x10A38,0x10A39,0x10A3A,0x10A3F,0x10AE5,0x10AE6,0x11001,0x11038,
429 	0x11039,0x1103A,0x1103B,0x1103C,0x1103D,0x1103E,0x1103F,0x11040,
430 	0x11041,0x11042,0x11043,0x11044,0x11045,0x11046,0x1107F,0x11080,
431 	0x11081,0x110B3,0x110B4,0x110B5,0x110B6,0x110B9,0x110BA,0x11100,
432 	0x11101,0x11102,0x11127,0x11128,0x11129,0x1112A,0x1112B,0x1112D,
433 	0x1112E,0x1112F,0x11130,0x11131,0x11132,0x11133,0x11134,0x11173,
434 	0x11180,0x11181,0x111B6,0x111B7,0x111B8,0x111B9,0x111BA,0x111BB,
435 	0x111BC,0x111BD,0x111BE,0x111CA,0x111CB,0x111CC,0x1122F,0x11230,
436 	0x11231,0x11234,0x11236,0x11237,0x1123E,0x112DF,0x112E3,0x112E4,
437 	0x112E5,0x112E6,0x112E7,0x112E8,0x112E9,0x112EA,0x11300,0x11301,
438 	0x1133C,0x11340,0x11366,0x11367,0x11368,0x11369,0x1136A,0x1136B,
439 	0x1136C,0x11370,0x11371,0x11372,0x11373,0x11374,0x11438,0x11439,
440 	0x1143A,0x1143B,0x1143C,0x1143D,0x1143E,0x1143F,0x11442,0x11443,
441 	0x11444,0x11446,0x114B3,0x114B4,0x114B5,0x114B6,0x114B7,0x114B8,
442 	0x114BA,0x114BF,0x114C0,0x114C2,0x114C3,0x115B2,0x115B3,0x115B4,
443 	0x115B5,0x115BC,0x115BD,0x115BF,0x115C0,0x115DC,0x115DD,0x11633,
444 	0x11634,0x11635,0x11636,0x11637,0x11638,0x11639,0x1163A,0x1163D,
445 	0x1163F,0x11640,0x116AB,0x116AD,0x116B0,0x116B1,0x116B2,0x116B3,
446 	0x116B4,0x116B5,0x116B7,0x1171D,0x1171E,0x1171F,0x11722,0x11723,
447 	0x11724,0x11725,0x11727,0x11728,0x11729,0x1172A,0x1172B,0x11C30,
448 	0x11C31,0x11C32,0x11C33,0x11C34,0x11C35,0x11C36,0x11C38,0x11C39,
449 	0x11C3A,0x11C3B,0x11C3C,0x11C3D,0x11C3F,0x11C92,0x11C93,0x11C94,
450 	0x11C95,0x11C96,0x11C97,0x11C98,0x11C99,0x11C9A,0x11C9B,0x11C9C,
451 	0x11C9D,0x11C9E,0x11C9F,0x11CA0,0x11CA1,0x11CA2,0x11CA3,0x11CA4,
452 	0x11CA5,0x11CA6,0x11CA7,0x11CAA,0x11CAB,0x11CAC,0x11CAD,0x11CAE,
453 	0x11CAF,0x11CB0,0x11CB2,0x11CB3,0x11CB5,0x11CB6,0x16AF0,0x16AF1,
454 	0x16AF2,0x16AF3,0x16AF4,0x16B30,0x16B31,0x16B32,0x16B33,0x16B34,
455 	0x16B35,0x16B36,0x16F8F,0x16F90,0x16F91,0x16F92,0x1BC9D,0x1BC9E,
456 	0x1D167,0x1D168,0x1D169,0x1D17B,0x1D17C,0x1D17D,0x1D17E,0x1D17F,
457 	0x1D180,0x1D181,0x1D182,0x1D185,0x1D186,0x1D187,0x1D188,0x1D189,
458 	0x1D18A,0x1D18B,0x1D1AA,0x1D1AB,0x1D1AC,0x1D1AD,0x1D242,0x1D243,
459 	0x1D244,0x1DA00,0x1DA01,0x1DA02,0x1DA03,0x1DA04,0x1DA05,0x1DA06,
460 	0x1DA07,0x1DA08,0x1DA09,0x1DA0A,0x1DA0B,0x1DA0C,0x1DA0D,0x1DA0E,
461 	0x1DA0F,0x1DA10,0x1DA11,0x1DA12,0x1DA13,0x1DA14,0x1DA15,0x1DA16,
462 	0x1DA17,0x1DA18,0x1DA19,0x1DA1A,0x1DA1B,0x1DA1C,0x1DA1D,0x1DA1E,
463 	0x1DA1F,0x1DA20,0x1DA21,0x1DA22,0x1DA23,0x1DA24,0x1DA25,0x1DA26,
464 	0x1DA27,0x1DA28,0x1DA29,0x1DA2A,0x1DA2B,0x1DA2C,0x1DA2D,0x1DA2E,
465 	0x1DA2F,0x1DA30,0x1DA31,0x1DA32,0x1DA33,0x1DA34,0x1DA35,0x1DA36,
466 	0x1DA3B,0x1DA3C,0x1DA3D,0x1DA3E,0x1DA3F,0x1DA40,0x1DA41,0x1DA42,
467 	0x1DA43,0x1DA44,0x1DA45,0x1DA46,0x1DA47,0x1DA48,0x1DA49,0x1DA4A,
468 	0x1DA4B,0x1DA4C,0x1DA4D,0x1DA4E,0x1DA4F,0x1DA50,0x1DA51,0x1DA52,
469 	0x1DA53,0x1DA54,0x1DA55,0x1DA56,0x1DA57,0x1DA58,0x1DA59,0x1DA5A,
470 	0x1DA5B,0x1DA5C,0x1DA5D,0x1DA5E,0x1DA5F,0x1DA60,0x1DA61,0x1DA62,
471 	0x1DA63,0x1DA64,0x1DA65,0x1DA66,0x1DA67,0x1DA68,0x1DA69,0x1DA6A,
472 	0x1DA6B,0x1DA6C,0x1DA75,0x1DA84,0x1DA9B,0x1DA9C,0x1DA9D,0x1DA9E,
473 	0x1DA9F,0x1DAA1,0x1DAA2,0x1DAA3,0x1DAA4,0x1DAA5,0x1DAA6,0x1DAA7,
474 	0x1DAA8,0x1DAA9,0x1DAAA,0x1DAAB,0x1DAAC,0x1DAAD,0x1DAAE,0x1DAAF,
475 	0x1E000,0x1E001,0x1E002,0x1E003,0x1E004,0x1E005,0x1E006,0x1E008,
476 	0x1E009,0x1E00A,0x1E00B,0x1E00C,0x1E00D,0x1E00E,0x1E00F,0x1E010,
477 	0x1E011,0x1E012,0x1E013,0x1E014,0x1E015,0x1E016,0x1E017,0x1E018,
478 	0x1E01B,0x1E01C,0x1E01D,0x1E01E,0x1E01F,0x1E020,0x1E021,0x1E023,
479 	0x1E024,0x1E026,0x1E027,0x1E028,0x1E029,0x1E02A,0x1E8D0,0x1E8D1,
480 	0x1E8D2,0x1E8D3,0x1E8D4,0x1E8D5,0x1E8D6,0x1E944,0x1E945,0x1E946,
481 	0x1E947,0x1E948,0x1E949,0x1E94A,0xE0100,0xE0101,0xE0102,0xE0103,
482 	0xE0104,0xE0105,0xE0106,0xE0107,0xE0108,0xE0109,0xE010A,0xE010B,
483 	0xE010C,0xE010D,0xE010E,0xE010F,0xE0110,0xE0111,0xE0112,0xE0113,
484 	0xE0114,0xE0115,0xE0116,0xE0117,0xE0118,0xE0119,0xE011A,0xE011B,
485 	0xE011C,0xE011D,0xE011E,0xE011F,0xE0120,0xE0121,0xE0122,0xE0123,
486 	0xE0124,0xE0125,0xE0126,0xE0127,0xE0128,0xE0129,0xE012A,0xE012B,
487 	0xE012C,0xE012D,0xE012E,0xE012F,0xE0130,0xE0131,0xE0132,0xE0133,
488 	0xE0134,0xE0135,0xE0136,0xE0137,0xE0138,0xE0139,0xE013A,0xE013B,
489 	0xE013C,0xE013D,0xE013E,0xE013F,0xE0140,0xE0141,0xE0142,0xE0143,
490 	0xE0144,0xE0145,0xE0146,0xE0147,0xE0148,0xE0149,0xE014A,0xE014B,
491 	0xE014C,0xE014D,0xE014E,0xE014F,0xE0150,0xE0151,0xE0152,0xE0153,
492 	0xE0154,0xE0155,0xE0156,0xE0157,0xE0158,0xE0159,0xE015A,0xE015B,
493 	0xE015C,0xE015D,0xE015E,0xE015F,0xE0160,0xE0161,0xE0162,0xE0163,
494 	0xE0164,0xE0165,0xE0166,0xE0167,0xE0168,0xE0169,0xE016A,0xE016B,
495 	0xE016C,0xE016D,0xE016E,0xE016F,0xE0170,0xE0171,0xE0172,0xE0173,
496 	0xE0174,0xE0175,0xE0176,0xE0177,0xE0178,0xE0179,0xE017A,0xE017B,
497 	0xE017C,0xE017D,0xE017E,0xE017F,0xE0180,0xE0181,0xE0182,0xE0183,
498 	0xE0184,0xE0185,0xE0186,0xE0187,0xE0188,0xE0189,0xE018A,0xE018B,
499 	0xE018C,0xE018D,0xE018E,0xE018F,0xE0190,0xE0191,0xE0192,0xE0193,
500 	0xE0194,0xE0195,0xE0196,0xE0197,0xE0198,0xE0199,0xE019A,0xE019B,
501 	0xE019C,0xE019D,0xE019E,0xE019F,0xE01A0,0xE01A1,0xE01A2,0xE01A3,
502 	0xE01A4,0xE01A5,0xE01A6,0xE01A7,0xE01A8,0xE01A9,0xE01AA,0xE01AB,
503 	0xE01AC,0xE01AD,0xE01AE,0xE01AF,0xE01B0,0xE01B1,0xE01B2,0xE01B3,
504 	0xE01B4,0xE01B5,0xE01B6,0xE01B7,0xE01B8,0xE01B9,0xE01BA,0xE01BB,
505 	0xE01BC,0xE01BD,0xE01BE,0xE01BF,0xE01C0,0xE01C1,0xE01C2,0xE01C3,
506 	0xE01C4,0xE01C5,0xE01C6,0xE01C7,0xE01C8,0xE01C9,0xE01CA,0xE01CB,
507 	0xE01CC,0xE01CD,0xE01CE,0xE01CF,0xE01D0,0xE01D1,0xE01D2,0xE01D3,
508 	0xE01D4,0xE01D5,0xE01D6,0xE01D7,0xE01D8,0xE01D9,0xE01DA,0xE01DB,
509 	0xE01DC,0xE01DD,0xE01DE,0xE01DF,0xE01E0,0xE01E1,0xE01E2,0xE01E3,
510 	0xE01E4,0xE01E5,0xE01E6,0xE01E7,0xE01E8,0xE01E9,0xE01EA,0xE01EB,
511 	0xE01EC,0xE01ED,0xE01EE,0xE01EF,
512 };
513 
514 const size_t bc_history_combo_chars_len =
515 	sizeof(bc_history_combo_chars) / sizeof(bc_history_combo_chars[0]);
516 
517 #if BC_DEBUG_CODE
518 BcFile bc_history_debug_fp;
519 char *bc_history_debug_buf;
520 #endif // BC_DEBUG_CODE
521 #endif // BC_ENABLE_HISTORY
522 
523 const char bc_func_main[] = "(main)";
524 const char bc_func_read[] = "(read)";
525 
526 #if BC_DEBUG_CODE
527 const char* bc_inst_names[] = {
528 
529 #if BC_ENABLED
530 	"BC_INST_INC",
531 	"BC_INST_DEC",
532 #endif // BC_ENABLED
533 
534 	"BC_INST_NEG",
535 	"BC_INST_BOOL_NOT",
536 #if BC_ENABLE_EXTRA_MATH
537 	"BC_INST_TRUNC",
538 #endif // BC_ENABLE_EXTRA_MATH
539 
540 	"BC_INST_POWER",
541 	"BC_INST_MULTIPLY",
542 	"BC_INST_DIVIDE",
543 	"BC_INST_MODULUS",
544 	"BC_INST_PLUS",
545 	"BC_INST_MINUS",
546 
547 #if BC_ENABLE_EXTRA_MATH
548 	"BC_INST_PLACES",
549 
550 	"BC_INST_LSHIFT",
551 	"BC_INST_RSHIFT",
552 #endif // BC_ENABLE_EXTRA_MATH
553 
554 	"BC_INST_REL_EQ",
555 	"BC_INST_REL_LE",
556 	"BC_INST_REL_GE",
557 	"BC_INST_REL_NE",
558 	"BC_INST_REL_LT",
559 	"BC_INST_REL_GT",
560 
561 	"BC_INST_BOOL_OR",
562 	"BC_INST_BOOL_AND",
563 
564 #if BC_ENABLED
565 	"BC_INST_ASSIGN_POWER",
566 	"BC_INST_ASSIGN_MULTIPLY",
567 	"BC_INST_ASSIGN_DIVIDE",
568 	"BC_INST_ASSIGN_MODULUS",
569 	"BC_INST_ASSIGN_PLUS",
570 	"BC_INST_ASSIGN_MINUS",
571 #if BC_ENABLE_EXTRA_MATH
572 	"BC_INST_ASSIGN_PLACES",
573 	"BC_INST_ASSIGN_LSHIFT",
574 	"BC_INST_ASSIGN_RSHIFT",
575 #endif // BC_ENABLE_EXTRA_MATH
576 	"BC_INST_ASSIGN",
577 
578 	"BC_INST_ASSIGN_POWER_NO_VAL",
579 	"BC_INST_ASSIGN_MULTIPLY_NO_VAL",
580 	"BC_INST_ASSIGN_DIVIDE_NO_VAL",
581 	"BC_INST_ASSIGN_MODULUS_NO_VAL",
582 	"BC_INST_ASSIGN_PLUS_NO_VAL",
583 	"BC_INST_ASSIGN_MINUS_NO_VAL",
584 #if BC_ENABLE_EXTRA_MATH
585 	"BC_INST_ASSIGN_PLACES_NO_VAL",
586 	"BC_INST_ASSIGN_LSHIFT_NO_VAL",
587 	"BC_INST_ASSIGN_RSHIFT_NO_VAL",
588 #endif // BC_ENABLE_EXTRA_MATH
589 #endif // BC_ENABLED
590 	"BC_INST_ASSIGN_NO_VAL",
591 
592 	"BC_INST_NUM",
593 	"BC_INST_VAR",
594 	"BC_INST_ARRAY_ELEM",
595 #if BC_ENABLED
596 	"BC_INST_ARRAY",
597 #endif // BC_ENABLED
598 
599 	"BC_INST_ZERO",
600 	"BC_INST_ONE",
601 
602 #if BC_ENABLED
603 	"BC_INST_LAST",
604 #endif // BC_ENABLED
605 	"BC_INST_IBASE",
606 	"BC_INST_OBASE",
607 	"BC_INST_SCALE",
608 #if BC_ENABLE_EXTRA_MATH
609 	"BC_INST_SEED",
610 #endif // BC_ENABLE_EXTRA_MATH
611 	"BC_INST_LENGTH",
612 	"BC_INST_SCALE_FUNC",
613 	"BC_INST_SQRT",
614 	"BC_INST_ABS",
615 #if BC_ENABLE_EXTRA_MATH
616 	"BC_INST_IRAND",
617 #endif // BC_ENABLE_EXTRA_MATH
618 	"BC_INST_READ",
619 #if BC_ENABLE_EXTRA_MATH
620 	"BC_INST_RAND",
621 #endif // BC_ENABLE_EXTRA_MATH
622 	"BC_INST_MAXIBASE",
623 	"BC_INST_MAXOBASE",
624 	"BC_INST_MAXSCALE",
625 #if BC_ENABLE_EXTRA_MATH
626 	"BC_INST_MAXRAND",
627 #endif // BC_ENABLE_EXTRA_MATH
628 
629 	"BC_INST_PRINT",
630 	"BC_INST_PRINT_POP",
631 	"BC_INST_STR",
632 	"BC_INST_PRINT_STR",
633 
634 #if BC_ENABLED
635 	"BC_INST_JUMP",
636 	"BC_INST_JUMP_ZERO",
637 
638 	"BC_INST_CALL",
639 
640 	"BC_INST_RET",
641 	"BC_INST_RET0",
642 	"BC_INST_RET_VOID",
643 
644 	"BC_INST_HALT",
645 #endif // BC_ENABLED
646 
647 #if DC_ENABLED
648 	"BC_INST_POP",
649 	"BC_INST_POP_EXEC",
650 	"BC_INST_MODEXP",
651 	"BC_INST_DIVMOD",
652 
653 	"BC_INST_EXECUTE",
654 	"BC_INST_EXEC_COND",
655 
656 	"BC_INST_ASCIIFY",
657 	"BC_INST_PRINT_STREAM",
658 
659 	"BC_INST_PRINT_STACK",
660 	"BC_INST_CLEAR_STACK",
661 	"BC_INST_STACK_LEN",
662 	"BC_INST_DUPLICATE",
663 	"BC_INST_SWAP",
664 
665 	"BC_INST_LOAD",
666 	"BC_INST_PUSH_VAR",
667 	"BC_INST_PUSH_TO_VAR",
668 
669 	"BC_INST_QUIT",
670 	"BC_INST_NQUIT",
671 #endif // DC_ENABLED
672 };
673 #endif // BC_DEBUG_CODE
674 
675 const char bc_parse_zero[2] = "0";
676 const char bc_parse_one[2] = "1";
677 
678 #if BC_ENABLED
679 const BcLexKeyword bc_lex_kws[] = {
680 	BC_LEX_KW_ENTRY("auto", 4, true),
681 	BC_LEX_KW_ENTRY("break", 5, true),
682 	BC_LEX_KW_ENTRY("continue", 8, false),
683 	BC_LEX_KW_ENTRY("define", 6, true),
684 	BC_LEX_KW_ENTRY("for", 3, true),
685 	BC_LEX_KW_ENTRY("if", 2, true),
686 	BC_LEX_KW_ENTRY("limits", 6, false),
687 	BC_LEX_KW_ENTRY("return", 6, true),
688 	BC_LEX_KW_ENTRY("while", 5, true),
689 	BC_LEX_KW_ENTRY("halt", 4, false),
690 	BC_LEX_KW_ENTRY("last", 4, false),
691 	BC_LEX_KW_ENTRY("ibase", 5, true),
692 	BC_LEX_KW_ENTRY("obase", 5, true),
693 	BC_LEX_KW_ENTRY("scale", 5, true),
694 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
695 	BC_LEX_KW_ENTRY("seed", 4, false),
696 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
697 	BC_LEX_KW_ENTRY("length", 6, true),
698 	BC_LEX_KW_ENTRY("print", 5, false),
699 	BC_LEX_KW_ENTRY("sqrt", 4, true),
700 	BC_LEX_KW_ENTRY("abs", 3, false),
701 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
702 	BC_LEX_KW_ENTRY("irand", 5, false),
703 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
704 	BC_LEX_KW_ENTRY("quit", 4, true),
705 	BC_LEX_KW_ENTRY("read", 4, false),
706 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
707 	BC_LEX_KW_ENTRY("rand", 4, false),
708 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
709 	BC_LEX_KW_ENTRY("maxibase", 8, false),
710 	BC_LEX_KW_ENTRY("maxobase", 8, false),
711 	BC_LEX_KW_ENTRY("maxscale", 8, false),
712 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
713 	BC_LEX_KW_ENTRY("maxrand", 7, false),
714 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
715 	BC_LEX_KW_ENTRY("else", 4, false),
716 };
717 
718 const size_t bc_lex_kws_len = sizeof(bc_lex_kws) / sizeof(BcLexKeyword);
719 
720 // This is an array that corresponds to token types. An entry is
721 // true if the token is valid in an expression, false otherwise.
722 const uint8_t bc_parse_exprs[] = {
723 	BC_PARSE_EXPR_ENTRY(false, false, true, true, true, true, true, true),
724 	BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true),
725 	BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true),
726 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
727 	BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true),
728 	BC_PARSE_EXPR_ENTRY(true, true, false, false, true, true, false, false),
729 	BC_PARSE_EXPR_ENTRY(false, false, false, false, false, true, true, false),
730 	BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, false, false),
731 	BC_PARSE_EXPR_ENTRY(false, true, true, true, true, true, true, false),
732 	BC_PARSE_EXPR_ENTRY(true, true, true, false, true, true, true, true),
733 	BC_PARSE_EXPR_ENTRY(true, true, false, 0, 0, 0, 0, 0)
734 #elif BC_ENABLE_EXTRA_MATH // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
735 	BC_PARSE_EXPR_ENTRY(true, true, true, true, true, true, true, true),
736 	BC_PARSE_EXPR_ENTRY(true, true, false, false, true, true, false, false),
737 	BC_PARSE_EXPR_ENTRY(false, false, false, false, false, true, true, false),
738 	BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, false, false),
739 	BC_PARSE_EXPR_ENTRY(false, true, true, true, true, true, false, true),
740 	BC_PARSE_EXPR_ENTRY(true, false, true, true, true, true, false, 0),
741 #else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
742 	BC_PARSE_EXPR_ENTRY(true, true, true, false, false, true, true, false),
743 	BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, true, true),
744 	BC_PARSE_EXPR_ENTRY(false, false, false, false, false, false, false, false),
745 	BC_PARSE_EXPR_ENTRY(false, false, true, true, true, true, true, false),
746 	BC_PARSE_EXPR_ENTRY(true, true, false, true, true, true, true, false)
747 #endif // BC_ENABLE_EXTRA_MATH
748 };
749 
750 // This is an array of data for operators that correspond to token types.
751 const uchar bc_parse_ops[] = {
752 	BC_PARSE_OP(0, false), BC_PARSE_OP(0, false),
753 	BC_PARSE_OP(1, false), BC_PARSE_OP(1, false),
754 #if BC_ENABLE_EXTRA_MATH
755 	BC_PARSE_OP(2, false),
756 #endif // BC_ENABLE_EXTRA_MATH
757 	BC_PARSE_OP(4, false),
758 	BC_PARSE_OP(5, true), BC_PARSE_OP(5, true), BC_PARSE_OP(5, true),
759 	BC_PARSE_OP(6, true), BC_PARSE_OP(6, true),
760 #if BC_ENABLE_EXTRA_MATH
761 	BC_PARSE_OP(3, false),
762 	BC_PARSE_OP(7, true), BC_PARSE_OP(7, true),
763 #endif // BC_ENABLE_EXTRA_MATH
764 	BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), BC_PARSE_OP(9, true),
765 	BC_PARSE_OP(9, true), BC_PARSE_OP(9, true), BC_PARSE_OP(9, true),
766 	BC_PARSE_OP(11, true), BC_PARSE_OP(10, true),
767 	BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), BC_PARSE_OP(8, false),
768 	BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), BC_PARSE_OP(8, false),
769 #if BC_ENABLE_EXTRA_MATH
770 	BC_PARSE_OP(8, false), BC_PARSE_OP(8, false), BC_PARSE_OP(8, false),
771 #endif // BC_ENABLE_EXTRA_MATH
772 	BC_PARSE_OP(8, false),
773 };
774 
775 // These identify what tokens can come after expressions in certain cases.
776 const BcParseNext bc_parse_next_expr =
777 	BC_PARSE_NEXT(4, BC_LEX_NLINE, BC_LEX_SCOLON, BC_LEX_RBRACE, BC_LEX_EOF);
778 const BcParseNext bc_parse_next_param =
779 	BC_PARSE_NEXT(2, BC_LEX_RPAREN, BC_LEX_COMMA);
780 const BcParseNext bc_parse_next_print =
781 	BC_PARSE_NEXT(4, BC_LEX_COMMA, BC_LEX_NLINE, BC_LEX_SCOLON, BC_LEX_EOF);
782 const BcParseNext bc_parse_next_rel = BC_PARSE_NEXT(1, BC_LEX_RPAREN);
783 const BcParseNext bc_parse_next_elem = BC_PARSE_NEXT(1, BC_LEX_RBRACKET);
784 const BcParseNext bc_parse_next_for = BC_PARSE_NEXT(1, BC_LEX_SCOLON);
785 const BcParseNext bc_parse_next_read =
786 	BC_PARSE_NEXT(2, BC_LEX_NLINE, BC_LEX_EOF);
787 #endif // BC_ENABLED
788 
789 #if DC_ENABLED
790 const uint8_t dc_lex_regs[] = {
791 	BC_LEX_OP_REL_EQ, BC_LEX_OP_REL_LE, BC_LEX_OP_REL_GE, BC_LEX_OP_REL_NE,
792 	BC_LEX_OP_REL_LT, BC_LEX_OP_REL_GT, BC_LEX_SCOLON, BC_LEX_COLON,
793 	BC_LEX_KW_ELSE, BC_LEX_LOAD, BC_LEX_LOAD_POP, BC_LEX_OP_ASSIGN,
794 	BC_LEX_STORE_PUSH,
795 };
796 
797 const size_t dc_lex_regs_len = sizeof(dc_lex_regs) / sizeof(uint8_t);
798 
799 const uchar dc_lex_tokens[] = {
800 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
801 	BC_LEX_KW_IRAND,
802 #else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
803 	BC_LEX_INVALID,
804 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
805 	BC_LEX_INVALID,
806 #if BC_ENABLE_EXTRA_MATH
807 	BC_LEX_OP_TRUNC,
808 #else // BC_ENABLE_EXTRA_MATH
809 	BC_LEX_INVALID,
810 #endif // BC_ENABLE_EXTRA_MATH
811 	BC_LEX_OP_MODULUS, BC_LEX_INVALID,
812 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
813 	BC_LEX_KW_RAND,
814 #else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
815 	BC_LEX_INVALID,
816 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
817 	BC_LEX_LPAREN, BC_LEX_RPAREN, BC_LEX_OP_MULTIPLY, BC_LEX_OP_PLUS,
818 	BC_LEX_INVALID, BC_LEX_OP_MINUS, BC_LEX_INVALID, BC_LEX_OP_DIVIDE,
819 	BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID,
820 	BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID,
821 	BC_LEX_INVALID, BC_LEX_INVALID,
822 	BC_LEX_COLON, BC_LEX_SCOLON, BC_LEX_OP_REL_GT, BC_LEX_OP_REL_EQ,
823 	BC_LEX_OP_REL_LT, BC_LEX_KW_READ,
824 #if BC_ENABLE_EXTRA_MATH
825 	BC_LEX_OP_PLACES,
826 #else // BC_ENABLE_EXTRA_MATH
827 	BC_LEX_INVALID,
828 #endif // BC_ENABLE_EXTRA_MATH
829 	BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_INVALID,
830 	BC_LEX_INVALID, BC_LEX_INVALID, BC_LEX_EQ_NO_REG,
831 #if BC_ENABLE_EXTRA_MATH
832 	BC_LEX_OP_LSHIFT,
833 #else // BC_ENABLE_EXTRA_MATH
834 	BC_LEX_INVALID,
835 #endif // BC_ENABLE_EXTRA_MATH
836 	BC_LEX_KW_IBASE,
837 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
838 	BC_LEX_KW_SEED,
839 #else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
840 	BC_LEX_INVALID,
841 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
842 	BC_LEX_KW_SCALE, BC_LEX_LOAD_POP, BC_LEX_OP_BOOL_AND, BC_LEX_OP_BOOL_NOT,
843 	BC_LEX_KW_OBASE, BC_LEX_PRINT_STREAM, BC_LEX_NQUIT, BC_LEX_POP,
844 	BC_LEX_STORE_PUSH, BC_LEX_KW_MAXIBASE, BC_LEX_KW_MAXOBASE,
845 	BC_LEX_KW_MAXSCALE,
846 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
847 	BC_LEX_KW_MAXRAND,
848 #else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
849 	BC_LEX_INVALID,
850 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
851 	BC_LEX_SCALE_FACTOR,
852 	BC_LEX_INVALID, BC_LEX_KW_LENGTH, BC_LEX_INVALID, BC_LEX_INVALID,
853 	BC_LEX_INVALID, BC_LEX_OP_POWER, BC_LEX_NEG, BC_LEX_INVALID,
854 	BC_LEX_ASCIIFY, BC_LEX_KW_ABS, BC_LEX_CLEAR_STACK, BC_LEX_DUPLICATE,
855 	BC_LEX_KW_ELSE, BC_LEX_PRINT_STACK, BC_LEX_INVALID,
856 #if BC_ENABLE_EXTRA_MATH
857 	BC_LEX_OP_RSHIFT,
858 #else // BC_ENABLE_EXTRA_MATH
859 	BC_LEX_INVALID,
860 #endif // BC_ENABLE_EXTRA_MATH
861 	BC_LEX_STORE_IBASE,
862 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
863 	BC_LEX_STORE_SEED,
864 #else // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
865 	BC_LEX_INVALID,
866 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
867 	BC_LEX_STORE_SCALE, BC_LEX_LOAD,
868 	BC_LEX_OP_BOOL_OR, BC_LEX_PRINT_POP, BC_LEX_STORE_OBASE, BC_LEX_KW_PRINT,
869 	BC_LEX_KW_QUIT, BC_LEX_SWAP, BC_LEX_OP_ASSIGN, BC_LEX_INVALID,
870 	BC_LEX_INVALID, BC_LEX_KW_SQRT, BC_LEX_INVALID, BC_LEX_EXECUTE,
871 	BC_LEX_INVALID, BC_LEX_STACK_LEVEL,
872 	BC_LEX_LBRACE, BC_LEX_OP_MODEXP, BC_LEX_RBRACE, BC_LEX_OP_DIVMOD,
873 	BC_LEX_INVALID
874 };
875 
876 const uchar dc_parse_insts[] = {
877 	BC_INST_INVALID, BC_INST_INVALID,
878 #if BC_ENABLED
879 	BC_INST_INVALID, BC_INST_INVALID,
880 #endif // BC_ENABLED
881 	BC_INST_INVALID, BC_INST_BOOL_NOT,
882 #if BC_ENABLE_EXTRA_MATH
883 	BC_INST_TRUNC,
884 #endif // BC_ENABLE_EXTRA_MATH
885 	BC_INST_POWER, BC_INST_MULTIPLY, BC_INST_DIVIDE, BC_INST_MODULUS,
886 	BC_INST_PLUS, BC_INST_MINUS,
887 #if BC_ENABLE_EXTRA_MATH
888 	BC_INST_PLACES,
889 	BC_INST_LSHIFT, BC_INST_RSHIFT,
890 #endif // BC_ENABLE_EXTRA_MATH
891 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
892 	BC_INST_INVALID, BC_INST_INVALID,
893 	BC_INST_BOOL_OR, BC_INST_BOOL_AND,
894 #if BC_ENABLED
895 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
896 	BC_INST_INVALID, BC_INST_INVALID,
897 #if BC_ENABLE_EXTRA_MATH
898 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
899 #endif // BC_ENABLE_EXTRA_MATH
900 #endif // BC_ENABLED
901 	BC_INST_INVALID,
902 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_REL_GT, BC_INST_REL_LT,
903 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_REL_GE,
904 	BC_INST_INVALID, BC_INST_REL_LE,
905 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
906 #if BC_ENABLED
907 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
908 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
909 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
910 #endif // BC_ENABLED
911 	BC_INST_IBASE, BC_INST_OBASE, BC_INST_SCALE,
912 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
913 	BC_INST_SEED,
914 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
915 	BC_INST_LENGTH, BC_INST_PRINT,
916 	BC_INST_SQRT, BC_INST_ABS,
917 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
918 	BC_INST_IRAND,
919 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
920 	BC_INST_QUIT, BC_INST_INVALID,
921 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
922 	BC_INST_RAND,
923 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
924 	BC_INST_MAXIBASE,
925 	BC_INST_MAXOBASE, BC_INST_MAXSCALE,
926 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
927 	BC_INST_MAXRAND,
928 #endif // BC_ENABLE_EXTRA_MATH
929 	BC_INST_INVALID,
930 	BC_INST_REL_EQ, BC_INST_MODEXP, BC_INST_DIVMOD, BC_INST_INVALID,
931 	BC_INST_EXECUTE, BC_INST_PRINT_STACK, BC_INST_CLEAR_STACK,
932 	BC_INST_STACK_LEN, BC_INST_DUPLICATE, BC_INST_SWAP, BC_INST_POP,
933 	BC_INST_ASCIIFY, BC_INST_PRINT_STREAM,
934 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
935 #if BC_ENABLE_EXTRA_MATH
936 	BC_INST_INVALID,
937 #endif // BC_ENABLE_EXTRA_MATH
938 	BC_INST_INVALID, BC_INST_INVALID, BC_INST_INVALID,
939 	BC_INST_PRINT_POP, BC_INST_NQUIT, BC_INST_SCALE_FUNC,
940 };
941 #endif // DC_ENABLED
942 
943 #endif // !BC_ENABLE_LIBRARY
944 
945 #if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
946 
947 const BcRandState bc_rand_multiplier = BC_RAND_MULTIPLIER;
948 
949 #endif // BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
950 
951 #if BC_LONG_BIT >= 64
952 const BcDig bc_num_bigdigMax[] = {
953 	709551616U,
954 	446744073U,
955 	18U,
956 };
957 const BcDig bc_num_bigdigMax2[] = {
958 	768211456U,
959 	374607431U,
960 	938463463U,
961 	282366920U,
962 	340U,
963 };
964 #else // BC_LONG_BIT >= 64
965 const BcDig bc_num_bigdigMax[] = {
966 	7296U,
967 	9496U,
968 	42U,
969 };
970 const BcDig bc_num_bigdigMax2[] = {
971 	1616U,
972 	955U,
973 	737U,
974 	6744U,
975 	1844U,
976 };
977 #endif // BC_LONG_BIT >= 64
978 
979 const size_t bc_num_bigdigMax_size = sizeof(bc_num_bigdigMax) / sizeof(BcDig);
980 const size_t bc_num_bigdigMax2_size = sizeof(bc_num_bigdigMax2) / sizeof(BcDig);
981 
982 const char bc_num_hex_digits[] = "0123456789ABCDEF";
983 
984 const BcBigDig bc_num_pow10[BC_BASE_DIGS + 1] = {
985 	1,
986 	10,
987 	100,
988 	1000,
989 	10000,
990 #if BC_BASE_DIGS > 4
991 	100000,
992 	1000000,
993 	10000000,
994 	100000000,
995 	1000000000,
996 #endif // BC_BASE_DIGS > 4
997 };
998 
999 #if !BC_ENABLE_LIBRARY
1000 
1001 const BcNumBinaryOp bc_program_ops[] = {
1002 	bc_num_pow, bc_num_mul, bc_num_div, bc_num_mod, bc_num_add, bc_num_sub,
1003 #if BC_ENABLE_EXTRA_MATH
1004 	bc_num_places, bc_num_lshift, bc_num_rshift,
1005 #endif // BC_ENABLE_EXTRA_MATH
1006 };
1007 
1008 const BcNumBinaryOpReq bc_program_opReqs[] = {
1009 	bc_num_powReq, bc_num_mulReq, bc_num_divReq, bc_num_divReq,
1010 	bc_num_addReq, bc_num_addReq,
1011 #if BC_ENABLE_EXTRA_MATH
1012 	bc_num_placesReq, bc_num_placesReq, bc_num_placesReq,
1013 #endif // BC_ENABLE_EXTRA_MATH
1014 };
1015 
1016 const BcProgramUnary bc_program_unarys[] = {
1017 	bc_program_negate, bc_program_not,
1018 #if BC_ENABLE_EXTRA_MATH
1019 	bc_program_trunc,
1020 #endif // BC_ENABLE_EXTRA_MATH
1021 };
1022 
1023 const char bc_program_exprs_name[] = "<exprs>";
1024 
1025 const char bc_program_stdin_name[] = "<stdin>";
1026 const char bc_program_ready_msg[] = "ready for more input\n";
1027 const size_t bc_program_ready_msg_len = sizeof(bc_program_ready_msg) - 1;
1028 const char bc_program_esc_chars[] = "ab\\efnqrt";
1029 const char bc_program_esc_seqs[] = "\a\b\\\\\f\n\"\r\t";
1030 
1031 #endif // !BC_ENABLE_LIBRARY
1032