HyperDbg Debugger
Loading...
Searching...
No Matches
common.h File Reference

Go to the source code of this file.

Classes

struct  _SCRIPT_ENGINE_TOKEN
 read tokens from input stored in this structure More...
struct  _SCRIPT_ENGINE_TOKEN_LIST
 this structure is a dynamic container of TOKENS More...
struct  _USER_DEFINED_FUNCTION_NODE
 User-defined function linked list node. More...
struct  _INCLUDE_NODE
 Include file linked list node. More...

Macros

#define COMMON_H
#define SYMBOL_BUFFER_INIT_SIZE   64
#define TOKEN_VALUE_MAX_LEN   8
 maximum length of string in the token
#define TOKEN_LIST_INIT_SIZE   256
 init size of token list

Typedefs

typedef enum _SCRIPT_ENGINE_TOKEN_TYPE SCRIPT_ENGINE_TOKEN_TYPE
 enumerates possible types for token
typedef struct _SCRIPT_ENGINE_TOKEN SCRIPT_ENGINE_TOKEN
 read tokens from input stored in this structure
typedef struct _SCRIPT_ENGINE_TOKENPSCRIPT_ENGINE_TOKEN
typedef struct _SCRIPT_ENGINE_TOKEN_LIST SCRIPT_ENGINE_TOKEN_LIST
 this structure is a dynamic container of TOKENS
typedef struct _SCRIPT_ENGINE_TOKEN_LISTPSCRIPT_ENGINE_TOKEN_LIST
typedef struct _USER_DEFINED_FUNCTION_NODE USER_DEFINED_FUNCTION_NODE
 User-defined function linked list node.
typedef struct _USER_DEFINED_FUNCTION_NODEPUSER_DEFINED_FUNCTION_NODE
typedef struct _INCLUDE_NODE INCLUDE_NODE
 Include file linked list node.
typedef struct _INCLUDE_NODEPINCLUDE_NODE

Enumerations

enum  _SCRIPT_ENGINE_TOKEN_TYPE {
  LOCAL_ID , LOCAL_UNRESOLVED_ID , GLOBAL_ID , GLOBAL_UNRESOLVED_ID ,
  DECIMAL , STATE_ID , HEX , OCTAL ,
  BINARY , SPECIAL_TOKEN , KEYWORD , WHITE_SPACE ,
  COMMENT , REGISTER , PSEUDO_REGISTER , NON_TERMINAL ,
  SEMANTIC_RULE , END_OF_STACK , EPSILON , TEMP ,
  STRING , WSTRING , FUNCTION_ID , FUNCTION_PARAMETER_ID ,
  SCRIPT_VARIABLE_TYPE , DEFERENCE_TEMP , UNKNOWN
}
 enumerates possible types for token More...

Functions

PSCRIPT_ENGINE_TOKEN NewUnknownToken (void)
 Allocates a new token.
PSCRIPT_ENGINE_TOKEN NewToken (SCRIPT_ENGINE_TOKEN_TYPE Type, char *Value)
 Allocates a new token with given type and value.
VOID RemoveToken (PSCRIPT_ENGINE_TOKEN *Token)
 Removes allocated memory of a token.
VOID PrintToken (PSCRIPT_ENGINE_TOKEN Token)
 Prints token.
VOID AppendByte (PSCRIPT_ENGINE_TOKEN Token, CHAR c)
 Appends char to the token value.
VOID AppendWchar (PSCRIPT_ENGINE_TOKEN Token, wchar_t c)
 Appends wchar_t to the token value.
PSCRIPT_ENGINE_TOKEN CopyToken (PSCRIPT_ENGINE_TOKEN Token)
 Copies a PTOKEN.
PSCRIPT_ENGINE_TOKEN NewTemp (PSCRIPT_ENGINE_ERROR_TYPE)
 Allocates a new temporary variable and returns it.
VOID FreeTemp (PSCRIPT_ENGINE_TOKEN Temp)
 Frees the memory allocated by Temp.
VARIABLE_TYPEHandleType (PSCRIPT_ENGINE_TOKEN_LIST PtokenStack)
 Return a variable type based on the token stack.
VARIABLE_TYPEGetCommonVariableType (VARIABLE_TYPE *Ty1, VARIABLE_TYPE *Ty2)
 Returns the common variable type between two types.
PSCRIPT_ENGINE_TOKEN_LIST NewTokenList (void)
 Allocates a new SCRIPT_ENGINE_TOKEN_LIST.
VOID RemoveTokenList (PSCRIPT_ENGINE_TOKEN_LIST TokenList)
 Removes allocated memory of a SCRIPT_ENGINE_TOKEN_LIST.
VOID PrintTokenList (PSCRIPT_ENGINE_TOKEN_LIST TokenList)
 Prints each Token inside a TokenList.
PSCRIPT_ENGINE_TOKEN_LIST Push (PSCRIPT_ENGINE_TOKEN_LIST TokenList, PSCRIPT_ENGINE_TOKEN Token)
 Adds Token to the last empty position of TokenList.
PSCRIPT_ENGINE_TOKEN Pop (PSCRIPT_ENGINE_TOKEN_LIST TokenList)
 Removes last Token of a TokenList and returns it.
PSCRIPT_ENGINE_TOKEN Top (PSCRIPT_ENGINE_TOKEN_LIST TokenList)
 Returns last Token of a TokenList.
PSCRIPT_ENGINE_TOKEN TopIndexed (PSCRIPT_ENGINE_TOKEN_LIST TokenList, int Index)
 Returns the token at a specific index from the top of the token list.
char IsNoneTerminal (PSCRIPT_ENGINE_TOKEN Token)
 Checks whether this Token is noneterminal NoneTerminal token starts with capital letter.
char IsSemanticRule (PSCRIPT_ENGINE_TOKEN Token)
 Checks whether this Token is semantic rule SemanticRule token starts with '@'.
char IsEqual (const PSCRIPT_ENGINE_TOKEN Token1, const PSCRIPT_ENGINE_TOKEN Token2)
 Checks whether the value and type of Token1 and Token2 are the same.
int GetNonTerminalId (PSCRIPT_ENGINE_TOKEN Token)
 Gets the Non Terminal Id object.
int GetTerminalId (PSCRIPT_ENGINE_TOKEN Token)
 Gets the Terminal Id object.
int LalrGetNonTerminalId (PSCRIPT_ENGINE_TOKEN Token)
 Gets the Non Terminal Id object.
int LalrGetTerminalId (PSCRIPT_ENGINE_TOKEN Token)
 Gets the Terminal Id object.
char IsHex (char c)
 Checks whether input char belongs to hexadecimal digit-set or not.
char IsDecimal (char c)
 Checks whether input char belongs to decimal digit-set or not.
char IsLetter (char c)
 Checks whether input char belongs to alphabet set or not.
char IsUnderscore (char c)
 Checks whether input char is underscore (_) or not.
char IsBinary (char c)
 Checks whether input char belongs to binary digit-set or not.
char IsOctal (char c)
 Checks whether input char belongs to octal digit-set or not.
VOID SetType (unsigned long long *Val, unsigned char Type)
 Set the Type object.
unsigned long long DecimalToInt (char *str)
 Converts an decimal string to a integer.
unsigned long long DecimalToSignedInt (char *str)
 Converts an decimal string to a signed integer.
unsigned long long HexToInt (char *str)
 Converts an hexadecimal string to integer.
unsigned long long OctalToInt (char *str)
 Converts an octal string to integer.
unsigned long long BinaryToInt (char *str)
 Converts a binary string to integer.
VOID RotateLeftStringOnce (char *str)
 Rotate a character array to the left by one time.
