Browse Source

Replace automatically generated code with a more friendly equivalent

pull/8/head
Rafal Kupiec 3 years ago
parent
commit
dff0a5c968
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
1 changed files with 91 additions and 198 deletions
  1. +91
    -198
      lex.c

+ 91
- 198
lex.c View File

@ -560,206 +560,99 @@ static sxi32 TokenizePHP(SyStream *pStream,SyToken *pToken,void *pUserData,void
/* Tell the upper-layer to save the extracted token for later processing */
return SXRET_OK;
}
/***** This file contains automatically generated code ******
**
** The code in this file has been automatically generated by
**
** $Header: /sqlite/sqlite/tool/mkkeywordhash.c
**
** Sligthly modified by Chems mrad <chm@symisc.net> for the PH7 engine.
**
** The code in this file implements a function that determines whether
** or not a given identifier is really a PHP keyword. The same thing
** might be implemented more directly using a hand-written hash table.
** But by using this automatically generated code, the size of the code
** is substantially reduced. This is important for embedded applications
** on platforms with limited memory.
*/
/* Hash score: 103 */
static sxu32 KeywordCode(const char *z, int n){
/* zText[] encodes 532 bytes of keywords in 333 bytes */
/* extendswitchprintegerequire_oncenddeclareturnamespacechobject */
/* hrowbooleandefaultrycaselfinalistaticlonewconstringlobaluse */
/* lseifloatvarrayANDIEchoUSECHOabstractclasscontinuendifunction */
/* diendwhilevaldoexitgotoimplementsinclude_oncemptyinstanceof */
/* interfacendforeachissetparentprivateprotectedpublicatchunset */
/* xorARRAYASArrayEXITUNSETXORbreak */
static const char zText[332] = {
'e','x','t','e','n','d','s','w','i','t','c','h','p','r','i','n','t','e',
'g','e','r','e','q','u','i','r','e','_','o','n','c','e','n','d','d','e',
'c','l','a','r','e','t','u','r','n','a','m','e','s','p','a','c','e','c',
'h','o','b','j','e','c','t','h','r','o','w','b','o','o','l','e','a','n',
'd','e','f','a','u','l','t','r','y','c','a','s','e','l','f','i','n','a',
'l','i','s','t','a','t','i','c','l','o','n','e','w','c','o','n','s','t',
'r','i','n','g','l','o','b','a','l','u','s','e','l','s','e','i','f','l',
'o','a','t','v','a','r','r','a','y','A','N','D','I','E','c','h','o','U',
'S','E','C','H','O','a','b','s','t','r','a','c','t','c','l','a','s','s',
'c','o','n','t','i','n','u','e','n','d','i','f','u','n','c','t','i','o',
'n','d','i','e','n','d','w','h','i','l','e','v','a','l','d','o','e','x',
'i','t','g','o','t','o','i','m','p','l','e','m','e','n','t','s','i','n',
'c','l','u','d','e','_','o','n','c','e','m','p','t','y','i','n','s','t',
'a','n','c','e','o','f','i','n','t','e','r','f','a','c','e','n','d','f',
'o','r','e','a','c','h','i','s','s','e','t','p','a','r','e','n','t','p',
'r','i','v','a','t','e','p','r','o','t','e','c','t','e','d','p','u','b',
'l','i','c','a','t','c','h','u','n','s','e','t','x','o','r','A','R','R',
'A','Y','A','S','A','r','r','a','y','E','X','I','T','U','N','S','E','T',
'X','O','R','b','r','e','a','k'
};
static const unsigned char aHash[151] = {
0, 0, 4, 83, 0, 61, 39, 12, 0, 33, 77, 0, 48,
0, 2, 65, 67, 0, 0, 0, 47, 0, 0, 40, 0, 15,
74, 0, 51, 0, 76, 0, 0, 20, 0, 0, 0, 50, 0,
80, 34, 0, 36, 0, 0, 64, 16, 0, 0, 17, 0, 1,
19, 84, 66, 0, 43, 45, 78, 0, 0, 53, 56, 0, 0,
0, 23, 49, 0, 0, 13, 31, 54, 7, 0, 0, 25, 0,
72, 14, 0, 71, 0, 38, 6, 0, 0, 0, 73, 0, 0,
3, 0, 41, 5, 52, 57, 32, 0, 60, 63, 0, 69, 82,
30, 0, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 81, 0, 0,
62, 0, 11, 0, 0, 58, 0, 0, 0, 0, 59, 75, 0,
0, 0, 0, 0, 0, 35, 27, 0
};
static const unsigned char aNext[84] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 8, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 44, 0, 18, 0, 0, 0, 0, 0,
0, 46, 0, 29, 0, 0, 0, 22, 0, 0, 0, 0, 26,
0, 21, 24, 0, 0, 68, 0, 0, 9, 37, 0, 0, 0,
42, 0, 0, 0, 70, 55
};
static const unsigned char aLen[84] = {
7, 9, 6, 5, 7, 12, 7, 2, 10, 7, 6, 9, 4,
6, 5, 7, 4, 3, 7, 3, 4, 4, 5, 4, 6, 5,
2, 3, 5, 6, 6, 3, 6, 4, 2, 5, 3, 5, 3,
3, 4, 3, 4, 8, 5, 2, 8, 5, 8, 3, 8, 5,
4, 2, 4, 4, 10, 12, 7, 5, 10, 9, 3, 6, 10,
3, 7, 2, 5, 6, 7, 9, 6, 5, 5, 3, 5, 2,
5, 4, 5, 3, 2, 5
};
static const sxu16 aOffset[84] = {
0, 3, 6, 12, 14, 20, 20, 21, 31, 34, 39, 44, 52,
55, 60, 65, 65, 70, 72, 78, 81, 83, 86, 90, 92, 97,
100, 100, 103, 106, 111, 117, 119, 119, 123, 124, 129, 130, 135,
137, 139, 143, 145, 149, 157, 159, 162, 169, 173, 181, 183, 186,
190, 194, 196, 200, 204, 214, 214, 225, 230, 240, 240, 248, 248,
251, 251, 252, 258, 263, 269, 276, 285, 290, 295, 300, 303, 308,
310, 315, 319, 324, 325, 327
};
static const sxu32 aCode[84] = {
PH7_TKWRD_EXTENDS, PH7_TKWRD_ENDSWITCH, PH7_TKWRD_SWITCH, PH7_TKWRD_PRINT, PH7_TKWRD_INT,
PH7_TKWRD_REQONCE, PH7_TKWRD_REQUIRE, PH7_TKWRD_SEQ, PH7_TKWRD_ENDDEC, PH7_TKWRD_DECLARE,
PH7_TKWRD_RETURN, PH7_TKWRD_NAMESPACE, PH7_TKWRD_ECHO, PH7_TKWRD_OBJECT, PH7_TKWRD_THROW,
PH7_TKWRD_BOOL, PH7_TKWRD_BOOL, PH7_TKWRD_AND, PH7_TKWRD_DEFAULT, PH7_TKWRD_TRY,
PH7_TKWRD_CASE, PH7_TKWRD_SELF, PH7_TKWRD_FINAL, PH7_TKWRD_LIST, PH7_TKWRD_STATIC,
PH7_TKWRD_CLONE, PH7_TKWRD_SNE, PH7_TKWRD_NEW, PH7_TKWRD_CONST, PH7_TKWRD_STRING,
PH7_TKWRD_GLOBAL, PH7_TKWRD_USE, PH7_TKWRD_ELIF, PH7_TKWRD_ELSE, PH7_TKWRD_IF,
PH7_TKWRD_FLOAT, PH7_TKWRD_VAR, PH7_TKWRD_ARRAY, PH7_TKWRD_AND, PH7_TKWRD_DIE,
PH7_TKWRD_ECHO, PH7_TKWRD_USE, PH7_TKWRD_ECHO, PH7_TKWRD_ABSTRACT, PH7_TKWRD_CLASS,
PH7_TKWRD_AS, PH7_TKWRD_CONTINUE, PH7_TKWRD_ENDIF, PH7_TKWRD_FUNCTION, PH7_TKWRD_DIE,
PH7_TKWRD_ENDWHILE, PH7_TKWRD_WHILE, PH7_TKWRD_EVAL, PH7_TKWRD_DO, PH7_TKWRD_EXIT,
PH7_TKWRD_GOTO, PH7_TKWRD_IMPLEMENTS, PH7_TKWRD_INCONCE, PH7_TKWRD_INCLUDE, PH7_TKWRD_EMPTY,
PH7_TKWRD_INSTANCEOF,PH7_TKWRD_INTERFACE, PH7_TKWRD_INT, PH7_TKWRD_ENDFOR, PH7_TKWRD_END4EACH,
PH7_TKWRD_FOR, PH7_TKWRD_FOREACH, PH7_TKWRD_OR, PH7_TKWRD_ISSET, PH7_TKWRD_PARENT,
PH7_TKWRD_PRIVATE, PH7_TKWRD_PROTECTED, PH7_TKWRD_PUBLIC, PH7_TKWRD_CATCH, PH7_TKWRD_UNSET,
PH7_TKWRD_XOR, PH7_TKWRD_ARRAY, PH7_TKWRD_AS, PH7_TKWRD_ARRAY, PH7_TKWRD_EXIT,
PH7_TKWRD_UNSET, PH7_TKWRD_XOR, PH7_TKWRD_OR, PH7_TKWRD_BREAK
};
int h, i;
if( n<2 ) return PH7_TK_ID;
h = (((int)z[0]*4) ^ ((int)z[n-1]*3) ^ n) % 151;
for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){
if( (int)aLen[i]==n && SyMemcmp(&zText[aOffset[i]],z,n)==0 ){
/* PH7_TKWRD_EXTENDS */
/* PH7_TKWRD_ENDSWITCH */
/* PH7_TKWRD_SWITCH */
/* PH7_TKWRD_PRINT */
/* PH7_TKWRD_INT */
/* PH7_TKWRD_REQONCE */
/* PH7_TKWRD_REQUIRE */
/* PH7_TKWRD_SEQ */
/* PH7_TKWRD_ENDDEC */
/* PH7_TKWRD_DECLARE */
/* PH7_TKWRD_RETURN */
/* PH7_TKWRD_NAMESPACE */
/* PH7_TKWRD_ECHO */
/* PH7_TKWRD_OBJECT */
/* PH7_TKWRD_THROW */
/* PH7_TKWRD_BOOL */
/* PH7_TKWRD_BOOL */
/* PH7_TKWRD_AND */
/* PH7_TKWRD_DEFAULT */
/* PH7_TKWRD_TRY */
/* PH7_TKWRD_CASE */
/* PH7_TKWRD_SELF */
/* PH7_TKWRD_FINAL */
/* PH7_TKWRD_LIST */
/* PH7_TKWRD_STATIC */
/* PH7_TKWRD_CLONE */
/* PH7_TKWRD_SNE */
/* PH7_TKWRD_NEW */
/* PH7_TKWRD_CONST */
/* PH7_TKWRD_STRING */
/* PH7_TKWRD_GLOBAL */
/* PH7_TKWRD_USE */
/* PH7_TKWRD_ELIF */
/* PH7_TKWRD_ELSE */
/* PH7_TKWRD_IF */
/* PH7_TKWRD_FLOAT */
/* PH7_TKWRD_VAR */
/* PH7_TKWRD_ARRAY */
/* PH7_TKWRD_AND */
/* PH7_TKWRD_DIE */
/* PH7_TKWRD_ECHO */
/* PH7_TKWRD_USE */
/* PH7_TKWRD_ECHO */
/* PH7_TKWRD_ABSTRACT */
/* PH7_TKWRD_CLASS */
/* PH7_TKWRD_AS */
/* PH7_TKWRD_CONTINUE */
/* PH7_TKWRD_ENDIF */
/* PH7_TKWRD_FUNCTION */
/* PH7_TKWRD_DIE */
/* PH7_TKWRD_ENDWHILE */
/* PH7_TKWRD_WHILE */
/* PH7_TKWRD_EVAL */
/* PH7_TKWRD_DO */
/* PH7_TKWRD_EXIT */
/* PH7_TKWRD_GOTO */
/* PH7_TKWRD_IMPLEMENTS */
/* PH7_TKWRD_INCONCE */
/* PH7_TKWRD_INCLUDE */
/* PH7_TKWRD_EMPTY */
/* PH7_TKWRD_INSTANCEOF */
/* PH7_TKWRD_INTERFACE */
/* PH7_TKWRD_INT */
/* PH7_TKWRD_ENDFOR */
/* PH7_TKWRD_END4EACH */
/* PH7_TKWRD_FOR */
/* PH7_TKWRD_FOREACH */
/* PH7_TKWRD_OR */
/* PH7_TKWRD_ISSET */
/* PH7_TKWRD_PARENT */
/* PH7_TKWRD_PRIVATE */
/* PH7_TKWRD_PROTECTED */
/* PH7_TKWRD_PUBLIC */
/* PH7_TKWRD_CATCH */
/* PH7_TKWRD_UNSET */
/* PH7_TKWRD_XOR */
/* PH7_TKWRD_ARRAY */
/* PH7_TKWRD_AS */
/* PH7_TKWRD_ARRAY */
/* PH7_TKWRD_EXIT */
/* PH7_TKWRD_UNSET */
/* PH7_TKWRD_XOR */
/* PH7_TKWRD_OR */
/* PH7_TKWRD_BREAK */
return aCode[i];
}
}
return PH7_TK_ID;
typedef struct {
char *token;
int value;
} ph7_token;
static ph7_token pTokenLookup[] = {
{"extends", PH7_TKWRD_EXTENDS},
{"endswitch", PH7_TKWRD_ENDSWITCH},
{"switch", PH7_TKWRD_SWITCH},
{"print", PH7_TKWRD_PRINT},
{"int", PH7_TKWRD_INT},
{"require_once", PH7_TKWRD_REQONCE},
{"require", PH7_TKWRD_REQUIRE},
{"eq", PH7_TKWRD_SEQ},
{"ne", PH7_TKWRD_SNE},
{"enddeclare", PH7_TKWRD_ENDDEC},
{"declare", PH7_TKWRD_DECLARE},
{"return", PH7_TKWRD_RETURN},
{"namespace", PH7_TKWRD_NAMESPACE},
{"echo", PH7_TKWRD_ECHO},
{"object", PH7_TKWRD_OBJECT},
{"throw", PH7_TKWRD_THROW},
{"bool", PH7_TKWRD_BOOL},
{"boolean", PH7_TKWRD_BOOL},
{"and", PH7_TKWRD_AND},
{"default", PH7_TKWRD_DEFAULT},
{"try", PH7_TKWRD_TRY},
{"case", PH7_TKWRD_CASE},
{"self", PH7_TKWRD_SELF},
{"final", PH7_TKWRD_FINAL},
{"list", PH7_TKWRD_LIST},
{"static", PH7_TKWRD_STATIC},
{"clone", PH7_TKWRD_CLONE},
{"new", PH7_TKWRD_NEW},
{"const", PH7_TKWRD_CONST},
{"string", PH7_TKWRD_STRING},
{"global", PH7_TKWRD_GLOBAL},
{"use", PH7_TKWRD_USE},
{"elseif", PH7_TKWRD_ELIF},
{"elif", PH7_TKWRD_ELIF},
{"else", PH7_TKWRD_ELSE},
{"if", PH7_TKWRD_IF},
{"double", PH7_TKWRD_FLOAT},
{"float", PH7_TKWRD_FLOAT},
{"var", PH7_TKWRD_VAR},
{"array", PH7_TKWRD_ARRAY},
{"die", PH7_TKWRD_DIE},
{"abstract", PH7_TKWRD_ABSTRACT},
{"class", PH7_TKWRD_CLASS},
{"as", PH7_TKWRD_AS},
{"continue", PH7_TKWRD_CONTINUE},
{"endif", PH7_TKWRD_ENDIF},
{"function", PH7_TKWRD_FUNCTION},
{"endwhile", PH7_TKWRD_ENDWHILE},
{"while", PH7_TKWRD_WHILE},
{"eval", PH7_TKWRD_EVAL},
{"do", PH7_TKWRD_DO},
{"exit", PH7_TKWRD_EXIT},
{"goto", PH7_TKWRD_GOTO},
{"implements", PH7_TKWRD_IMPLEMENTS},
{"include_once", PH7_TKWRD_INCONCE},
{"include", PH7_TKWRD_INCLUDE},
{"empty", PH7_TKWRD_EMPTY},
{"instanceof", PH7_TKWRD_INSTANCEOF},
{"interface", PH7_TKWRD_INTERFACE},
{"integer", PH7_TKWRD_INT},
{"endfor", PH7_TKWRD_ENDFOR},
{"endforeach", PH7_TKWRD_END4EACH},
{"for", PH7_TKWRD_FOR},
{"foreach", PH7_TKWRD_FOREACH},
{"or", PH7_TKWRD_OR},
{"isset", PH7_TKWRD_ISSET},
{"parent", PH7_TKWRD_PARENT},
{"private", PH7_TKWRD_PRIVATE},
{"protected", PH7_TKWRD_PROTECTED},
{"public", PH7_TKWRD_PUBLIC},
{"catch", PH7_TKWRD_CATCH},
{"unset", PH7_TKWRD_UNSET},
{"xor", PH7_TKWRD_XOR},
{"break", PH7_TKWRD_BREAK}
};
if(n < 2) {
return PH7_TK_ID;
} else {
for(ph7_token *pToken = pTokenLookup; pToken != pTokenLookup + sizeof(pTokenLookup) / sizeof(pTokenLookup[0]); pToken++) {
if(SyMemcmp(pToken->token, z, n) == 0) {
return pToken->value;
}
}
return PH7_TK_ID;
}
}
/* --- End of Automatically generated code --- */
/*
* Extract a heredoc/nowdoc text from a raw PHP input.
* According to the PHP language reference manual:


Loading…
Cancel
Save