Overview
Comment: | Further progress on writing the lexer |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
c36edda36791645735354fb2c607cf16 |
User & Date: | user on 2018-04-22 00:44:59 |
Other Links: | manifest | tags |
Context
2018-04-27
| ||
20:25 | More codes and testing in class codes parser check-in: 02b262b608 user: user tags: trunk | |
2018-04-22
| ||
00:44 | Further progress on writing the lexer check-in: c36edda367 user: user tags: trunk | |
2018-04-20
| ||
05:04 | Add class.c and add more instruction names check-in: 06c8b2a469 user: user tags: trunk | |
Changes
Modified class.c from [a8af44a33c] to [c6330b030d].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #define TF_EQUAL 0x0002 #define TF_ABNORMAL 0x0004 #define TF_COMPAT 0x0008 #define TF_DIR 0x0010 #define TF_DROP 0x0020 #define TF_NAME 0x0080 #define TF_KEY 0x0100 | < > | 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 | #define TF_EQUAL 0x0002 #define TF_ABNORMAL 0x0004 #define TF_COMPAT 0x0008 #define TF_DIR 0x0010 #define TF_DROP 0x0020 #define TF_NAME 0x0080 #define TF_KEY 0x0100 #define TF_OPEN 0x0400 #define TF_CLOSE 0x0800 #define TF_INT 0x1000 #define TF_MACRO 0x4000 #define TF_EOF 0x8000 typedef struct { const char*txt; Uint32 num; } Op_Names; #include "instruc.h" #define Tokenf(x) (tokent&(x)) Class*classes[0x4000]; const char*messages[0x4000]; int max_animation=32; Sint32 max_volume=10000; static FILE*classfp; |
︙ | ︙ | |||
107 108 109 110 111 112 113 114 115 116 117 118 119 120 | } static int name_compar(const void*a,const void*b) { const Op_Names*x=a; const Op_Names*y=b; return strcmp(x->txt,y->txt); } #define ReturnToken(x,y) do{ tokent=x; tokenv=y; return; }while(0) static void nxttok(void) { int c,i; int fl=0; int n=0; int pr=0; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | } static int name_compar(const void*a,const void*b) { const Op_Names*x=a; const Op_Names*y=b; return strcmp(x->txt,y->txt); } static Class*initialize_class(int n,int f,const char*name) { Class*cl; if(classes[n]) fatal("Duplicate class number %d\n",n); cl=classes[n]=malloc(sizeof(Class)); if(!cl) fatal("Allocation failed\n"); cl->name=strdup(name); if(!cl->name) fatal("Allocation failed\n"); cl->edithelp=cl->gamehelp=0; cl->codes=cl->messages=cl->images=0; cl->height=cl->weight=cl->climb=cl->density=cl->volume=cl->strength=cl->arrivals=cl->departures=0; cl->temperature=cl->misc4=cl->misc5=cl->misc6=cl->misc7=0; cl->uservars=cl->hard[0]=cl->hard[1]=cl->hard[2]=cl->hard[3]=0; cl->oflags=cl->sharp[0]=cl->sharp[1]=cl->sharp[2]=cl->sharp[3]=0; cl->shape=cl->shovable=cl->collisionLayers=cl->nimages=0; cl->cflags=f; if(undef_class<=n) undef_class=n+1; } static int look_class_name(void) { int i; int u=undef_class; for(i=1;i<undef_class;i++) { if(classes[i]) { if(!strcmp(classes[i]->name,tokenstr)) { if(classes[i]->cflags&CF_NOCLASS2) classes[i]->cflags|=CF_NOCLASS1; return i; } } else { u=i; } } if(u==0x4000) ParseError("Too many class names; cannot add $%s\n",tokenstr); initialize_class(u,CF_NOCLASS1,tokenstr); return u; } static int look_message_name(void) { int i; int u=undef_message; for(i=0;i<undef_message;i++) { if(messages[i]) { if(!strcmp(messages[i],tokenstr)) return i; } else { u=i; } } if(u==0x4000) ParseError("Too many message names; cannot add #%s",tokenstr); if(u==undef_message) ++undef_message; messages[u]=strdup(tokenstr); if(!messages[u]) fatal("Allocation failed\n"); return u; } #define ReturnToken(x,y) do{ tokent=x; tokenv=y; return; }while(0) static void nxttok(void) { int c,i; int fl=0; int n=0; int pr=0; |
︙ | ︙ | |||
131 132 133 134 135 136 137 | while(c!=EOF && c!='\n') c=fgetc(classfp); ++linenum; goto again; } if(c=='(') ReturnToken(TF_OPEN,0); if(c==')') ReturnToken(TF_CLOSE,0); if(c=='"') { | | > | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | while(c!=EOF && c!='\n') c=fgetc(classfp); ++linenum; goto again; } if(c=='(') ReturnToken(TF_OPEN,0); if(c==')') ReturnToken(TF_CLOSE,0); if(c=='"') { tokent=TF_NAME|TF_ABNORMAL; tokenv=OP_STRING; read_quoted_string(); return; } if(c=='=') { fl|=TF_EQUAL; c=fgetc(classfp); } |
︙ | ︙ | |||
167 168 169 170 171 172 173 | switch(pr) { case 0: if(chkind[c=*tokenstr]==2) { char*e; if(c=='-' || c=='+') n=1; else n=0; if(n && !tokenstr[1]) goto norm; tokent=TF_INT; | | | > > | > > | | > > > > | > > | > > > > > > > | > > > > | 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 | switch(pr) { case 0: if(chkind[c=*tokenstr]==2) { char*e; if(c=='-' || c=='+') n=1; else n=0; if(n && !tokenstr[1]) goto norm; tokent=TF_INT; if(fl) ParseError("Invalid use of , and = in token\n"); if(c=='0' && tokenstr[1]=='x') { tokenv=strtol(tokenstr+2,&e,16); } else if(c=='0' && tokenstr[1]=='o') { tokenv=strtol(tokenstr+2,&e,8); } else { tokenv=strtol(tokenstr+n,&e,10); } if(e && *e) ParseError("Invalid token: %s\n",tokenstr); if(c=='-') tokenv=-tokenv; } else { static Op_Names key={tokenstr}; const Op_Names*op; norm: op=bsearch(&key,op_names,N_OP_NAMES,sizeof(Op_Names),name_compar); if(!op) ParseError("Invalid token: %s\n",tokenstr); tokenv=op->num&0xFFFF; tokent=op->num>>16; if(fl&~tokent) ParseError("Invalid use of , and = in token: %s\n",tokenstr); if(fl&TF_COMMA) tokenv+=0x0800; if(fl&TF_EQUAL) tokenv+=0x1000; tokent&=fl|~(TF_COMMA|TF_EQUAL); } break; case '$': if(fl) ParseError("Invalid use of , and = in token\n"); tokent=TF_NAME; tokenv=look_class_name()+0x4000; break; case '!': // Just ignore sounds for now if(fl) ParseError("Invalid use of , and = in token\n"); tokent=TF_NAME; tokenv=0x0400; break; case '%': if(fl&TF_COMMA) ParseError("Invalid use of , in token\n"); tokent=TF_NAME|fl; tokenv=OP_LOCAL; break; case '@': if(fl&TF_COMMA) ParseError("Invalid use of , in token\n"); tokent=TF_NAME|fl; break; case '#': if(fl) ParseError("Invalid use of , and = in token\n"); tokent=TF_NAME; tokenv=look_message_name()+0xC000; break; case ':': tokent=TF_NAME|TF_ABNORMAL|fl; tokenv=OP_LABEL; break; case '&': break; case '\'': if(fl) ParseError("Invalid use of , and = in token\n"); tokent=TF_NAME|TF_KEY; for(i=8;i<256;i++) { if(heromesh_key_names[i] && !strcmp(heromesh_key_names[i],tokenstr)) { tokenv=i; return; } } ParseError("Invalid Hero Mesh key name: %s\n",tokenstr); break; } } void load_classes(void) { int i; for(i=1;i<undef_class;i++) if(classes[i] && (classes[i]->cflags&CF_NOCLASS1)) fatal("Class $%s mentioned but not defined",classes[i]->name); } |
Modified heromesh.h from [f8e6ccfb6c] to [927413f183].
︙ | ︙ | |||
74 75 76 77 78 79 80 | Uint16*messages; // use 0xFFFF if no such message block; not present if CF_GROUP Uint16*images; // high bit is set if available to editor; not present if CF_GROUP Sint32 height,weight,climb,density,volume,strength,arrivals,departures; Sint32 temperature,misc4,misc5,misc6,misc7; Uint16 uservars,oflags; Uint16 sharp[4]; Uint16 hard[4]; | | | | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | Uint16*messages; // use 0xFFFF if no such message block; not present if CF_GROUP Uint16*images; // high bit is set if available to editor; not present if CF_GROUP Sint32 height,weight,climb,density,volume,strength,arrivals,departures; Sint32 temperature,misc4,misc5,misc6,misc7; Uint16 uservars,oflags; Uint16 sharp[4]; Uint16 hard[4]; Uint8 cflags,shape,shovable,collisionLayers,nimages; } Class; extern Class*classes[0x4000]; // 0 isn't a real class extern const char*messages[0x4000]; // index is 256 less than message number extern int max_animation; // max steps in animation queue (default 32) extern Sint32 max_volume; // max total volume to allow moving diagonally (default 10000) void load_classes(void); // == bindings == |
︙ | ︙ |
Modified instruc from [be5d10fd00] to [fbb7f15d4d].
︙ | ︙ | |||
177 178 179 180 181 182 183 | -DefaultImage -Help -EditorHelp -SUBS ; Main operations Animate | | | | | | | | | | | > | | 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 | -DefaultImage -Help -EditorHelp -SUBS ; Main operations Animate ,Assassinate ; destroy without sending any messages .Broadcast *BroadcastClass ; for (Broadcast [class]) .BroadcastEx ; broadcast with three arguments BroadcastSum ; Broadcast, but result is sum of return values BroadcastSumEx .Create DelInventory Delta .,Destroy FlushClass FlushObj GetInventory HeightAt IgnoreKey .,IntMove ; move without initializing Inertia ,JumpTo ,Loc ; same as: Xloc Yloc LocateMe LoseLevel MaxInventory ; error if more than that many slots in inventory .,Move .,MovePlus "Move+" ; obj.Inertia+=Strength instead of obj.Inertia=Strength .,MoveTo ; the internal MoveTo() function NewX NewY ,ObjAbove ObjClassAt ,ObjBelow ,ObjDir PopUp *PopUpArgs ; for (PopUp [number]) QueueTurn ; queue another turn that automatically occurs after this one .,Send .,SendEx ; send with three arguments SetInventory Sound Trace VolumeAt WinLevel ,XDir ,YDir |
︙ | ︙ |
Modified instruc.h from [8595c2a4b6] to [be3608b2e3].
︙ | ︙ | |||
306 307 308 309 310 311 312 | #define OP_OBJCLASSAT 32909 #define OP_OBJBELOW 32910 #define OP_OBJBELOW_C 34958 #define OP_OBJDIR 32911 #define OP_OBJDIR_C 34959 #define OP_POPUP 32912 #define OP_POPUPARGS 32913 | > | | | | | | | | | | | | | | | | | | | | | | 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | #define OP_OBJCLASSAT 32909 #define OP_OBJBELOW 32910 #define OP_OBJBELOW_C 34958 #define OP_OBJDIR 32911 #define OP_OBJDIR_C 34959 #define OP_POPUP 32912 #define OP_POPUPARGS 32913 #define OP_QUEUETURN 32914 #define OP_SEND 32915 #define OP_SEND_C 34963 #define OP_SEND_D 41107 #define OP_SEND_CD 43155 #define OP_SENDEX 32916 #define OP_SENDEX_C 34964 #define OP_SENDEX_D 41108 #define OP_SENDEX_CD 43156 #define OP_SETINVENTORY 32917 #define OP_SOUND 32918 #define OP_TRACE 32919 #define OP_VOLUMEAT 32920 #define OP_WINLEVEL 32921 #define OP_XDIR 32922 #define OP_XDIR_C 34970 #define OP_YDIR 32923 #define OP_YDIR_C 34971 #define OP_FUNCTION 32924 #define OP_LOCAL 32925 #define OP_LABEL 32926 #define OP_STRING 32927 #ifdef HEROMESH_CLASS static const Op_Names op_names[]={ {"*",8486933}, {"+",8421395}, {"-",8421396}, {".",10518528}, {"/",8486934}, |
︙ | ︙ | |||
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | {"ObjClassAt",8421517}, {"ObjDir",8487055}, {"PLAYERMOVING",8389133}, {"POSTINIT",8389138}, {"POUR",8389377}, {"POWER",8389386}, {"PopUp",8421520}, {"Quiz",8683627}, {"R",9437198}, {"RATCHET1",8389418}, {"RATCHET2",8389412}, {"RATTLE",8389403}, {"RB",9437197}, {"RF",9437199}, {"S",9437190}, {"SE",9437191}, {"SMALL_POP",8389389}, {"SPLASH",8389376}, {"STEAM",8389424}, {"STOP",8388608}, {"SUBS",8683632}, {"SUNK",8389131}, {"SW",9437189}, {"Self",8421474}, | > | | | | | | | | | | 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | {"ObjClassAt",8421517}, {"ObjDir",8487055}, {"PLAYERMOVING",8389133}, {"POSTINIT",8389138}, {"POUR",8389377}, {"POWER",8389386}, {"PopUp",8421520}, {"QueueTurn",8421522}, {"Quiz",8683627}, {"R",9437198}, {"RATCHET1",8389418}, {"RATCHET2",8389412}, {"RATTLE",8389403}, {"RB",9437197}, {"RF",9437199}, {"S",9437190}, {"SE",9437191}, {"SMALL_POP",8389389}, {"SPLASH",8389376}, {"STEAM",8389424}, {"STOP",8388608}, {"SUBS",8683632}, {"SUNK",8389131}, {"SW",9437189}, {"Self",8421474}, {"Send",10584211}, {"SendEx",10584212}, {"SetInventory",8421525}, {"Shape",8618030}, {"ShapeDir",8618053}, {"Sharp",8618052}, {"Shovable",8618054}, {"Sound",8421526}, {"Stealthy",8618078}, {"Strength",9142337}, {"TAHTASHH",8389409}, {"THMP_thmp",8389405}, {"THWIT",8389384}, {"TICK",8389391}, {"Temperature",9142316}, {"Trace",8421527}, {"UH_OH",8389382}, {"UNCORK",8389414}, {"UNHH",8389381}, {"UserSignal",8618076}, {"VACUUM",8389411}, {"VisualOnly",8618077}, {"Volume",9142329}, {"VolumeAt",8421528}, {"W",9437188}, {"WAHOO",8389400}, {"WHACK",8389423}, {"Weight",9142331}, {"WinLevel",8421529}, {"XDir",8487066}, {"Xloc",8486959}, {"YDir",8487067}, {"YEEHAW",8389401}, {"Yloc",8486960}, {"again",8683530}, {"band",8421403}, {"begin",8683529}, {"bit",8683551}, {"bit0",8388609}, |
︙ | ︙ | |||
591 592 593 594 595 596 597 | {"rsh",8486938}, {"swap",8421378}, {"then",8683527}, {"tuck",8421380}, {"until",8683531}, {"while",8683532}, }; | | | 593 594 595 596 597 598 599 600 601 | {"rsh",8486938}, {"swap",8421378}, {"then",8683527}, {"tuck",8421380}, {"until",8683531}, {"while",8683532}, }; #define N_OP_NAMES 262 #endif |
Modified quarks from [c0379a86e6] to [28bc2772ba].
︙ | ︙ | |||
204 205 206 207 208 209 210 211 | sqlMemStatus sqlSmallAllocations sqlCoveringIndexScan sqlPowerSafe ! Miscellaneous level | > | 204 205 206 207 208 209 210 211 212 | sqlMemStatus sqlSmallAllocations sqlCoveringIndexScan sqlPowerSafe ! Miscellaneous level tracePrefix |