Skip to content

Commit a778e21

Browse files
committed
tad more progress on literal numerics
1 parent df850ca commit a778e21

File tree

1 file changed

+73
-4
lines changed

1 file changed

+73
-4
lines changed

n82-tokenize.lex

+73-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@
4242
<data>\" yyput('"'); BEGIN(datastring);
4343
<datastring>\" yyput('"'); BEGIN(data);
4444

45-
//xxxxx need to handle literal numeric expressions here. Not just ASCII.
46-
// 0 = 0x11 = 17
47-
// 1 = 0x12 = 18
48-
// -1 = 0xF4 0x12 = -18
45+
//xxxxx need to handle literal numeric expressions here. Not just ASCII.
46+
-?[0-9.]+([%#!]|[DE][-+]?[0-9]+ if ( yytext[0] == '-')
47+
yyput(0xF1);
48+
yyput(atoi(yytext) + 0x11);
49+
BEGIN(INITIAL)
4950

5051
/* Newline ends <string>, <remark>, <data>, and <datastring> conditions. */
5152
<*>\r?\n yyput('\0'); BEGIN(INITIAL);
@@ -213,3 +214,71 @@ LOF yyput(0xff); yyput(0xa9);
213214

214215
/* The main() routine, yyput(), fixup_ptrs() */
215216
#include "m100-tokenize-main.c"
217+
218+
/* Literal number handling routine */
219+
int tokenize_number(char *s) {
220+
int len = strlen(s);
221+
if (len == 0) return 1;
222+
int sign = (s[0] == '-');
223+
if (sign) s++, len--;
224+
225+
226+
227+
return 0;
228+
}
229+
230+
// xxx this is not finished yet. xxxx
231+
// N82 integers can only range from -32768 to 32767
232+
/* Single digit integers are efficiently encoded as 0 = 0x11 to 9 = 0x1A. */
233+
// 0 = 0x11
234+
// 1 = 0x12
235+
// 9 = 0x1A
236+
237+
/* Minus sign is encoded as 0xF4 */
238+
// -1 = 0xF4 0x12
239+
240+
/* Numbers from 10 to 255 are encoded with an ID of 0F */
241+
// 10 = 0x0F0A
242+
// 255 = 0x0FFF
243+
244+
/* Numbers 256 to 32767 are encoded with an ID of 1C */
245+
// 256 1C 00 01
246+
// 257 1C 01 01
247+
// 512 1C 00 02
248+
// 32767 1C FF 7F
249+
250+
/* Single precision floating point. 1D B0 B1 B2 EX */
251+
// 32768 1D 00 00 00 90
252+
// 32769 1D 00 01 00 90
253+
// 65534 1D 00 FE 7F 90
254+
// 65535 1D 00 FF 7F 90
255+
// 131071 1D 80 FF 7F 91
256+
// 131072 1D 00 00 00 92
257+
258+
/* Double-precision floating point. ID: 1F */
259+
// 1F 00 00 00 00 00 00 00 7E .125# 2^-3
260+
// 1F 00 00 00 00 00 00 00 7F .25# 2^-2
261+
// 1F 00 00 00 00 00 00 00 80 .5# 2^-1
262+
// 1F 00 00 00 00 00 00 20 80 .625# 2^-1 + 2^-3
263+
// 1F 00 00 00 00 00 00 40 80 .75# 2^-1 + 2^-2
264+
// 1F 00 00 00 00 00 00 60 80 .875# 2^-1 + 2^-2 + 2^-3
265+
// 1F 80 00 00 00 00 00 00 FF 8.507059173023492D+37 -> (same)
266+
267+
/*******************************************************************/
268+
/* Microsoft Binary Format (MBF) for 64-bit floating point numbers */
269+
/* Tokenized as nine bytes: */
270+
/* ID B0 B1 B2 B3 B4 B5 B6 EX */
271+
/* */
272+
/* ID is 1F for double-precision floating point */
273+
/* Value is (-1)^Signbit x Mantissa ^ Exponent */
274+
/* 8-bit Exponent is EX-128 */
275+
/* Signbit is high bit of B6. (B6 is left with only 7 bits) */
276+
/* 55-bit Mantissa is B6 B5 B4 B3 B2 B1 B0 */
277+
/* */
278+
/* There is an implicit "1" bit at the start of the mantissa. */
279+
/* Note that the implicit 1 is AFTER the decimal point. */
280+
/* */
281+
/*******************************************************************/
282+
283+
284+

0 commit comments

Comments
 (0)