Merge pull request #393 from YashasSamaga/refactor-enum-tokens

use enum for defining tokens
This commit is contained in:
Yashas Samaga B L 2019-04-24 11:41:14 +05:30 committed by GitHub
commit 4c0536989e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 116 additions and 109 deletions

View File

@ -188,7 +188,7 @@ typedef struct s_symbol {
/* Possible entries for "usage" /* Possible entries for "usage"
* *
* This byte is used as a serie of bits, the syntax is different for * This byte is used as a series of bits, the syntax is different for
* functions and other symbols: * functions and other symbols:
* *
* VARIABLE * VARIABLE
@ -238,7 +238,7 @@ typedef struct s_symbol {
*/ */
#define uRETNONE 0x10 #define uRETNONE 0x10
#define flgDEPRECATED 0x01 /* symbol is deprecated (avoid use) */ #define flagDEPRECATED 0x01 /* symbol is deprecated (avoid use) */
#define flagNAKED 0x10 /* function is naked */ #define flagNAKED 0x10 /* function is naked */
#define flagPREDEF 0x20 /* symbol is pre-defined; successor of uPREDEF */ #define flagPREDEF 0x20 /* symbol is pre-defined; successor of uPREDEF */
@ -317,108 +317,115 @@ typedef struct s_valuepair {
/* Tokens recognized by lex() /* Tokens recognized by lex()
* Some of these constants are assigned as well to the variable "lastst" (see SC1.C) * Some of these constants are assigned as well to the variable "lastst" (see SC1.C)
*/ */
#define tFIRST 256 /* value of first multi-character operator */ enum {
#define tMIDDLE 280 /* value of last multi-character operator */ /* multi-character operators */
#define tLAST 331 /* value of last multi-character match-able token */ tFIRST = 256, /* value of first multi-character operator */
/* multi-character operators */
#define taMULT 256 /* *= */ taMULT = tFIRST, /* *= */
#define taDIV 257 /* /= */ taDIV, /* /= */
#define taMOD 258 /* %= */ taMOD, /* %= */
#define taADD 259 /* += */ taADD, /* += */
#define taSUB 260 /* -= */ taSUB, /* -= */
#define taSHL 261 /* <<= */ taSHL, /* <<= */
#define taSHRU 262 /* >>>= */ taSHRU, /* >>>= */
#define taSHR 263 /* >>= */ taSHR, /* >>= */
#define taAND 264 /* &= */ taAND, /* &= */
#define taXOR 265 /* ^= */ taXOR, /* ^= */
#define taOR 266 /* |= */ taOR, /* |= */
#define tlOR 267 /* || */ tlOR, /* || */
#define tlAND 268 /* && */ tlAND, /* && */
#define tlEQ 269 /* == */ tlEQ, /* == */
#define tlNE 270 /* != */ tlNE, /* != */
#define tlLE 271 /* <= */ tlLE, /* <= */
#define tlGE 272 /* >= */ tlGE, /* >= */
#define tSHL 273 /* << */ tSHL, /* << */
#define tSHRU 274 /* >>> */ tSHRU, /* >>> */
#define tSHR 275 /* >> */ tSHR, /* >> */
#define tINC 276 /* ++ */ tINC, /* ++ */
#define tDEC 277 /* -- */ tDEC, /* -- */
#define tELLIPS 278 /* ... */ tELLIPS, /* ... */
#define tDBLDOT 279 /* .. */ tDBLDOT, /* .. */
#define tDBLCOLON 280 /* :: */
/* reserved words (statements) */ tMIDDLE = tDBLDOT, /* value of last multi-character operator */
#define tASSERT 281
#define tBEGIN 282 /* reserved words (statements) */
#define tBREAK 283 tASSERT,
#define tCASE 284 tBEGIN,
#define tCHAR 285 tBREAK,
#define tCONST 286 tCASE,
#define tCONTINUE 287 tCHAR,
#define tDEFAULT 288 tCONST,
#define tDEFINED 289 tCONTINUE,
#define tDO 290 tDEFAULT,
#define tELSE 291 tDEFINED,
#define tEMIT 292 tDO,
#define t__EMIT 293 tELSE,
#define tEND 294 tEMIT,
#define tENUM 295 t__EMIT,
#define tEXIT 296 tEND,
#define tFOR 297 tENUM,
#define tFORWARD 298 tEXIT,
#define tGOTO 299 tFOR,
#define tIF 300 tFORWARD,
#define tNATIVE 301 tGOTO,
#define tNEW 302 tIF,
#define tOPERATOR 303 tNATIVE,
#define tPUBLIC 304 tNEW,
#define tRETURN 305 tOPERATOR,
#define tSIZEOF 306 tPUBLIC,
#define tSLEEP 307 tRETURN,
#define tSTATE 308 tSIZEOF,
#define tSTATIC 309 tSLEEP,
#define tSTOCK 310 tSTATE,
#define tSWITCH 311 tSTATIC,
#define tTAGOF 312 tSTOCK,
#define tTHEN 313 tSWITCH,
#define tWHILE 314 tTAGOF,
/* compiler directives */ tTHEN,
#define tpASSERT 315 /* #assert */ tWHILE,
#define tpDEFINE 316
#define tpELSE 317 /* #else */ /* compiler directives */
#define tpELSEIF 318 /* #elseif */ tpASSERT, /* #assert */
#define tpEMIT 319 tpDEFINE,
#define tpENDIF 320 tpELSE, /* #else */
#define tpENDINPUT 321 tpELSEIF, /* #elseif */
#define tpENDSCRPT 322 tpEMIT,
#define tpERROR 323 tpENDIF,
#define tpFILE 324 tpENDINPUT,
#define tpIF 325 /* #if */ tpENDSCRPT,
#define tINCLUDE 326 tpERROR,
#define tpLINE 327 tpFILE,
#define tpPRAGMA 328 tpIF,/* #if */
#define tpTRYINCLUDE 329 tpINCLUDE,
#define tpUNDEF 330 tpLINE,
#define tpWARNING 331 tpPRAGMA,
/* semicolon is a special case, because it can be optional */ tpTRYINCLUDE,
#define tTERM 332 /* semicolon or newline */ tpUNDEF,
#define tENDEXPR 333 /* forced end of expression */ tpWARNING,
/* other recognized tokens */
#define tNUMBER 334 /* integer number */ tLAST = tpWARNING, /* value of last multi-character match-able token */
#define tRATIONAL 335 /* rational number */
#define tSYMBOL 336 /* semicolon is a special case, because it can be optional */
#define tLABEL 337 tTERM,/* semicolon or newline */
#define tSTRING 338 tENDEXPR, /* forced end of expression */
/* argument types for emit/__emit */ /* other recognized tokens */
#define teANY 339 /* any value */ tNUMBER,/* integer number */
#define teNUMERIC 340 /* integer/rational number */ tRATIONAL, /* rational number */
#define teDATA 341 /* data (variable name or address) */ tSYMBOL,
#define teLOCAL 342 /* local variable (name or offset) */ tLABEL,
#define teFUNCTN 343 /* Pawn function */ tSTRING,
#define teNATIVE 344 /* native function */ /* argument types for emit/__emit */
#define teNONNEG 345 /* nonnegative integer */ teANY , /* any value */
/* for assigment to "lastst" only (see SC1.C) */ teNUMERIC, /* integer/rational number */
#define tEXPR 346 teDATA , /* data (variable name or address) */
#define tENDLESS 347 /* endless loop */ teLOCAL, /* local variable (name or offset) */
teFUNCTN, /* Pawn function */
teNATIVE, /* native function */
teNONNEG , /* nonnegative integer */
/* for assigment to "lastst" only (see SC1.C) */
tEXPR,
tENDLESS, /* endless loop */
};
/* (reversed) evaluation of staging buffer */ /* (reversed) evaluation of staging buffer */
#define sSTARTREORDER 0x01 #define sSTARTREORDER 0x01

View File

@ -3171,7 +3171,7 @@ SC_FUNC symbol *fetchfunc(char *name,int tag)
} /* if */ } /* if */
if (pc_deprecate!=NULL) { if (pc_deprecate!=NULL) {
assert(sym!=NULL); assert(sym!=NULL);
sym->flags|=flgDEPRECATED; sym->flags|=flagDEPRECATED;
if (sc_status==statWRITE) { if (sc_status==statWRITE) {
if (sym->documentation!=NULL) { if (sym->documentation!=NULL) {
free(sym->documentation); free(sym->documentation);
@ -3785,7 +3785,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc
cidx=code_idx; cidx=code_idx;
glbdecl=glb_declared; glbdecl=glb_declared;
} /* if */ } /* if */
if ((sym->flags & flgDEPRECATED)!=0) { if ((sym->flags & flagDEPRECATED)!=0) {
char *ptr= (sym->documentation!=NULL) ? sym->documentation : ""; char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
error(234,symbolname,ptr); /* deprecated (probably a public function) */ error(234,symbolname,ptr); /* deprecated (probably a public function) */
} /* if */ } /* if */

View File

@ -1082,7 +1082,7 @@ static int command(void)
} /* if */ } /* if */
check_empty(lptr); check_empty(lptr);
break; break;
case tINCLUDE: /* #include directive */ case tpINCLUDE: /* #include directive */
case tpTRYINCLUDE: case tpTRYINCLUDE:
ret=CMD_INCLUDE; ret=CMD_INCLUDE;
if (!SKIPPING) if (!SKIPPING)
@ -2136,7 +2136,7 @@ SC_FUNC void lexinit(void)
char *sc_tokens[] = { char *sc_tokens[] = {
"*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=",
"||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--", "||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--",
"...", "..", "::", "...", "..",
"assert", "*begin", "break", "case", "char", "const", "continue", "default", "assert", "*begin", "break", "case", "char", "const", "continue", "default",
"defined", "do", "else", "emit", "__emit", "*end", "enum", "exit", "for", "defined", "do", "else", "emit", "__emit", "*end", "enum", "exit", "for",
"forward", "goto", "if", "native", "new", "operator", "public", "return", "forward", "goto", "if", "native", "new", "operator", "public", "return",

View File

@ -2031,7 +2031,7 @@ static int nesting=0;
#endif #endif
sc_allowproccall=FALSE; /* parameters may not use procedure call syntax */ sc_allowproccall=FALSE; /* parameters may not use procedure call syntax */
if ((sym->flags & flgDEPRECATED)!=0) { if ((sym->flags & flagDEPRECATED)!=0) {
char *ptr= (sym->documentation!=NULL) ? sym->documentation : ""; char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
error(234,sym->name,ptr); /* deprecated (probably a native function) */ error(234,sym->name,ptr); /* deprecated (probably a native function) */
} /* if */ } /* if */