| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef TOK_INCLUDED |
| 23 |
#define TOK_INCLUDED |
| 24 |
|
| 25 |
#ifndef STD_INCLUDED |
| 26 |
#include "std.h" |
| 27 |
#endif |
| 28 |
#ifndef LIN_INCLUDED |
| 29 |
#include "lin.h" |
| 30 |
#endif |
| 31 |
#ifndef MCH_INCLUDED |
| 32 |
#include "mch.h" |
| 33 |
#endif |
| 34 |
#ifndef ERR_INCLUDED |
| 35 |
#include "err.h" |
| 36 |
#endif |
| 37 |
#ifndef MCM_INCLUDED |
| 38 |
#include "mcm.h" |
| 39 |
#endif |
| 40 |
|
| 41 |
|
| 42 |
#define TOKHASHSIZE 256 |
| 43 |
|
| 44 |
|
| 45 |
#define TOKSTUNK 0 |
| 46 |
#define TOKSTFUNC 1 |
| 47 |
#define TOKSTOBJ 2 |
| 48 |
#define TOKSTPROP 3 |
| 49 |
#define TOKSTLOCAL 4 |
| 50 |
#define TOKSTSELF 5 |
| 51 |
#define TOKSTBIFN 6 |
| 52 |
#define TOKSTFWDOBJ 7 |
| 53 |
#define TOKSTFWDFN 8 |
| 54 |
#define TOKSTINHERIT 9 |
| 55 |
#define TOKSTEXTERN 10 |
| 56 |
#define TOKSTKW 11 |
| 57 |
#define TOKSTLABEL 12 |
| 58 |
#define TOKSTARGC 13 |
| 59 |
#define TOKSTPROPSPEC 14 |
| 60 |
|
| 61 |
|
| 62 |
#define TOKTEOF 1 |
| 63 |
|
| 64 |
|
| 65 |
#define TOKTPLUS 2 |
| 66 |
#define TOKTMINUS 3 |
| 67 |
#define TOKTDIV 4 |
| 68 |
#define TOKTTIMES 5 |
| 69 |
#define TOKTNOT 6 |
| 70 |
#define TOKTEQ 7 |
| 71 |
#define TOKTNE 8 |
| 72 |
#define TOKTGT 9 |
| 73 |
#define TOKTGE 10 |
| 74 |
#define TOKTLT 11 |
| 75 |
#define TOKTLE 12 |
| 76 |
#define TOKTMOD 13 |
| 77 |
#define TOKTBAND 14 |
| 78 |
#define TOKTBOR 15 |
| 79 |
#define TOKTXOR 16 |
| 80 |
#define TOKTSHL 17 |
| 81 |
#define TOKTSHR 18 |
| 82 |
#define TOKTTILDE 30 |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
#define TOKTDOTSPEC 31 |
| 91 |
|
| 92 |
|
| 93 |
#define TOKTEXPINH 32 |
| 94 |
|
| 95 |
#define TOKTLPAR 50 |
| 96 |
#define TOKTRPAR 51 |
| 97 |
#define TOKTCOLON 52 |
| 98 |
#define TOKTDSTRING 53 |
| 99 |
#define TOKTSSTRING 54 |
| 100 |
#define TOKTNUMBER 55 |
| 101 |
#define TOKTSYMBOL 56 |
| 102 |
#define TOKTINVALID 57 |
| 103 |
#define TOKTLBRACK 58 |
| 104 |
#define TOKTRBRACK 59 |
| 105 |
#define TOKTLBRACE 60 |
| 106 |
#define TOKTRBRACE 61 |
| 107 |
#define TOKTSEM 62 |
| 108 |
#define TOKTCOMMA 63 |
| 109 |
#define TOKTDOT 64 |
| 110 |
#define TOKTOR 65 |
| 111 |
#define TOKTAND 66 |
| 112 |
#define TOKTIF 67 |
| 113 |
#define TOKTELSE 68 |
| 114 |
#define TOKTWHILE 69 |
| 115 |
#define TOKTFUNCTION 70 |
| 116 |
#define TOKTRETURN 71 |
| 117 |
#define TOKTLOCAL 72 |
| 118 |
#define TOKTOBJECT 73 |
| 119 |
#define TOKTBREAK 74 |
| 120 |
#define TOKTCONTINUE 75 |
| 121 |
#define TOKTLIST 76 |
| 122 |
#define TOKTNIL 77 |
| 123 |
#define TOKTTRUE 78 |
| 124 |
#define TOKTPASS 79 |
| 125 |
#define TOKTCLASS 80 |
| 126 |
#define TOKTEXIT 81 |
| 127 |
#define TOKTABORT 82 |
| 128 |
#define TOKTASKDO 83 |
| 129 |
#define TOKTASKIO 84 |
| 130 |
#define TOKTPOUND 85 |
| 131 |
#define TOKTQUESTION 86 |
| 132 |
#define TOKTCOMPOUND 87 |
| 133 |
#define TOKTIOSYN 88 |
| 134 |
#define TOKTDOSYN 89 |
| 135 |
#define TOKTEXTERN 90 |
| 136 |
#define TOKTFORMAT 91 |
| 137 |
#define TOKTDO 92 |
| 138 |
#define TOKTFOR 93 |
| 139 |
#define TOKTNEW 94 |
| 140 |
#define TOKTDELETE 95 |
| 141 |
|
| 142 |
|
| 143 |
#define TOKTINC 150 |
| 144 |
#define TOKTPOSTINC 151 |
| 145 |
#define TOKTDEC 152 |
| 146 |
#define TOKTPOSTDEC 153 |
| 147 |
#define TOKTPLEQ 154 |
| 148 |
#define TOKTMINEQ 155 |
| 149 |
#define TOKTDIVEQ 156 |
| 150 |
#define TOKTTIMEQ 157 |
| 151 |
#define TOKTASSIGN 158 |
| 152 |
#define TOKTMODEQ 159 |
| 153 |
#define TOKTBANDEQ 160 |
| 154 |
#define TOKTBOREQ 161 |
| 155 |
#define TOKTXOREQ 162 |
| 156 |
#define TOKTSHLEQ 163 |
| 157 |
#define TOKTSHREQ 164 |
| 158 |
|
| 159 |
#define TOKTSWITCH 200 |
| 160 |
#define TOKTCASE 201 |
| 161 |
#define TOKTDEFAULT 202 |
| 162 |
#define TOKTGOTO 203 |
| 163 |
#define TOKTELLIPSIS 204 |
| 164 |
#define TOKTSPECIAL 205 |
| 165 |
#define TOKTREPLACE 206 |
| 166 |
#define TOKTMODIFY 207 |
| 167 |
|
| 168 |
#define TOKTEQEQ 208 |
| 169 |
#define TOKTPOINTER 209 |
| 170 |
|
| 171 |
|
| 172 |
#define TOKNAMMAX 39 |
| 173 |
|
| 174 |
|
| 175 |
typedef struct toksdef toksdef; |
| 176 |
struct toksdef |
| 177 |
{ |
| 178 |
uchar tokstyp; |
| 179 |
uchar tokshsh; |
| 180 |
ushort toksval; |
| 181 |
ushort toksfr; |
| 182 |
uchar tokslen; |
| 183 |
char toksnam[TOKNAMMAX]; |
| 184 |
}; |
| 185 |
|
| 186 |
|
| 187 |
struct toks1def |
| 188 |
{ |
| 189 |
uchar tokstyp; |
| 190 |
uchar tokshsh; |
| 191 |
ushort toksval; |
| 192 |
ushort toksfr; |
| 193 |
uchar tokslen; |
| 194 |
char toksnam[1]; |
| 195 |
}; |
| 196 |
typedef struct toks1def toks1def; |
| 197 |
|
| 198 |
|
| 199 |
typedef struct toktdef toktdef; |
| 200 |
struct toktdef |
| 201 |
{ |
| 202 |
void (*toktfadd)(toktdef *tab, char *name, int namel, int typ, |
| 203 |
int val, int hash); |
| 204 |
int (*toktfsea)(toktdef *tab, char *name, int namel, int hash, |
| 205 |
toksdef *ret); |
| 206 |
void (*toktfset)(toktdef *tab, toksdef *sym); |
| 207 |
|
| 208 |
void (*toktfeach)(toktdef *tab, |
| 209 |
void (*fn)(void *ctx, toksdef *sym), |
| 210 |
void *fnctx); |
| 211 |
toktdef *toktnxt; |
| 212 |
errcxdef *tokterr; |
| 213 |
}; |
| 214 |
|
| 215 |
|
| 216 |
#define TOKPOOLMAX 128 |
| 217 |
|
| 218 |
|
| 219 |
struct tokthpdef |
| 220 |
{ |
| 221 |
mcmon tokthpobj; |
| 222 |
uint tokthpofs; |
| 223 |
}; |
| 224 |
typedef struct tokthpdef tokthpdef; |
| 225 |
|
| 226 |
|
| 227 |
struct tokshdef |
| 228 |
{ |
| 229 |
tokthpdef tokshnxt; |
| 230 |
toksdef tokshsc; |
| 231 |
}; |
| 232 |
typedef struct tokshdef tokshdef; |
| 233 |
|
| 234 |
|
| 235 |
struct tokthdef |
| 236 |
{ |
| 237 |
toktdef tokthsc; |
| 238 |
mcmcxdef *tokthmem; |
| 239 |
tokthpdef tokthhsh[TOKHASHSIZE]; |
| 240 |
uint tokthpcnt; |
| 241 |
mcmon tokthpool[TOKPOOLMAX]; |
| 242 |
uint tokthfinal[TOKPOOLMAX]; |
| 243 |
uchar *tokthcpool; |
| 244 |
ushort tokthsize; |
| 245 |
ushort tokthofs; |
| 246 |
}; |
| 247 |
typedef struct tokthdef tokthdef; |
| 248 |
|
| 249 |
|
| 250 |
#define TOKTHSIZE 4096 |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
struct toktldef |
| 260 |
{ |
| 261 |
toktdef toktlsc; |
| 262 |
uchar *toktlptr; |
| 263 |
uchar *toktlnxt; |
| 264 |
uint toktlcnt; |
| 265 |
uint toktlsiz; |
| 266 |
}; |
| 267 |
typedef struct toktldef toktldef; |
| 268 |
|
| 269 |
struct tokdef |
| 270 |
{ |
| 271 |
int toktyp; |
| 272 |
int toklen; |
| 273 |
long tokval; |
| 274 |
ushort tokofs; |
| 275 |
uint tokhash; |
| 276 |
char toknam[TOKNAMMAX+1]; |
| 277 |
toksdef toksym; |
| 278 |
}; |
| 279 |
typedef struct tokdef tokdef; |
| 280 |
|
| 281 |
|
| 282 |
#define TOKSCMAX 3 |
| 283 |
typedef struct tokscdef tokscdef; |
| 284 |
struct tokscdef |
| 285 |
{ |
| 286 |
tokscdef *tokscnxt; |
| 287 |
int toksctyp; |
| 288 |
int toksclen; |
| 289 |
char tokscstr[TOKSCMAX+1]; |
| 290 |
}; |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
#if TOKSCMAX == 3 |
| 300 |
# define toksceq(str1, str2, len1, len2) \ |
| 301 |
((len2) >= (len1) \ |
| 302 |
&& ((len1) == 1 \ |
| 303 |
|| ((str1)[1] == (str2)[1] \ |
| 304 |
&& ((len1) == 2 \ |
| 305 |
|| (str1)[2] == (str2)[2])))) |
| 306 |
#endif |
| 307 |
#ifndef toksceq |
| 308 |
# define toksceq(str1, str2, len) (!memcmp(str1, str2, (size_t)(len))) |
| 309 |
#endif |
| 310 |
|
| 311 |
|
| 312 |
struct tokldef |
| 313 |
{ |
| 314 |
int tokltyp; |
| 315 |
char toklstr[TOKSCMAX+1]; |
| 316 |
}; |
| 317 |
typedef struct tokldef tokldef; |
| 318 |
|
| 319 |
|
| 320 |
typedef struct tokpdef tokpdef; |
| 321 |
struct tokpdef |
| 322 |
{ |
| 323 |
tokpdef *tokpnxt; |
| 324 |
int tokplen; |
| 325 |
char tokpdir[1]; |
| 326 |
}; |
| 327 |
|
| 328 |
|
| 329 |
typedef struct tokdfdef tokdfdef; |
| 330 |
struct tokdfdef |
| 331 |
{ |
| 332 |
tokdfdef *nxt; |
| 333 |
char *nm; |
| 334 |
int len; |
| 335 |
int explen; |
| 336 |
char expan[1]; |
| 337 |
}; |
| 338 |
|
| 339 |
|
| 340 |
#define TOKDFHSHSIZ 64 |
| 341 |
#define TOKDFHSHMASK 63 |
| 342 |
|
| 343 |
|
| 344 |
#define TOKIFNEST 64 |
| 345 |
|
| 346 |
|
| 347 |
#define TOKIF_IF_YES 1 |
| 348 |
#define TOKIF_IF_NO 2 |
| 349 |
#define TOKIF_ELSE_YES 3 |
| 350 |
#define TOKIF_ELSE_NO 4 |
| 351 |
|
| 352 |
|
| 353 |
#define TOKMACNEST 20 |
| 354 |
|
| 355 |
|
| 356 |
struct tokcxdef |
| 357 |
{ |
| 358 |
errcxdef *tokcxerr; |
| 359 |
mcmcxdef *tokcxmem; |
| 360 |
struct dbgcxdef *tokcxdbg; |
| 361 |
lindef *tokcxlin; |
| 362 |
tokpdef *tokcxinc; |
| 363 |
toktdef *tokcxstab; |
| 364 |
void *tokcxscx; |
| 365 |
ushort (*tokcxsst)(void *ctx); |
| 366 |
|
| 367 |
void (*tokcxsad)(void *ctx, char *str, ushort len); |
| 368 |
|
| 369 |
void (*tokcxsend)(void *ctx); |
| 370 |
char *tokcxmsav[TOKMACNEST]; |
| 371 |
ushort tokcxmsvl[TOKMACNEST]; |
| 372 |
int tokcxmlvl; |
| 373 |
int tokcxflg; |
| 374 |
# define TOKCXFINMAC 0x01 |
| 375 |
# define TOKCXCASEFOLD 0x02 |
| 376 |
# define TOKCXFCMODE 0x04 |
| 377 |
# define TOKCXF_EMBED_PAREN_PRE 0x08 |
| 378 |
# define TOKCXF_EMBED_PAREN_AFT 0x10 |
| 379 |
# define TOKCXFLIN2 0x20 |
| 380 |
tokdef tokcxcur; |
| 381 |
char *tokcxbuf; |
| 382 |
ushort tokcxbsz; |
| 383 |
char *tokcxptr; |
| 384 |
ushort tokcxlen; |
| 385 |
uchar tokcxinx[256]; |
| 386 |
tokdfdef *tokcxdf[TOKDFHSHSIZ]; |
| 387 |
int tokcxifcnt; |
| 388 |
char tokcxif[TOKIFNEST]; |
| 389 |
int tokcxifcur; |
| 390 |
struct linfdef *tokcxhdr; |
| 391 |
tokscdef *tokcxsc[1]; |
| 392 |
}; |
| 393 |
typedef struct tokcxdef tokcxdef; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
tokcxdef *tokcxini(errcxdef *errctx, mcmcxdef *mctx, tokldef *sctab); |
| 398 |
|
| 399 |
|
| 400 |
void tokaddinc(tokcxdef *ctx, char *path, int pathlen); |
| 401 |
|
| 402 |
|
| 403 |
uint tokhsh(char *nam); |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
void tok_case_fold(tokcxdef *ctx, tokdef *tok); |
| 412 |
|
| 413 |
|
| 414 |
void tokthini(errcxdef *errctx, mcmcxdef *memctx, toktdef *toktab1); |
| 415 |
|
| 416 |
|
| 417 |
void tokthadd(toktdef *toktab, char *name, int namel, |
| 418 |
int typ, int val, int hash); |
| 419 |
|
| 420 |
|
| 421 |
void tokthset(toktdef *toktab, toksdef *sym); |
| 422 |
|
| 423 |
|
| 424 |
int tokthsea(toktdef *tab, char *name, int namel, int hash, |
| 425 |
toksdef *ret); |
| 426 |
|
| 427 |
|
| 428 |
void toktheach(toktdef *tab, void (*cb)(void *ctx, toksdef *sym), |
| 429 |
void *ctx); |
| 430 |
|
| 431 |
|
| 432 |
int tokthfind(toktdef *tab, int typ, uint val, toksdef *sym); |
| 433 |
|
| 434 |
|
| 435 |
void toktlini(errcxdef *errctx, toktldef *toktab, |
| 436 |
uchar *mem, uint siz); |
| 437 |
|
| 438 |
|
| 439 |
void toktladd(toktdef *toktab, char *name, int namel, |
| 440 |
int typ, int val, int hash); |
| 441 |
|
| 442 |
|
| 443 |
int toktlsea(toktdef *tab, char *name, int namel, int hash, |
| 444 |
toksdef *ret); |
| 445 |
|
| 446 |
|
| 447 |
void toktlset(toktdef *toktab, toksdef *sym); |
| 448 |
|
| 449 |
|
| 450 |
void toktleach(toktdef *tab, void (*cb)(void *ctx, toksdef *sym), |
| 451 |
void *ctx); |
| 452 |
|
| 453 |
|
| 454 |
void toktldel(toktldef *tab); |
| 455 |
|
| 456 |
|
| 457 |
int toknext(tokcxdef *ctx); |
| 458 |
|
| 459 |
|
| 460 |
int tokget1(tokcxdef *ctx, tokdef *tok, int consume); |
| 461 |
|
| 462 |
|
| 463 |
void tok_add_define(tokcxdef *ctx, char *sym, int len, |
| 464 |
char *expan, int explen); |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
void tok_add_define_cvtcase(tokcxdef *ctx, char *sym, int len, |
| 471 |
char *expan, int explen); |
| 472 |
|
| 473 |
|
| 474 |
void tok_add_define_num_cvtcase(tokcxdef *ctx, char *sym, int len, int num); |
| 475 |
|
| 476 |
|
| 477 |
void tok_del_define(tokcxdef *ctx, char *sym, int len); |
| 478 |
|
| 479 |
|
| 480 |
void tok_read_defines(tokcxdef *ctx, osfildef *fp, errcxdef *ec); |
| 481 |
|
| 482 |
|
| 483 |
void tok_write_defines(tokcxdef *ctx, osfildef *fp, errcxdef *ec); |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
#define TOKISSYM(c) \ |
| 488 |
(isalpha((uchar)(c)) || isdigit((uchar)(c)) || (c)=='_' || (c)=='$') |
| 489 |
|
| 490 |
|
| 491 |
#define TOKISHEX(c) \ |
| 492 |
(isdigit((uchar)(c))||((c)>='a'&&(c)<='f')||((c)>='A'&&(c)<='F')) |
| 493 |
#define TOKISOCT(c) \ |
| 494 |
(isdigit((uchar)(c))&&!((c)=='8'||(c)=='9')) |
| 495 |
|
| 496 |
#define TOKHEX2INT(c) \ |
| 497 |
(isdigit((uchar)c)?(c)-'0':((c)>='a'?(c)-'a'+10:(c)-'A'+10)) |
| 498 |
#define TOKOCT2INT(c) ((c)-'0') |
| 499 |
#define TOKDEC2INT(c) ((c)-'0') |
| 500 |
|
| 501 |
#endif |