char IsType1Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is OneOpFunc1.
char IsType2Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is OneOpFunc2.
char IsType4Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is VarArgFunc1.
char IsType5Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is ZeroOpFunc1.
char IsType6Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is TwoOpFunc1.
char IsType7Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is TwoOpFunc2.
char IsType8Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is ThreeOpFunc1.
char IsType9Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is OneOpFunc3.
char IsType10Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is TwoOpFunc3.
char IsType11Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is ThreeOpFunc3.
char IsType12Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is OneOpFunc4.
char IsType13Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is TwoOpFunc4.
char IsType14Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is ThreeOpFunc2.
char IsType15Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is ThreeOpFunc4.
char IsType16Func (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is ZeroOpFunc2.
char IsAssignmentOperator (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is assignment operator.
char IsTwoOperandOperator (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is OperatorsTwoOperandList.
char IsOneOperandOperator (PSCRIPT_ENGINE_TOKEN Operator)
 Checks whether this Token type is OperatorsOneOperandList.

Detailed Description

Author
M.H. Gholamrezaei (mh@hy.nosp@m.perd.nosp@m.bg.or.nosp@m.g)

Common routines header

Version
0.1
Date
2020-10-22

Macro Definition Documentation

◆ COMMON_H

#define COMMON_H

◆ SYMBOL_BUFFER_INIT_SIZE

#define SYMBOL_BUFFER_INIT_SIZE   64

initial size of symbol buffer

◆ TOKEN_LIST_INIT_SIZE

#define TOKEN_LIST_INIT_SIZE   256

init size of token list

◆ TOKEN_VALUE_MAX_LEN

#define TOKEN_VALUE_MAX_LEN   8

maximum length of string in the token

Typedef Documentation

◆ INCLUDE_NODE

typedef struct _INCLUDE_NODE INCLUDE_NODE

Include file linked list node.

◆ PINCLUDE_NODE

typedef struct _INCLUDE_NODE * PINCLUDE_NODE

◆ PSCRIPT_ENGINE_TOKEN

◆ PSCRIPT_ENGINE_TOKEN_LIST

◆ PUSER_DEFINED_FUNCTION_NODE

◆ SCRIPT_ENGINE_TOKEN

read tokens from input stored in this structure

◆ SCRIPT_ENGINE_TOKEN_LIST

this structure is a dynamic container of TOKENS

◆ SCRIPT_ENGINE_TOKEN_TYPE

enumerates possible types for token

◆ USER_DEFINED_FUNCTION_NODE

User-defined function linked list node.

Enumeration Type Documentation

◆ _SCRIPT_ENGINE_TOKEN_TYPE

enumerates possible types for token

Enumerator
LOCAL_ID 
LOCAL_UNRESOLVED_ID 
GLOBAL_ID 
GLOBAL_UNRESOLVED_ID 
DECIMAL 
STATE_ID 
HEX 
OCTAL 
BINARY 
SPECIAL_TOKEN 
KEYWORD 
WHITE_SPACE 
COMMENT 
REGISTER 
PSEUDO_REGISTER 
NON_TERMINAL 
SEMANTIC_RULE 
END_OF_STACK 
EPSILON 
TEMP 
STRING 
WSTRING 
FUNCTION_ID 
FUNCTION_PARAMETER_ID 
SCRIPT_VARIABLE_TYPE 
DEFERENCE_TEMP 
UNKNOWN 
37{
42 DECIMAL,
44 HEX,
45 OCTAL,
46 BINARY,
48 KEYWORD,
50 COMMENT,
56 EPSILON,
57 TEMP,
58 STRING,
59 WSTRING,
enum _SCRIPT_ENGINE_TOKEN_TYPE SCRIPT_ENGINE_TOKEN_TYPE
enumerates possible types for token
@ END_OF_STACK
Definition common.h:55
@ KEYWORD
Definition common.h:48
@ DEFERENCE_TEMP
Definition common.h:63
@ EPSILON
Definition common.h:56
@ TEMP
Definition common.h:57
@ LOCAL_UNRESOLVED_ID
Definition common.h:39
@ SCRIPT_VARIABLE_TYPE
Definition common.h:62
@ UNKNOWN
Definition common.h:64
@ SEMANTIC_RULE
Definition common.h:54
@ WHITE_SPACE
Definition common.h:49
@ LOCAL_ID
Definition common.h:38
@ PSEUDO_REGISTER
Definition common.h:52
@ WSTRING
Definition common.h:59
@ COMMENT
Definition common.h:50
@ GLOBAL_UNRESOLVED_ID
Definition common.h:41
@ SPECIAL_TOKEN
Definition common.h:47
@ REGISTER
Definition common.h:51
@ FUNCTION_ID
Definition common.h:60
@ OCTAL
Definition common.h:45
@ HEX
Definition common.h:44
@ GLOBAL_ID
Definition common.h:40
@ FUNCTION_PARAMETER_ID
Definition common.h:61
@ BINARY
Definition common.h:46
@ STRING
Definition common.h:58
@ DECIMAL
Definition common.h:42
@ NON_TERMINAL
Definition common.h:53
@ STATE_ID
Definition common.h:43

Function Documentation

◆ AppendByte()

VOID AppendByte ( PSCRIPT_ENGINE_TOKEN Token,
char c )

Appends char to the token value.

Parameters
Token
cthe character to append
Returns
void
244{
245 //
246 // Check overflow of the string
247 //
248 if (Token->Len >= Token->MaxLen - 1)
249 {
250 //
251 // Double the length of the allocated space for the string
252 //
253 Token->MaxLen *= 2;
254 char * NewValue = (char *)calloc(Token->MaxLen + 1, sizeof(char));
255
256 if (NewValue == NULL)
257 {
258 printf("err, could not allocate buffer");
259 return;
260 }
261
262 //
263 // Free Old buffer and update the pointer
264 //
265 memcpy(NewValue, Token->Value, Token->Len);
266 free(Token->Value);
267 Token->Value = NewValue;
268 }
269
270 //
271 // Append the new character to the string
272 //
273 Token->Value[Token->Len] = c;
274 Token->Len++;
275}
printf("ho")
unsigned int MaxLen
Definition common.h:75
unsigned int Len
Definition common.h:74
char * Value
Definition common.h:73

◆ AppendWchar()

VOID AppendWchar ( PSCRIPT_ENGINE_TOKEN Token,
wchar_t c )

Appends wchar_t to the token value.

Parameters
Token
cthe wide character to append
Returns
void
286{
287 //
288 // Check overflow of the string
289 //
290 if (Token->Len >= Token->MaxLen - 2)
291 {
292 //
293 // Double the length of the allocated space for the wstring
294 //
295 Token->MaxLen *= 2;
296 char * NewValue = (char *)calloc(Token->MaxLen + 2, sizeof(char));
297
298 if (NewValue == NULL)
299 {
300 printf("err, could not allocate buffer");
301 return;
302 }
303
304 //
305 // Free Old buffer and update the pointer
306 //
307 memcpy(NewValue, Token->Value, Token->Len);
308 free(Token->Value);
309 Token->Value = NewValue;
310 }
311
312 //
313 // Append the new character to the wstring
314 //
315 *((wchar_t *)(Token->Value) + Token->Len / 2) = c;
316 Token->Len += 2;
317}

◆ BinaryToInt()

unsigned long long BinaryToInt ( char * str)

Converts a binary string to integer.

Parameters
strthe binary string to convert
Returns
unsigned long long
1515{
1516 SIZE_T Len;
1517 unsigned long long Acc = 0;
1518
1519 Len = strlen(str);
1520
1521 for (int i = 0; i < Len; i++)
1522 {
1523 Acc <<= 1;
1524 Acc += (str[i] - '0');
1525 }
1526 return Acc;
1527}

◆ CopyToken()

Copies a PTOKEN.

Parameters
Tokenthe token to copy
Returns
PSCRIPT_ENGINE_TOKEN the copied token
327{
329
330 if (TokenCopy == NULL)
331 {
332 //
333 // There was an error allocating buffer
334 //
335 return NULL;
336 }
337
338 TokenCopy->Type = Token->Type;
339 TokenCopy->MaxLen = Token->MaxLen;
340 TokenCopy->Len = Token->Len;
341 TokenCopy->Value = (char *)calloc(strlen(Token->Value) + 1, sizeof(char));
342 TokenCopy->VariableType = Token->VariableType;
343
344 if (TokenCopy->Value == NULL)
345 {
346 //
347 // There was an error allocating buffer
348 //
349 free(TokenCopy);
350 return NULL;
351 }
352
353 strcpy(TokenCopy->Value, Token->Value);
354
355 return TokenCopy;
356}
NULL()
Definition test-case-generator.py:530
struct _SCRIPT_ENGINE_TOKEN * PSCRIPT_ENGINE_TOKEN
struct _SCRIPT_ENGINE_TOKEN SCRIPT_ENGINE_TOKEN
read tokens from input stored in this structure
SCRIPT_ENGINE_TOKEN_TYPE Type
Definition common.h:72
VARIABLE_TYPE * VariableType
Definition common.h:76

◆ DecimalToInt()

unsigned long long DecimalToInt ( char * str)

Converts an decimal string to a integer.

Parameters
strthe decimal string to convert
Returns
unsigned long long int
1405{
1406 unsigned long long Acc = 0;
1407 SIZE_T Len;
1408
1409 Len = strlen(str);
1410 for (int i = 0; i < Len; i++)
1411 {
1412 Acc *= 10;
1413 Acc += (str[i] - '0');
1414 }
1415 return Acc;
1416}

◆ DecimalToSignedInt()

unsigned long long DecimalToSignedInt ( char * str)

Converts an decimal string to a signed integer.

Parameters
strthe decimal string to convert
Returns
unsigned long long
1426{
1427 long long Acc = 0;
1428 SIZE_T Len;
1429
1430 if (str[0] == '-')
1431 {
1432 Len = strlen(str);
1433 for (int i = 1; i < Len; i++)
1434 {
1435 Acc *= 10;
1436 Acc += (str[i] - '0');
1437 }
1438 return -Acc;
1439 }
1440 else
1441 {
1442 Len = strlen(str);
1443 for (int i = 0; i < Len; i++)
1444 {
1445 Acc *= 10;
1446 Acc += (str[i] - '0');
1447 }
1448 return Acc;
1449 }
1450}

◆ FreeTemp()

VOID FreeTemp ( PSCRIPT_ENGINE_TOKEN Temp)

Frees the memory allocated by Temp.

Parameters
Tempthe token representing the temporary variable
Returns
VOID
694{
695 INT Id = (INT)DecimalToInt(Temp->Value);
696 if (Temp->Type == TEMP || Temp->Type == DEFERENCE_TEMP)
697 {
698 CurrentUserDefinedFunction->TempMap[Id] = 0;
699 }
700}
int INT
Definition BasicTypes.h:43
PUSER_DEFINED_FUNCTION_NODE CurrentUserDefinedFunction
Definition globals.c:16
unsigned long long DecimalToInt(char *str)
Converts an decimal string to a integer.
Definition common.c:1404

◆ GetCommonVariableType()

VARIABLE_TYPE * GetCommonVariableType ( VARIABLE_TYPE * Ty1,
VARIABLE_TYPE * Ty2 )

Returns the common variable type between two types.

Parameters
Ty1the first variable type
Ty2the second variable type
Returns
VARIABLE_TYPE * pointer to the common variable type
189{
190 // if (Ty1->Kind == TY_ARRAY)
191 //{
192 // return Ty1;
193 // }
194
195 // if (Ty2->Kind == TY_ARRAY)
196 //{
197 // return Ty2;
198 // }
199
200 return VARIABLE_TYPE_LONG;
201}
VARIABLE_TYPE * VARIABLE_TYPE_LONG
Definition type.c:23

◆ GetNonTerminalId()

int GetNonTerminalId ( PSCRIPT_ENGINE_TOKEN Token)

Gets the Non Terminal Id object.

Parameters
Tokenthe token to get the non-terminal ID of
Returns
int the non-terminal ID or INVALID
1102{
1103 for (int i = 0; i < NONETERMINAL_COUNT; i++)
1104 {
1105 if (!strcmp(Token->Value, NoneTerminalMap[i]))
1106 return i;
1107 }
1108 return INVALID;
1109}
#define INVALID
Definition ScriptEngineCommonDefinitions.h:92
const char * NoneTerminalMap[NONETERMINAL_COUNT]
Definition parse-table.c:863
#define NONETERMINAL_COUNT
Definition parse-table.h:6

◆ GetTerminalId()

int GetTerminalId ( PSCRIPT_ENGINE_TOKEN Token)

Gets the Terminal Id object.

Parameters
Tokenthe token to get the terminal ID of
Returns
int the terminal ID or INVALID
1119{
1120 for (int i = 0; i < TERMINAL_COUNT; i++)
1121 {
1122 if (Token->Type == HEX)
1123 {
1124 if (!strcmp("_hex", TerminalMap[i]))
1125 return i;
1126 }
1127 else if (Token->Type == GLOBAL_ID || Token->Type == GLOBAL_UNRESOLVED_ID)
1128 {
1129 if (!strcmp("_global_id", TerminalMap[i]))
1130 {
1131 return i;
1132 }
1133 }
1134 else if (Token->Type == LOCAL_ID || Token->Type == LOCAL_UNRESOLVED_ID)
1135 {
1136 if (!strcmp("_local_id", TerminalMap[i]))
1137 {
1138 return i;
1139 }
1140 }
1141 else if (Token->Type == FUNCTION_ID)
1142 {
1143 if (!strcmp("_function_id", TerminalMap[i]))
1144 {
1145 return i;
1146 }
1147 }
1148 else if (Token->Type == FUNCTION_PARAMETER_ID)
1149 {
1150 if (!strcmp("_function_parameter_id", TerminalMap[i]))
1151 {
1152 return i;
1153 }
1154 }
1155 else if (Token->Type == REGISTER)
1156 {
1157 if (!strcmp("_register", TerminalMap[i]))
1158 {
1159 return i;
1160 }
1161 }
1162 else if (Token->Type == PSEUDO_REGISTER)
1163 {
1164 if (!strcmp("_pseudo_register", TerminalMap[i]))
1165 {
1166 return i;
1167 }
1168 }
1169 else if (Token->Type == SCRIPT_VARIABLE_TYPE)
1170 {
1171 if (!strcmp("_script_variable_type", TerminalMap[i]))
1172 {
1173 return i;
1174 }
1175 }
1176 else if (Token->Type == DECIMAL)
1177 {
1178 if (!strcmp("_decimal", TerminalMap[i]))
1179 {
1180 return i;
1181 }
1182 }
1183 else if (Token->Type == BINARY)
1184 {
1185 if (!strcmp("_binary", TerminalMap[i]))
1186 {
1187 return i;
1188 }
1189 }
1190 else if (Token->Type == OCTAL)
1191 {
1192 if (!strcmp("_octal", TerminalMap[i]))
1193 {
1194 return i;
1195 }
1196 }
1197 else if (Token->Type == STRING)
1198 {
1199 if (!strcmp("_string", TerminalMap[i]))
1200 {
1201 return i;
1202 }
1203 }
1204 else if (Token->Type == WSTRING)
1205 {
1206 if (!strcmp("_wstring", TerminalMap[i]))
1207 {
1208 return i;
1209 }
1210 }
1211 else // Keyword
1212 {
1213 if (!strcmp(Token->Value, TerminalMap[i]))
1214 return i;
1215 }
1216 }
1217 return INVALID;
1218}
const char * TerminalMap[TERMINAL_COUNT]
Definition parse-table.c:929
#define TERMINAL_COUNT
Definition parse-table.h:5

◆ HandleType()

VARIABLE_TYPE * HandleType ( PSCRIPT_ENGINE_TOKEN_LIST PtokenStack)

Return a variable type based on the token stack.

Parameters
PtokenStackthe token stack containing type tokens
Returns
VARIABLE_TYPE * pointer to the resolved variable type
42{
43 enum
44 {
45 ENUM_VOID = 1 << 0,
46 ENUM_BOOL = 1 << 2,
47 ENUM_CHAR = 1 << 4,
48 ENUM_SHORT = 1 << 6,
49 ENUM_INT = 1 << 8,
50 ENUM_LONG = 1 << 10,
51 ENUM_FLOAT = 1 << 12,
52 ENUM_DOUBLE = 1 << 14,
53 ENUM_OTHER = 1 << 16,
54 ENUM_SIGNED = 1 << 17,
55 ENUM_UNSIGNED = 1 << 18,
56 };
57
59 int Counter = 0;
60 PSCRIPT_ENGINE_TOKEN TopToken = NULL;
61
62 while (PtokenStack->Pointer > 0)
63 {
64 TopToken = Pop(PtokenStack);
65 if (TopToken->Type != SCRIPT_VARIABLE_TYPE)
66 {
67 Push(PtokenStack, TopToken);
68 break;
69 }
70 if (!strcmp(TopToken->Value, "void"))
71 {
72 Counter += ENUM_VOID;
73 }
74 else if (!strcmp(TopToken->Value, "bool"))
75 {
76 Counter += ENUM_BOOL;
77 }
78 else if (!strcmp(TopToken->Value, "char"))
79 {
80 Counter += ENUM_CHAR;
81 }
82 else if (!strcmp(TopToken->Value, "short"))
83 {
84 Counter += ENUM_SHORT;
85 }
86 else if (!strcmp(TopToken->Value, "int"))
87 {
88 Counter += ENUM_INT;
89 }
90 else if (!strcmp(TopToken->Value, "long"))
91 {
92 Counter += ENUM_LONG;
93 }
94 else if (!strcmp(TopToken->Value, "float"))
95 {
96 Counter += ENUM_FLOAT;
97 }
98 else if (!strcmp(TopToken->Value, "double"))
99 {
100 Counter += ENUM_DOUBLE;
101 }
102 else if (!strcmp(TopToken->Value, "signed"))
103 {
104 Counter |= ENUM_SIGNED;
105 }
106 else if (!strcmp(TopToken->Value, "unsigned"))
107 {
108 Counter |= ENUM_UNSIGNED;
109 }
110 else
111 {
113 }
114 RemoveToken(&TopToken);
115
116 switch (Counter)
117 {
118 case ENUM_VOID:
119 Result = VARIABLE_TYPE_VOID;
120 break;
121 case ENUM_BOOL:
122 Result = VARIABLE_TYPE_BOOL;
123 break;
124 case ENUM_CHAR:
125 case ENUM_SIGNED + ENUM_CHAR:
126 Result = VARIABLE_TYPE_CHAR;
127 break;
128 case ENUM_UNSIGNED + ENUM_CHAR:
129 Result = VARIABLE_TYPE_UCHAR;
130 break;
131 case ENUM_SHORT:
132 case ENUM_SHORT + ENUM_INT:
133 case ENUM_SIGNED + ENUM_SHORT:
134 case ENUM_SIGNED + ENUM_SHORT + ENUM_INT:
135 Result = VARIABLE_TYPE_INT;
136 break;
137 case ENUM_UNSIGNED + ENUM_SHORT:
138 case ENUM_UNSIGNED + ENUM_SHORT + ENUM_INT:
139 Result = VARIABLE_TYPE_USHORT;
140 break;
141 case ENUM_INT:
142 case ENUM_SIGNED:
143 case ENUM_SIGNED + ENUM_INT:
144 Result = VARIABLE_TYPE_INT;
145 break;
146 case ENUM_UNSIGNED:
147 case ENUM_UNSIGNED + ENUM_INT:
148 Result = VARIABLE_TYPE_UINT;
149 break;
150 case ENUM_LONG:
151 case ENUM_LONG + ENUM_INT:
152 case ENUM_LONG + ENUM_LONG:
153 case ENUM_LONG + ENUM_LONG + ENUM_INT:
154 case ENUM_SIGNED + ENUM_LONG:
155 case ENUM_SIGNED + ENUM_LONG + ENUM_INT:
156 case ENUM_SIGNED + ENUM_LONG + ENUM_LONG:
157 case ENUM_SIGNED + ENUM_LONG + ENUM_LONG + ENUM_INT:
158 Result = VARIABLE_TYPE_LONG;
159 break;
160 case ENUM_UNSIGNED + ENUM_LONG:
161 case ENUM_UNSIGNED + ENUM_LONG + ENUM_INT:
162 case ENUM_UNSIGNED + ENUM_LONG + ENUM_LONG:
163 case ENUM_UNSIGNED + ENUM_LONG + ENUM_LONG + ENUM_INT:
164 Result = VARIABLE_TYPE_ULONG;
165 break;
166 case ENUM_FLOAT:
167 Result = VARIABLE_TYPE_FLOAT;
168 break;
169 case ENUM_DOUBLE:
170 Result = VARIABLE_TYPE_DOUBLE;
171 break;
172 case ENUM_LONG + ENUM_DOUBLE:
173 Result = VARIABLE_TYPE_LDOUBLE;
174 break;
175 }
176 }
177 return Result;
178}
PSCRIPT_ENGINE_TOKEN_LIST Push(PSCRIPT_ENGINE_TOKEN_LIST TokenList, PSCRIPT_ENGINE_TOKEN Token)
Adds Token to the last empty position of TokenList.
Definition common.c:441
void RemoveToken(PSCRIPT_ENGINE_TOKEN *Token)
Removes allocated memory of a token.
Definition common.c:116
PSCRIPT_ENGINE_TOKEN Pop(PSCRIPT_ENGINE_TOKEN_LIST TokenList)
Removes last Token of a TokenList and returns it.
Definition common.c:502
unsigned int Pointer
Definition common.h:86
VARIABLE_TYPE * VARIABLE_TYPE_FLOAT
Definition type.c:30
VARIABLE_TYPE * VARIABLE_TYPE_UCHAR
Definition type.c:25
VARIABLE_TYPE * VARIABLE_TYPE_UNKNOWN
Definition type.c:15
VARIABLE_TYPE * VARIABLE_TYPE_DOUBLE
Definition type.c:31
VARIABLE_TYPE * VARIABLE_TYPE_ULONG
Definition type.c:28
VARIABLE_TYPE * VARIABLE_TYPE_VOID
Definition type.c:17
VARIABLE_TYPE * VARIABLE_TYPE_BOOL
Definition type.c:18
VARIABLE_TYPE * VARIABLE_TYPE_INT
Definition type.c:22
VARIABLE_TYPE * VARIABLE_TYPE_CHAR
Definition type.c:20
VARIABLE_TYPE * VARIABLE_TYPE_UINT
Definition type.c:27
VARIABLE_TYPE * VARIABLE_TYPE_USHORT
Definition type.c:26
VARIABLE_TYPE * VARIABLE_TYPE_LDOUBLE
Definition type.c:32
struct _VARIABLE_TYPE VARIABLE_TYPE

◆ HexToInt()

unsigned long long HexToInt ( char * str)

Converts an hexadecimal string to integer.

Parameters
strthe hexadecimal string to convert
Returns
unsigned long long
1460{
1461 CHAR Temp;
1462 SIZE_T Len = strlen(str);
1463 unsigned long long Acc = 0;
1464 for (int i = 0; i < Len; i++)
1465 {
1466 Acc <<= 4;
1467 if (str[i] >= '0' && str[i] <= '9')
1468 {
1469 Temp = str[i] - '0';
1470 }
1471 else if (str[i] >= 'a' && str[i] <= 'f')
1472 {
1473 Temp = str[i] - 'a' + 10;
1474 }
1475 else
1476 {
1477 Temp = str[i] - 'A' + 10;
1478 }
1479 Acc += Temp;
1480 }
1481
1482 return Acc;
1483}
char CHAR
Definition BasicTypes.h:33

◆ IsAssignmentOperator()

char IsAssignmentOperator ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is assignment operator.

Parameters
Operatorthe token to check
Returns
char
1050{
1051 unsigned int n = ASSIGNMENT_OPERATOR_LIST_LENGTH;
1052 for (unsigned int i = 0; i < n; i++)
1053 {
1054 if (!strcmp(Operator->Value, AssignmentOperatorList[i]))
1055 {
1056 return 1;
1057 }
1058 }
1059 return 0;
1060}
const char * AssignmentOperatorList[]
Definition parse-table.c:1272
#define ASSIGNMENT_OPERATOR_LIST_LENGTH
Definition parse-table.h:15

◆ IsBinary()

char IsBinary ( char c)

Checks whether input char belongs to binary digit-set or not.

Parameters
cthe character to check
Returns
char
624{
625 if (c == '0' || c == '1')
626 return 1;
627 else
628 {
629 return 0;
630 }
631}

◆ IsDecimal()

char IsDecimal ( char c)

Checks whether input char belongs to decimal digit-set or not.

Parameters
cthe character to check
Returns
char
575{
576 if (c >= '0' && c <= '9')
577 return 1;
578 else
579 return 0;
580}

◆ IsEqual()

char IsEqual ( const PSCRIPT_ENGINE_TOKEN Token1,
const PSCRIPT_ENGINE_TOKEN Token2 )

Checks whether the value and type of Token1 and Token2 are the same.

Parameters
Token1the first token to compare
Token2the second token to compare
Returns
char
1348{
1349 if (Token1->Type == Token2->Type)
1350 {
1351 if (Token1->Type == SPECIAL_TOKEN)
1352 {
1353 if (!strcmp(Token1->Value, Token2->Value))
1354 {
1355 return 1;
1356 }
1357 }
1358 else
1359 {
1360 return 1;
1361 }
1362 }
1363 if (Token1->Type == GLOBAL_ID && Token2->Type == GLOBAL_UNRESOLVED_ID)
1364 {
1365 return 1;
1366 }
1367 if (Token1->Type == GLOBAL_UNRESOLVED_ID && Token2->Type == GLOBAL_ID)
1368 {
1369 return 1;
1370 }
1371
1372 if (Token1->Type == LOCAL_ID && Token2->Type == LOCAL_UNRESOLVED_ID)
1373 {
1374 return 1;
1375 }
1376 if (Token1->Type == LOCAL_UNRESOLVED_ID && Token2->Type == LOCAL_ID)
1377 {
1378 return 1;
1379 }
1380
1381 return 0;
1382}

◆ IsHex()

char IsHex ( char c)

Checks whether input char belongs to hexadecimal digit-set or not.

Parameters
cthe character to check
Returns
char
560{
561 if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
562 return 1;
563 else
564 return 0;
565}

◆ IsLetter()

char IsLetter ( char c)

Checks whether input char belongs to alphabet set or not.

Parameters
cthe character to check
Returns
char
590{
591 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
592 return 1;
593 else
594 {
595 return 0;
596 }
597}

◆ IsNoneTerminal()

char IsNoneTerminal ( PSCRIPT_ENGINE_TOKEN Token)

Checks whether this Token is noneterminal NoneTerminal token starts with capital letter.

Parameters
Tokenthe token to check
Returns
char
1071{
1072 if (Token->Value[0] >= 'A' && Token->Value[0] <= 'Z')
1073 return 1;
1074 else
1075 return 0;
1076}

◆ IsOctal()

char IsOctal ( char c)

Checks whether input char belongs to octal digit-set or not.

Parameters
cthe character to check
Returns
char
641{
642 if (c >= '0' && c <= '7')
643 return 1;
644 else
645 return 0;
646}

◆ IsOneOperandOperator()

char IsOneOperandOperator ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is OperatorsOneOperandList.

Parameters
Operatorthe token to check
Returns
char
770{
771 unsigned int n = OPERATORS_ONE_OPERAND_LIST_LENGTH;
772 for (unsigned int i = 0; i < n; i++)
773 {
774 if (!strcmp(Operator->Value, OperatorsOneOperandList[i]))
775 {
776 return 1;
777 }
778 }
779 return 0;
780}
const char * OperatorsOneOperandList[]
Definition parse-table.c:1267
#define OPERATORS_ONE_OPERAND_LIST_LENGTH
Definition parse-table.h:10

◆ IsSemanticRule()

char IsSemanticRule ( PSCRIPT_ENGINE_TOKEN Token)

Checks whether this Token is semantic rule SemanticRule token starts with '@'.

Parameters
Tokenthe token to check
Returns
char
1087{
1088 if (Token->Value[0] == '@')
1089 return 1;
1090 else
1091 return 0;
1092}

◆ IsTwoOperandOperator()

char IsTwoOperandOperator ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is OperatorsTwoOperandList.

Parameters
Operatorthe token to check
Returns
char
750{
751 unsigned int n = OPERATORS_TWO_OPERAND_LIST_LENGTH;
752 for (unsigned int i = 0; i < n; i++)
753 {
754 if (!strcmp(Operator->Value, OperatorsTwoOperandList[i]))
755 {
756 return 1;
757 }
758 }
759 return 0;
760}
const char * OperatorsTwoOperandList[]
Definition parse-table.c:1249
#define OPERATORS_TWO_OPERAND_LIST_LENGTH
Definition parse-table.h:11

◆ IsType10Func()

char IsType10Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is TwoOpFunc3.

Parameters
Operatorthe token to check
Returns
char
910{
911 unsigned int n = TWOOPFUNC3_LENGTH;
912 for (unsigned int i = 0; i < n; i++)
913 {
914 if (!strcmp(Operator->Value, TwoOpFunc3[i]))
915 {
916 return 1;
917 }
918 }
919 return 0;
920}
const char * TwoOpFunc3[]
Definition parse-table.c:1349
#define TWOOPFUNC3_LENGTH
Definition parse-table.h:24

◆ IsType11Func()

char IsType11Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is ThreeOpFunc3.

Parameters
Operatorthe token to check
Returns
char
930{
931 unsigned int n = THREEOPFUNC3_LENGTH;
932 for (unsigned int i = 0; i < n; i++)
933 {
934 if (!strcmp(Operator->Value, ThreeOpFunc3[i]))
935 {
936 return 1;
937 }
938 }
939 return 0;
940}
const char * ThreeOpFunc3[]
Definition parse-table.c:1352
#define THREEOPFUNC3_LENGTH
Definition parse-table.h:25

◆ IsType12Func()

char IsType12Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is OneOpFunc4.

Parameters
Operatorthe token to check
Returns
char
950{
951 unsigned int n = ONEOPFUNC4_LENGTH;
952 for (unsigned int i = 0; i < n; i++)
953 {
954 if (!strcmp(Operator->Value, OneOpFunc4[i]))
955 {
956 return 1;
957 }
958 }
959 return 0;
960}
const char * OneOpFunc4[]
Definition parse-table.c:1359
#define ONEOPFUNC4_LENGTH
Definition parse-table.h:27

◆ IsType13Func()

char IsType13Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is TwoOpFunc4.

Parameters
Operatorthe token to check
Returns
char
970{
971 unsigned int n = TWOOPFUNC4_LENGTH;
972 for (unsigned int i = 0; i < n; i++)
973 {
974 if (!strcmp(Operator->Value, TwoOpFunc4[i]))
975 {
976 return 1;
977 }
978 }
979 return 0;
980}
const char * TwoOpFunc4[]
Definition parse-table.c:1362
#define TWOOPFUNC4_LENGTH
Definition parse-table.h:28

◆ IsType14Func()

char IsType14Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is ThreeOpFunc2.

Parameters
Operatorthe token to check
Returns
char
990{
991 unsigned int n = THREEOPFUNC2_LENGTH;
992 for (unsigned int i = 0; i < n; i++)
993 {
994 if (!strcmp(Operator->Value, ThreeOpFunc2[i]))
995 {
996 return 1;
997 }
998 }
999 return 0;
1000}
const char * ThreeOpFunc2[]
Definition parse-table.c:1287
#define THREEOPFUNC2_LENGTH
Definition parse-table.h:18

◆ IsType15Func()

char IsType15Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is ThreeOpFunc4.

Parameters
Operatorthe token to check
Returns
char
1010{
1011 unsigned int n = THREEOPFUNC4_LENGTH;
1012 for (unsigned int i = 0; i < n; i++)
1013 {
1014 if (!strcmp(Operator->Value, ThreeOpFunc4[i]))
1015 {
1016 return 1;
1017 }
1018 }
1019 return 0;
1020}
const char * ThreeOpFunc4[]
Definition parse-table.c:1356
#define THREEOPFUNC4_LENGTH
Definition parse-table.h:26

◆ IsType16Func()

char IsType16Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is ZeroOpFunc2.

Parameters
Operatorthe token to check
Returns
char
1030{
1031 unsigned int n = ZEROOPFUNC2_LENGTH;
1032 for (unsigned int i = 0; i < n; i++)
1033 {
1034 if (!strcmp(Operator->Value, ZeroOpFunc2[i]))
1035 {
1036 return 1;
1037 }
1038 }
1039 return 0;
1040}
const char * ZeroOpFunc2[]
Definition parse-table.c:1374
#define ZEROOPFUNC2_LENGTH
Definition parse-table.h:30

◆ IsType1Func()

char IsType1Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is OneOpFunc1.

Parameters
Operatorthe token to check
Returns
char
710{
711 unsigned int n = ONEOPFUNC1_LENGTH;
712 for (unsigned int i = 0; i < n; i++)
713 {
714 if (!strcmp(Operator->Value, OneOpFunc1[i]))
715 {
716 return 1;
717 }
718 }
719 return 0;
720}
const char * OneOpFunc1[]
Definition parse-table.c:1306
#define ONEOPFUNC1_LENGTH
Definition parse-table.h:21

◆ IsType2Func()

char IsType2Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is OneOpFunc2.

Parameters
Operatorthe token to check
Returns
char
730{
731 unsigned int n = ONEOPFUNC2_LENGTH;
732 for (unsigned int i = 0; i < n; i++)
733 {
734 if (!strcmp(Operator->Value, OneOpFunc2[i]))
735 {
736 return 1;
737 }
738 }
739 return 0;
740}
const char * OneOpFunc2[]
Definition parse-table.c:1334
#define ONEOPFUNC2_LENGTH
Definition parse-table.h:22

◆ IsType4Func()

char IsType4Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is VarArgFunc1.

Parameters
Operatorthe token to check
Returns
char
790{
791 unsigned int n = VARARGFUNC1_LENGTH;
792 for (unsigned int i = 0; i < n; i++)
793 {
794 if (!strcmp(Operator->Value, VarArgFunc1[i]))
795 {
796 return 1;
797 }
798 }
799 return 0;
800}
const char * VarArgFunc1[]
Definition parse-table.c:1383
#define VARARGFUNC1_LENGTH
Definition parse-table.h:31

◆ IsType5Func()

char IsType5Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is ZeroOpFunc1.

Parameters
Operatorthe token to check
Returns
char
810{
811 unsigned int n = ZEROOPFUNC1_LENGTH;
812 for (unsigned int i = 0; i < n; i++)
813 {
814 if (!strcmp(Operator->Value, ZeroOpFunc1[i]))
815 {
816 return 1;
817 }
818 }
819 return 0;
820}
const char * ZeroOpFunc1[]
Definition parse-table.c:1365
#define ZEROOPFUNC1_LENGTH
Definition parse-table.h:29

◆ IsType6Func()

char IsType6Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is TwoOpFunc1.

Parameters
Operatorthe token to check
Returns
char
830{
831 unsigned int n = TWOOPFUNC1_LENGTH;
832 for (unsigned int i = 0; i < n; i++)
833 {
834 if (!strcmp(Operator->Value, TwoOpFunc1[i]))
835 {
836 return 1;
837 }
838 }
839 return 0;
840}
const char * TwoOpFunc1[]
Definition parse-table.c:1292
#define TWOOPFUNC1_LENGTH
Definition parse-table.h:19

◆ IsType7Func()

char IsType7Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is TwoOpFunc2.

Parameters
Operatorthe token to check
Returns
char
850{
851 unsigned int n = TWOOPFUNC2_LENGTH;
852 for (unsigned int i = 0; i < n; i++)
853 {
854 if (!strcmp(Operator->Value, TwoOpFunc2[i]))
855 {
856 return 1;
857 }
858 }
859 return 0;
860}
const char * TwoOpFunc2[]
Definition parse-table.c:1302
#define TWOOPFUNC2_LENGTH
Definition parse-table.h:20

◆ IsType8Func()

char IsType8Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is ThreeOpFunc1.

Parameters
Operatorthe token to check
Returns
char
870{
871 unsigned int n = THREEOPFUNC1_LENGTH;
872 for (unsigned int i = 0; i < n; i++)
873 {
874 if (!strcmp(Operator->Value, ThreeOpFunc1[i]))
875 {
876 return 1;
877 }
878 }
879 return 0;
880}
const char * ThreeOpFunc1[]
Definition parse-table.c:1284
#define THREEOPFUNC1_LENGTH
Definition parse-table.h:17

◆ IsType9Func()

char IsType9Func ( PSCRIPT_ENGINE_TOKEN Operator)

Checks whether this Token type is OneOpFunc3.

Parameters
Operatorthe token to check
Returns
char
890{
891 unsigned int n = ONEOPFUNC3_LENGTH;
892 for (unsigned int i = 0; i < n; i++)
893 {
894 if (!strcmp(Operator->Value, OneOpFunc3[i]))
895 {
896 return 1;
897 }
898 }
899 return 0;
900}
const char * OneOpFunc3[]
Definition parse-table.c:1346
#define ONEOPFUNC3_LENGTH
Definition parse-table.h:23

◆ IsUnderscore()

char IsUnderscore ( char c)

Checks whether input char is underscore (_) or not.

Parameters
cthe character to check
Returns
char
607{
608 if (c >= '_')
609 return 1;
610 else
611 {
612 return 0;
613 }
614}

◆ LalrGetNonTerminalId()

int LalrGetNonTerminalId ( PSCRIPT_ENGINE_TOKEN Token)

Gets the Non Terminal Id object.

Parameters
Tokenthe token to get the non-terminal ID of
Returns
int the non-terminal ID or INVALID
1228{
1229 for (int i = 0; i < LALR_NONTERMINAL_COUNT; i++)
1230 {
1231 if (!strcmp(Token->Value, LalrNoneTerminalMap[i]))
1232 return i;
1233 }
1234 return INVALID;
1235}
const char * LalrNoneTerminalMap[NONETERMINAL_COUNT]
Definition parse-table.c:2066
#define LALR_NONTERMINAL_COUNT
Definition parse-table.h:65

◆ LalrGetTerminalId()

int LalrGetTerminalId ( PSCRIPT_ENGINE_TOKEN Token)

Gets the Terminal Id object.

Parameters
Tokenthe token to get the terminal ID of
Returns
int the terminal ID or INVALID
1245{
1246 for (int i = 0; i < LALR_TERMINAL_COUNT; i++)
1247 {
1248 if (Token->Type == HEX)
1249 {
1250 if (!strcmp("_hex", LalrTerminalMap[i]))
1251 return i;
1252 }
1253 else if (Token->Type == GLOBAL_ID || Token->Type == GLOBAL_UNRESOLVED_ID)
1254 {
1255 if (!strcmp("_global_id", LalrTerminalMap[i]))
1256 {
1257 return i;
1258 }
1259 }
1260 else if (Token->Type == LOCAL_ID || Token->Type == LOCAL_UNRESOLVED_ID)
1261 {
1262 if (!strcmp("_local_id", LalrTerminalMap[i]))
1263 {
1264 return i;
1265 }
1266 }
1267 else if (Token->Type == FUNCTION_ID)
1268 {
1269 if (!strcmp("_function_id", LalrTerminalMap[i]))
1270 {
1271 return i;
1272 }
1273 }
1274 else if (Token->Type == FUNCTION_PARAMETER_ID)
1275 {
1276 if (!strcmp("_function_parameter_id", LalrTerminalMap[i]))
1277 {
1278 return i;
1279 }
1280 }
1281 else if (Token->Type == REGISTER)
1282 {
1283 if (!strcmp("_register", LalrTerminalMap[i]))
1284 {
1285 return i;
1286 }
1287 }
1288 else if (Token->Type == PSEUDO_REGISTER)
1289 {
1290 if (!strcmp("_pseudo_register", LalrTerminalMap[i]))
1291 {
1292 return i;
1293 }
1294 }
1295 else if (Token->Type == DECIMAL)
1296 {
1297 if (!strcmp("_decimal", LalrTerminalMap[i]))
1298 {
1299 return i;
1300 }
1301 }
1302 else if (Token->Type == BINARY)
1303 {
1304 if (!strcmp("_binary", LalrTerminalMap[i]))
1305 {
1306 return i;
1307 }
1308 }
1309 else if (Token->Type == OCTAL)
1310 {
1311 if (!strcmp("_octal", LalrTerminalMap[i]))
1312 {
1313 return i;
1314 }
1315 }
1316 else if (Token->Type == STRING)
1317 {
1318 if (!strcmp("_string", LalrTerminalMap[i]))
1319 {
1320 return i;
1321 }
1322 }
1323 else if (Token->Type == WSTRING)
1324 {
1325 if (!strcmp("_wstring", LalrTerminalMap[i]))
1326 {
1327 return i;
1328 }
1329 }
1330 else // Keyword
1331 {
1332 if (!strcmp(Token->Value, LalrTerminalMap[i]))
1333 return i;
1334 }
1335 }
1336 return INVALID;
1337}
const char * LalrTerminalMap[TERMINAL_COUNT]
Definition parse-table.c:2095
#define LALR_TERMINAL_COUNT
Definition parse-table.h:64

◆ NewTemp()

Allocates a new temporary variable and returns it.

Parameters
Errorthe error type pointer
Returns
PSCRIPT_ENGINE_TOKEN
656{
657 static unsigned int TempID = 0;
658 int i;
659 for (i = 0; i < MAX_TEMP_COUNT; i++)
660 {
661 if (CurrentUserDefinedFunction->TempMap[i] == 0)
662 {
663 TempID = i;
664 CurrentUserDefinedFunction->TempMap[i] = 1;
665 break;
666 }
667 }
668 if (i == MAX_TEMP_COUNT)
669 {
671 }
673 char TempValue[8];
674 sprintf(TempValue, "%d", TempID);
675 strcpy(Temp->Value, TempValue);
676 Temp->Type = TEMP;
677
678 if (CurrentUserDefinedFunction->MaxTempNumber < (i + 1))
679 {
680 CurrentUserDefinedFunction->MaxTempNumber = i + 1;
681 }
682
683 return Temp;
684}
PSCRIPT_ENGINE_TOKEN NewUnknownToken()
Allocates a new token.
Definition common.c:20
#define MAX_TEMP_COUNT
Definition globals.h:16
@ SCRIPT_ENGINE_ERROR_TEMP_LIST_FULL
Definition type.h:75

◆ NewToken()

PSCRIPT_ENGINE_TOKEN NewToken ( SCRIPT_ENGINE_TOKEN_TYPE Type,
char * Value )

Allocates a new token with given type and value.

Parameters
Typethe type of the token
Valuethe value string of the token
Returns
PSCRIPT_ENGINE_TOKEN the allocated new token
70{
71 //
72 // Allocate memory for token]
73 //
75
76 if (Token == NULL)
77 {
78 //
79 // There was an error allocating buffer
80 //
81 return NULL;
82 }
83
84 //
85 // Init fields
86 //
87 unsigned int Len = (unsigned int)strlen(Value);
88 Token->Type = Type;
89 Token->Len = Len;
90 Token->MaxLen = Len;
91 Token->Value = (char *)calloc(Token->MaxLen + 1, sizeof(char));
93 Token->VariableMemoryIdx = 0;
94
95 if (Token->Value == NULL)
96 {
97 //
98 // There was an error allocating buffer
99 //
100 free(Token);
101 return NULL;
102 }
103
104 strcpy(Token->Value, Value);
105
106 return Token;
107}
RequestedActionOfThePacket Value(0x1) 00000000
unsigned long long VariableMemoryIdx
Definition common.h:77

◆ NewTokenList()

PSCRIPT_ENGINE_TOKEN_LIST NewTokenList ( void )

Allocates a new SCRIPT_ENGINE_TOKEN_LIST.

Returns
PSCRIPT_ENGINE_TOKEN_LIST the allocated token list
365{
367
368 //
369 // Allocation of memory for SCRIPT_ENGINE_TOKEN_LIST structure
370 //
371 TokenList = (PSCRIPT_ENGINE_TOKEN_LIST)malloc(sizeof(*TokenList));
372
373 if (TokenList == NULL)
374 {
375 //
376 // There was an error allocating buffer
377 //
378 return NULL;
379 }
380
381 //
382 // Initialize fields of SCRIPT_ENGINE_TOKEN_LIST
383 //
384 TokenList->Pointer = 0;
385 TokenList->Size = TOKEN_LIST_INIT_SIZE;
386
387 //
388 // Allocation of memory for SCRIPT_ENGINE_TOKEN_LIST buffer
389 //
390 TokenList->Head = (PSCRIPT_ENGINE_TOKEN *)malloc(TokenList->Size * sizeof(PSCRIPT_ENGINE_TOKEN));
391
392 return TokenList;
393}
struct _SCRIPT_ENGINE_TOKEN_LIST * PSCRIPT_ENGINE_TOKEN_LIST
#define TOKEN_LIST_INIT_SIZE
init size of token list
Definition common.h:31
unsigned int Size
Definition common.h:87
PSCRIPT_ENGINE_TOKEN * Head
Definition common.h:85

◆ NewUnknownToken()

PSCRIPT_ENGINE_TOKEN NewUnknownToken ( void )

Allocates a new token.

Returns
PSCRIPT_ENGINE_TOKEN the allocated new unknown token
21{
23
24 //
25 // Allocate memory for token and its value
26 //
27 Token = (PSCRIPT_ENGINE_TOKEN)malloc(sizeof(SCRIPT_ENGINE_TOKEN));
28
29 if (Token == NULL)
30 {
31 //
32 // There was an error allocating buffer
33 //
34 return NULL;
35 }
36
37 Token->Value = (char *)calloc(TOKEN_VALUE_MAX_LEN + 1, sizeof(char));
38
39 if (Token->Value == NULL)
40 {
41 //
42 // There was an error allocating buffer
43 //
44 free(Token);
45 return NULL;
46 }
47
48 //
49 // Init fields
50 //
51 strcpy(Token->Value, "");
52 Token->Type = UNKNOWN;
53 Token->Len = 0;
56 Token->VariableMemoryIdx = 0;
57
58 return Token;
59}
#define TOKEN_VALUE_MAX_LEN
maximum length of string in the token
Definition common.h:26

◆ OctalToInt()

unsigned long long OctalToInt ( char * str)

Converts an octal string to integer.

Parameters
strthe octal string to convert
Returns
unsigned long long
1493{
1494 SIZE_T Len;
1495 unsigned long long Acc = 0;
1496
1497 Len = strlen(str);
1498
1499 for (int i = 0; i < Len; i++)
1500 {
1501 Acc <<= 3;
1502 Acc += (str[i] - '0');
1503 }
1504 return Acc;
1505}

◆ Pop()

Removes last Token of a TokenList and returns it.

Parameters
TokenList
Returns
PSCRIPT_ENGINE_TOKEN
503{
504 //
505 // Calculate address to read most recent token
506 //
507 if (TokenList->Pointer > 0)
508 TokenList->Pointer--; // not consider what if the token's type is string or wstring
509 uintptr_t Head = (uintptr_t)TokenList->Head;
510 uintptr_t Pointer = (uintptr_t)TokenList->Pointer;
511 PSCRIPT_ENGINE_TOKEN * ReadAddr = (PSCRIPT_ENGINE_TOKEN *)(Head + Pointer * sizeof(PSCRIPT_ENGINE_TOKEN));
512
513 return *ReadAddr;
514}

◆ PrintToken()

VOID PrintToken ( PSCRIPT_ENGINE_TOKEN Token)

Prints token.

prints value and type of token

Parameters
Tokenthe token to print
Returns
void
133{
134 //
135 // Prints value of the Token
136 //
137 if (Token->Type == WHITE_SPACE)
138 {
139 printf("< :");
140 }
141 else
142 {
143 printf("<'%s' : ", Token->Value);
144 }
145
146 //
147 // Prints type of the Token
148 //
149 switch (Token->Type)
150 {
151 case GLOBAL_ID:
152 printf(" GLOBAL_ID>\n");
153 break;
155 printf(" GLOBAL_UNRESOLVED_ID>\n");
156 break;
157 case LOCAL_ID:
158 printf(" LOCAL_ID>\n");
159 break;
161 printf(" LOCAL_UNRESOLVED_ID>\n");
162 break;
163 case STATE_ID:
164 printf(" STATE_ID>\n");
165 break;
166 case DECIMAL:
167 printf(" DECIMAL>\n");
168 break;
169 case HEX:
170 printf(" HEX>\n");
171 break;
172 case OCTAL:
173 printf(" OCTAL>\n");
174 break;
175 case BINARY:
176 printf(" BINARY>\n");
177 break;
178 case SPECIAL_TOKEN:
179 printf(" SPECIAL_TOKEN>\n");
180 break;
181 case KEYWORD:
182 printf(" KEYWORD>\n");
183 break;
184 case WHITE_SPACE:
185 printf(" WHITE_SPACE>\n");
186 break;
187 case COMMENT:
188 printf(" COMMENT>\n");
189 break;
190 case REGISTER:
191 printf(" REGISTER>\n");
192 break;
193 case PSEUDO_REGISTER:
194 printf(" PSEUDO_REGISTER>\n");
195 break;
196 case SEMANTIC_RULE:
197 printf(" SEMANTIC_RULE>\n");
198 break;
199 case NON_TERMINAL:
200 printf(" NON_TERMINAL>\n");
201 break;
202 case END_OF_STACK:
203 printf(" END_OF_STACK>\n");
204 break;
205 case STRING:
206 printf(" STRING>\n");
207 break;
208 case WSTRING:
209 printf(" WSTRING>\n");
210 break;
211 case TEMP:
212 printf(" TEMP>\n");
213 break;
214 case UNKNOWN:
215 printf(" UNKNOWN>\n");
216 break;
218 printf(" SCRIPT_VARIABLE_TYPE>\n");
219 break;
220 case FUNCTION_ID:
221 printf(" FUNCTION_ID>\n");
222 break;
224 printf(" FUNCTION_PARAMETER_ID>\n");
225 break;
226 case DEFERENCE_TEMP:
227 printf(" DEFERENCE_TEMP>\n");
228 break;
229 default:
230 printf(" ERROR>\n");
231 break;
232 }
233}

◆ PrintTokenList()

VOID PrintTokenList ( PSCRIPT_ENGINE_TOKEN_LIST TokenList)

Prints each Token inside a TokenList.

Parameters
TokenList
Returns
void
424{
426 for (uintptr_t i = 0; i < TokenList->Pointer; i++)
427 {
428 Token = *(TokenList->Head + i);
429 PrintToken(Token);
430 }
431}
void PrintToken(PSCRIPT_ENGINE_TOKEN Token)
Prints token.
Definition common.c:132

◆ Push()

Adds Token to the last empty position of TokenList.

Parameters
TokenListthe token list to push into
Tokenthe token to add
Returns
PSCRIPT_ENGINE_TOKEN_LIST
442{
443 //
444 // Calculate address to write new token
445 //
446 uintptr_t Head = (uintptr_t)TokenList->Head;
447 uintptr_t Pointer = (uintptr_t)TokenList->Pointer;
448 PSCRIPT_ENGINE_TOKEN * WriteAddr = (PSCRIPT_ENGINE_TOKEN *)(Head + Pointer * sizeof(PSCRIPT_ENGINE_TOKEN));
449
450 //
451 // Write Token to appropriate address in TokenList
452 //
453 *WriteAddr = Token;
454
455 //
456 // Update Pointer
457 //
458 TokenList->Pointer++;
459
460 //
461 // Handle overflow
462 //
463 if (Pointer == TokenList->Size - 1)
464 {
465 //
466 // Allocate a new buffer for string list with doubled length
467 //
468 PSCRIPT_ENGINE_TOKEN * NewHead = (PSCRIPT_ENGINE_TOKEN *)malloc(2 * TokenList->Size * sizeof(PSCRIPT_ENGINE_TOKEN));
469
470 if (NewHead == NULL)
471 {
472 printf("err, could not allocate buffer");
473 return NULL;
474 }
475
476 //
477 // Copy old buffer to new buffer
478 //
479 memcpy(NewHead, TokenList->Head, TokenList->Size * sizeof(PSCRIPT_ENGINE_TOKEN));
480
481 //
482 // Free old buffer
483 //
484 free(TokenList->Head);
485
486 //
487 // Update Head and size of TokenList
488 //
489 TokenList->Size = TokenList->Size * 2;
490 TokenList->Head = NewHead;
491 }
492
493 return TokenList;
494}

◆ RemoveToken()

VOID RemoveToken ( PSCRIPT_ENGINE_TOKEN * Token)

Removes allocated memory of a token.

Parameters
Token
Returns
void
117{
118 free((*Token)->Value);
119 free(*Token);
120 *Token = NULL;
121 return;
122}

◆ RemoveTokenList()

VOID RemoveTokenList ( PSCRIPT_ENGINE_TOKEN_LIST TokenList)

Removes allocated memory of a SCRIPT_ENGINE_TOKEN_LIST.

Parameters
TokenList
Returns
void
403{
405 for (uintptr_t i = 0; i < TokenList->Pointer; i++)
406 {
407 Token = *(TokenList->Head + i);
408 RemoveToken(&Token);
409 }
410 free(TokenList->Head);
411 free(TokenList);
412
413 return;
414}

◆ RotateLeftStringOnce()

VOID RotateLeftStringOnce ( char * str)

Rotate a character array to the left by one time.

Parameters
strthe string to rotate
Returns
void
1537{
1538 INT Length = (INT)strlen(str);
1539 CHAR Temp = str[0];
1540 for (int i = 0; i < (Length - 1); i++)
1541 {
1542 str[i] = str[i + 1];
1543 }
1544 str[Length - 1] = Temp;
1545}

◆ SetType()

VOID SetType ( unsigned long long * Val,
unsigned char Type )

Set the Type object.

Parameters
Val
Type
Returns
void
1393{
1394 *Val = (unsigned long long int)Type;
1395}

◆ Top()

Returns last Token of a TokenList.

Parameters
TokenList
Returns
PSCRIPT_ENGINE_TOKEN
524{
525 //
526 // Calculate address to read most recent pushed token
527 //
528 uintptr_t Head = (uintptr_t)TokenList->Head;
529 uintptr_t Pointer = (uintptr_t)TokenList->Pointer - 1;
530 PSCRIPT_ENGINE_TOKEN * ReadAddr = (PSCRIPT_ENGINE_TOKEN *)(Head + Pointer * sizeof(PSCRIPT_ENGINE_TOKEN));
531
532 return *ReadAddr;
533}

◆ TopIndexed()

PSCRIPT_ENGINE_TOKEN TopIndexed ( PSCRIPT_ENGINE_TOKEN_LIST TokenList,
int Index )

Returns the token at a specific index from the top of the token list.

Parameters
TokenListthe token list to index into
Indexthe zero-based index from the top
Returns
PSCRIPT_ENGINE_TOKEN
544{
545 uintptr_t Head = (uintptr_t)TokenList->Head;
546 uintptr_t Pointer = (uintptr_t)TokenList->Pointer - 1 - Index;
547 PSCRIPT_ENGINE_TOKEN * ReadAddr = (PSCRIPT_ENGINE_TOKEN *)(Head + Pointer * sizeof(PSCRIPT_ENGINE_TOKEN));
548
549 return *ReadAddr;
550}