HyperDbg Debugger
Loading...
Searching...
No Matches
scanner.c File Reference
#include "pch.h"

Functions

PSCRIPT_ENGINE_TOKEN GetToken (char *c, char *str)
 reads a token from the input string
PSCRIPT_ENGINE_TOKEN Scan (char *str, char *c)
 Perform scanning the script engine.
char sgetc (char *str)
 Returns the next character in the input string.
char IsKeyword (char *str)
 Check whether a string is a keyword or not.
char IsRegister (char *str)
 Check if string is register or not.
char IsVariableType (char *str)
 Check if string is variable type or not.
char IsId (char *str)
 Check if string is Id or not.

Detailed Description

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

Script Engine Scanner

Version
0.1
Date
2020-10-22

Function Documentation

◆ GetToken()

PSCRIPT_ENGINE_TOKEN GetToken ( char * c,
char * str )

reads a token from the input string

Parameters
c
str
Returns
PSCRIPT_ENGINE_TOKEN
23{
25
26 switch (*c)
27 {
28 case '"':
29 do
30 {
31 *c = sgetc(str);
32
33 if (*c == '\\')
34 {
35 *c = sgetc(str);
36 if (*c == 'n')
37 {
38 AppendByte(Token, '\n');
39 continue;
40 }
41 if (*c == '\\')
42 {
43 AppendByte(Token, '\\');
44 continue;
45 }
46 else if (*c == 't')
47 {
48 AppendByte(Token, '\t');
49 continue;
50 }
51 else if (*c == 'x')
52 {
53 char ByteString[] = "000";
54 INT Len = (INT)strlen(ByteString);
55 int i = 0;
56 for (; i < Len; i++)
57 {
58 *c = sgetc(str);
59 if (!IsHex(*c))
60 break;
61
62 RotateLeftStringOnce(ByteString);
63 ByteString[Len - 1] = *c;
64 }
65
66 if (i == 0 || i == 3)
67 {
68 Token->Type = UNKNOWN;
69 *c = sgetc(str);
70 return Token;
71 }
72 else
73 {
74 InputIdx--;
75 CHAR Num = (CHAR)strtol(ByteString, NULL, 16);
76 AppendByte(Token, Num);
77 }
78 }
79 else if (*c == '"')
80 {
81 AppendByte(Token, '"');
82 continue;
83 }
84 else
85 {
86 Token->Type = UNKNOWN;
87 *c = sgetc(str);
88 return Token;
89 }
90 }
91 else if (*c == '"')
92 {
93 break;
94 }
95 else
96 {
97 AppendByte(Token, *c);
98 }
99 } while (1);
100
101 Token->Len++;
102 Token->Type = STRING;
103 *c = sgetc(str);
104 return Token;
105 case '~':
106 strcpy(Token->Value, "~");
107 Token->Type = SPECIAL_TOKEN;
108 *c = sgetc(str);
109 return Token;
110
111 case '+':
112 *c = sgetc(str);
113 if (*c == '+')
114 {
115 strcpy(Token->Value, "++");
116 Token->Type = SPECIAL_TOKEN;
117 *c = sgetc(str);
118 return Token;
119 }
120 else if (*c == '=')
121 {
122 strcpy(Token->Value, "+=");
123 Token->Type = SPECIAL_TOKEN;
124 *c = sgetc(str);
125 return Token;
126 }
127 else
128 {
129 strcpy(Token->Value, "+");
130 Token->Type = SPECIAL_TOKEN;
131 return Token;
132 }
133 case '-':
134 *c = sgetc(str);
135 if (*c == '-')
136 {
137 strcpy(Token->Value, "--");
138 Token->Type = SPECIAL_TOKEN;
139 *c = sgetc(str);
140 return Token;
141 }
142 else if (*c == '=')
143 {
144 strcpy(Token->Value, "-=");
145 Token->Type = SPECIAL_TOKEN;
146 *c = sgetc(str);
147 return Token;
148 }
149 else
150 {
151 strcpy(Token->Value, "-");
152 Token->Type = SPECIAL_TOKEN;
153 return Token;
154 }
155 case '*':
156 *c = sgetc(str);
157 if (*c == '=')
158 {
159 strcpy(Token->Value, "*=");
160 Token->Type = SPECIAL_TOKEN;
161 *c = sgetc(str);
162 return Token;
163 }
164 else
165 {
166 strcpy(Token->Value, "*");
167 Token->Type = SPECIAL_TOKEN;
168 return Token;
169 }
170 case '>':
171 *c = sgetc(str);
172 if (*c == '>')
173 {
174 *c = sgetc(str);
175 if (*c == '=')
176 {
177 strcpy(Token->Value, ">>=");
178 Token->Type = SPECIAL_TOKEN;
179 *c = sgetc(str);
180 return Token;
181 }
182 else
183 {
184 strcpy(Token->Value, ">>");
185 Token->Type = SPECIAL_TOKEN;
186 return Token;
187 }
188 }
189 else if (*c == '=')
190 {
191 strcpy(Token->Value, ">=");
192 Token->Type = SPECIAL_TOKEN;
193 *c = sgetc(str);
194 return Token;
195 }
196 else
197 {
198 strcpy(Token->Value, ">");
199 Token->Type = SPECIAL_TOKEN;
200 return Token;
201 }
202 case '<':
203 *c = sgetc(str);
204 if (*c == '<')
205 {
206 *c = sgetc(str);
207 if (*c == '=')
208 {
209 strcpy(Token->Value, "<<=");
210 Token->Type = SPECIAL_TOKEN;
211 *c = sgetc(str);
212 return Token;
213 }
214 else
215 {
216 strcpy(Token->Value, "<<");
217 Token->Type = SPECIAL_TOKEN;
218 return Token;
219 }
220 }
221 else if (*c == '=')
222 {
223 strcpy(Token->Value, "<=");
224 Token->Type = SPECIAL_TOKEN;
225 *c = sgetc(str);
226 return Token;
227 }
228 else
229 {
230 strcpy(Token->Value, "<");
231 Token->Type = SPECIAL_TOKEN;
232 return Token;
233 }
234 case '/':
235 *c = sgetc(str);
236 if (*c == '=')
237 {
238 strcpy(Token->Value, "/=");
239 Token->Type = SPECIAL_TOKEN;
240 *c = sgetc(str);
241
242 return Token;
243 }
244 else if (*c == '/')
245 {
246 do
247 {
248 *c = sgetc(str);
249 } while (*c != '\n' && (int)*c != EOF);
250
251 Token->Type = COMMENT;
252 *c = sgetc(str);
253 return Token;
254 }
255 else if (*c == '*')
256 {
257 do
258 {
259 *c = sgetc(str);
260 if (*c == '*')
261 {
262 *c = sgetc(str);
263 if (*c == '/')
264 {
265 Token->Type = COMMENT;
266 *c = sgetc(str);
267 return Token;
268 }
269 }
270 if ((int)*c == EOF)
271 break;
272 } while (1);
273
274 Token->Type = UNKNOWN;
275 *c = sgetc(str);
276 return Token;
277 }
278 else
279 {
280 strcpy(Token->Value, "/");
281 Token->Type = SPECIAL_TOKEN;
282 return Token;
283 }
284
285 case '=':
286 *c = sgetc(str);
287 if (*c == '=')
288 {
289 strcpy(Token->Value, "==");
290 Token->Type = SPECIAL_TOKEN;
291 *c = sgetc(str);
292 return Token;
293 }
294 else
295 {
296 strcpy(Token->Value, "=");
297 Token->Type = SPECIAL_TOKEN;
298 return Token;
299 }
300 case '!':
301 *c = sgetc(str);
302 if (*c == '=')
303 {
304 strcpy(Token->Value, "!=");
305 Token->Type = SPECIAL_TOKEN;
306 *c = sgetc(str);
307 return Token;
308 }
309 else
310 {
311 strcpy(Token->Value, "!");
312 Token->Type = UNKNOWN;
313 return Token;
314 }
315 case '%':
316 *c = sgetc(str);
317 if (*c == '=')
318 {
319 strcpy(Token->Value, "%=");
320 Token->Type = SPECIAL_TOKEN;
321 *c = sgetc(str);
322 return Token;
323 }
324 else
325 {
326 strcpy(Token->Value, "%");
327 Token->Type = SPECIAL_TOKEN;
328 }
329 return Token;
330
331 case ',':
332 strcpy(Token->Value, ",");
333 Token->Type = SPECIAL_TOKEN;
334 *c = sgetc(str);
335 return Token;
336
337 case ';':
338 strcpy(Token->Value, ";");
339 Token->Type = SPECIAL_TOKEN;
340 *c = sgetc(str);
341 return Token;
342
343 case ':':
344 strcpy(Token->Value, ":");
345 Token->Type = SPECIAL_TOKEN;
346 *c = sgetc(str);
347 return Token;
348
349 case '(':
350 strcpy(Token->Value, "(");
351 Token->Type = SPECIAL_TOKEN;
352 *c = sgetc(str);
353 return Token;
354 case ')':
355 strcpy(Token->Value, ")");
356 Token->Type = SPECIAL_TOKEN;
357 *c = sgetc(str);
358 return Token;
359 case '{':
360 strcpy(Token->Value, "{");
361 Token->Type = SPECIAL_TOKEN;
362 *c = sgetc(str);
363 return Token;
364 case '}':
365 strcpy(Token->Value, "}");
366 Token->Type = SPECIAL_TOKEN;
367 *c = sgetc(str);
368 return Token;
369 case '[':
370 strcpy(Token->Value, "[");
371 Token->Type = SPECIAL_TOKEN;
372 *c = sgetc(str);
373 return Token;
374 case ']':
375 strcpy(Token->Value, "]");
376 Token->Type = SPECIAL_TOKEN;
377 *c = sgetc(str);
378 return Token;
379 case '|':
380 *c = sgetc(str);
381 if (*c == '|')
382 {
383 strcpy(Token->Value, "||");
384 Token->Type = SPECIAL_TOKEN;
385 *c = sgetc(str);
386 return Token;
387 }
388 else if (*c == '=')
389 {
390 strcpy(Token->Value, "|=");
391 Token->Type = SPECIAL_TOKEN;
392 *c = sgetc(str);
393 return Token;
394 }
395 else
396 {
397 strcpy(Token->Value, "|");
398 Token->Type = SPECIAL_TOKEN;
399 return Token;
400 }
401 case '&':
402 *c = sgetc(str);
403 if (*c == '&')
404 {
405 strcpy(Token->Value, "&&");
406 Token->Type = SPECIAL_TOKEN;
407 *c = sgetc(str);
408 return Token;
409 }
410 else if (*c == '=')
411 {
412 strcpy(Token->Value, "&=");
413 Token->Type = SPECIAL_TOKEN;
414 *c = sgetc(str);
415 return Token;
416 }
417 else
418 {
419 strcpy(Token->Value, "&");
420 Token->Type = SPECIAL_TOKEN;
421 return Token;
422 }
423
424 case '^':
425 *c = sgetc(str);
426 if (*c == '=')
427 {
428 strcpy(Token->Value, "^=");
429 Token->Type = SPECIAL_TOKEN;
430 *c = sgetc(str);
431 return Token;
432 }
433 else
434 {
435 strcpy(Token->Value, "^");
436 Token->Type = SPECIAL_TOKEN;
437 }
438 return Token;
439 case '@':
440 *c = sgetc(str);
441 if (IsLetter(*c))
442 {
443 while (IsLetter(*c) || IsDecimal(*c) || IsUnderscore(*c))
444 {
445 AppendByte(Token, *c);
446 *c = sgetc(str);
447 }
448 if (RegisterToInt(Token->Value) != INVALID)
449 {
450 Token->Type = REGISTER;
451 }
452 else
453 {
454 Token->Type = UNKNOWN;
455 }
456 return Token;
457 }
458
459 case '$':
460 *c = sgetc(str);
461 if (IsLetter(*c))
462 {
463 //
464 // Append valid characters for pseudo registers' name
465 //
466 while (IsLetter(*c) || IsDecimal(*c) || *c == '_')
467 {
468 AppendByte(Token, *c);
469 *c = sgetc(str);
470 }
471 if (PseudoRegToInt(Token->Value) != INVALID)
472 {
473 Token->Type = PSEUDO_REGISTER;
474 }
475 else
476 {
477 Token->Type = UNKNOWN;
478 }
479
480 return Token;
481 }
482
483 case '.':
484 AppendByte(Token, *c);
485 *c = sgetc(str);
486 if (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'))
487 {
488 do
489 {
490 AppendByte(Token, *c);
491 *c = sgetc(str);
492 } while (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'));
493
494 BOOLEAN WasFound = FALSE;
495 BOOLEAN HasBang = strstr(Token->Value, "!") != 0;
496 UINT64 Address = 0;
497
498 if (HasBang)
499 {
500 Address = ScriptEngineConvertNameToAddress(Token->Value, &WasFound);
501 }
502
503 if (WasFound)
504 {
505 RemoveToken(&Token);
506 char HexStr[20] = {0};
507 sprintf(HexStr, "%llx", Address);
508 Token = NewToken(HEX, HexStr);
509 }
510 else
511 {
512 if (HasBang)
513 {
514 Token->Type = UNKNOWN;
515 return Token;
516 }
517 else
518 {
519 if (GetGlobalIdentifierVal(Token) != -1)
520 {
521 Token->Type = GLOBAL_ID;
523 }
524 else
525 {
526 Token->Type = GLOBAL_UNRESOLVED_ID;
527 }
528 }
529 }
530 }
531 else
532 {
533 Token->Type = UNKNOWN;
534 return Token;
535 }
536 return Token;
537
538 case '#':
539 do
540 {
541 if (*c != '`')
542 AppendByte(Token, *c);
543 *c = sgetc(str);
544 } while (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'));
545 if (IsKeyword(Token->Value))
546 {
547 Token->Type = KEYWORD;
548 }
549 else
550 {
551 Token->Type = UNKNOWN;
552 }
553 return Token;
554
555 case ' ':
556 case '\t':
557 strcpy(Token->Value, "");
558 Token->Type = WHITE_SPACE;
559 *c = sgetc(str);
560 return Token;
561 case '\n':
562 strcpy(Token->Value, "\n");
563 Token->Type = WHITE_SPACE;
564 *c = sgetc(str);
565 return Token;
566
567 case '0':
568 *c = sgetc(str);
569 if (*c == 'x')
570 {
571 *c = sgetc(str);
572 while (IsHex(*c) || *c == '`')
573 {
574 if (*c != '`')
575 AppendByte(Token, *c);
576 *c = sgetc(str);
577 }
578 Token->Type = HEX;
579 return Token;
580 }
581 else if (*c == 'o')
582 {
583 *c = sgetc(str);
584 while (IsOctal(*c) || *c == '`')
585 {
586 if (*c != '`')
587 AppendByte(Token, *c);
588 *c = sgetc(str);
589 }
590 Token->Type = OCTAL;
591 return Token;
592 }
593 else if (*c == 'n')
594 {
595 *c = sgetc(str);
596 while (IsDecimal(*c) || *c == '`')
597 {
598 if (*c != '`')
599 AppendByte(Token, *c);
600 *c = sgetc(str);
601 }
602 Token->Type = DECIMAL;
603 return Token;
604 }
605 else if (*c == 'y')
606 {
607 *c = sgetc(str);
608 while (IsBinary(*c) || *c == '`')
609 {
610 if (*c != '`')
611 AppendByte(Token, *c);
612 *c = sgetc(str);
613 }
614 Token->Type = BINARY;
615 return Token;
616 }
617
618 else if (IsHex(*c))
619 {
620 do
621 {
622 if (*c != '`')
623 AppendByte(Token, *c);
624 *c = sgetc(str);
625 } while (IsHex(*c) || *c == '`');
626 Token->Type = HEX;
627 return Token;
628 }
629 else
630 {
631 strcpy(Token->Value, "0");
632 Token->Type = HEX;
633 return Token;
634 }
635
636 case 'L':
637 if (*(str + InputIdx) == '"')
638 {
639 InputIdx++;
640 do
641 {
642 *c = sgetc(str);
643
644 if (*c == '\\')
645 {
646 *c = sgetc(str);
647 if (*c == 'n')
648 {
649 AppendWchar(Token, L'\n');
650 continue;
651 }
652 if (*c == '\\')
653 {
654 AppendWchar(Token, L'\\');
655 continue;
656 }
657 else if (*c == 't')
658 {
659 AppendWchar(Token, L'\t');
660 continue;
661 }
662 else if (*c == 'x')
663 {
664 char ByteString[] = "00000";
665 INT Len = (INT)strlen(ByteString);
666 int i = 0;
667 for (; i < Len; i++)
668 {
669 *c = sgetc(str);
670 if (!IsHex(*c))
671 break;
672
673 RotateLeftStringOnce(ByteString);
674 ByteString[Len - 1] = *c;
675 }
676
677 if (i == 0 || i == 5)
678 {
679 Token->Type = UNKNOWN;
680 *c = sgetc(str);
681 return Token;
682 }
683 else
684 {
685 InputIdx--;
686 WCHAR Num = (WCHAR)strtol(ByteString, NULL, 16);
687 AppendWchar(Token, Num);
688 }
689 }
690 else if (*c == '"')
691 {
692 AppendWchar(Token, L'"');
693 continue;
694 }
695 else
696 {
697 Token->Type = UNKNOWN;
698 *c = sgetc(str);
699 return Token;
700 }
701 }
702 else if (*c == '"')
703 {
704 break;
705 }
706 else
707 {
708 AppendWchar(Token, (wchar_t)*c);
709 }
710 } while (1);
711
712 Token->Len += 2;
713 Token->Type = WSTRING;
714 *c = sgetc(str);
715 return Token;
716 }
717
718 default:
719 if (*c >= '0' && *c <= '9')
720 {
721 do
722 {
723 if (*c != '`')
724 AppendByte(Token, *c);
725 *c = sgetc(str);
726 } while (IsHex(*c) || *c == '`');
727 Token->Type = HEX;
728 return Token;
729 }
730 else if ((*c >= 'a' && *c <= 'f') || (*c >= 'A' && *c <= 'F') || (*c == '_') || (*c == '!'))
731 {
732 UINT8 NotHex = 0;
733 do
734 {
735 if (*c != '`')
736 AppendByte(Token, *c);
737
738 *c = sgetc(str);
739 if (IsHex(*c) || *c == '`' || *c == '_')
740 {
741 // Nothing
742 }
743 else if ((*c >= 'G' && *c <= 'Z') || (*c >= 'g' && *c <= 'z'))
744 {
745 NotHex = 1;
746 break;
747 }
748 else
749 {
750 break;
751 }
752 } while (1);
753 if (NotHex)
754 {
755 do
756 {
757 if (*c != '`')
758 AppendByte(Token, *c);
759 *c = sgetc(str);
760 } while (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'));
761 if (IsKeyword(Token->Value))
762 {
763 Token->Type = KEYWORD;
764 }
765 else if (IsRegister(Token->Value))
766 {
767 Token->Type = REGISTER;
768 }
769 else if (IsVariableType(Token->Value))
770 {
771 Token->Type = SCRIPT_VARIABLE_TYPE;
772 }
773 else
774 {
775 BOOLEAN WasFound = FALSE;
776 BOOLEAN HasBang = strstr(Token->Value, "!") != 0;
777 UINT64 Address = 0;
778
779 if (HasBang)
780 {
781 Address = ScriptEngineConvertNameToAddress(Token->Value, &WasFound);
782 }
783
784 if (WasFound)
785 {
786 RemoveToken(&Token);
787 char str[20] = {0};
788 sprintf(str, "%llx", Address);
789 Token = NewToken(HEX, str);
790 }
791 else
792 {
793 if (HasBang)
794 {
795 Token->Type = UNKNOWN;
796 return Token;
797 }
798 else
799 {
801 {
802 Token->Type = FUNCTION_ID;
803 }
804 else if (GetFunctionParameterIdentifier(Token) != -1)
805 {
807 }
808 else if (GetLocalIdentifierVal(Token) != -1)
809 {
810 Token->Type = LOCAL_ID;
812 }
813 else
814 {
815 Token->Type = LOCAL_UNRESOLVED_ID;
816 }
817 }
818 }
819 }
820 return Token;
821 }
822 else
823 {
824 if (IsKeyword(Token->Value))
825 {
826 Token->Type = KEYWORD;
827 }
828 else if (IsRegister(Token->Value))
829 {
830 Token->Type = REGISTER;
831 }
832 else if (IsVariableType(Token->Value))
833 {
834 Token->Type = SCRIPT_VARIABLE_TYPE;
835 }
836 else if (IsId(Token->Value))
837 {
838 BOOLEAN WasFound = FALSE;
839 BOOLEAN HasBang = strstr(Token->Value, "!") != 0;
840 UINT64 Address = 0;
841
842 if (HasBang)
843 {
844 Address = ScriptEngineConvertNameToAddress(Token->Value, &WasFound);
845 }
846
847 if (WasFound)
848 {
849 RemoveToken(&Token);
850 char HexStr[20] = {0};
851 sprintf(HexStr, "%llx", Address);
852 Token = NewToken(HEX, HexStr);
853 }
854 else
855 {
856 if (HasBang)
857 {
858 Token->Type = UNKNOWN;
859 return Token;
860 }
861 else
862 {
864 {
865 Token->Type = FUNCTION_ID;
866 }
867 else if (GetFunctionParameterIdentifier(Token) != -1)
868 {
870 }
871 else if (GetLocalIdentifierVal(Token) != -1)
872 {
873 Token->Type = LOCAL_ID;
875 }
876 else
877 {
878 Token->Type = LOCAL_UNRESOLVED_ID;
879 }
880 Token->VariableType;
881 }
882 }
883 }
884 else
885 {
886 Token->Type = HEX;
887 }
888 return Token;
889 }
890 }
891 else if ((*c >= 'G' && *c <= 'Z') || (*c >= 'g' && *c <= 'z') || (*c == '_') || (*c == '!'))
892 {
893 do
894 {
895 if (*c != '`')
896 AppendByte(Token, *c);
897 *c = sgetc(str);
898 } while (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'));
899 if (IsKeyword(Token->Value))
900 {
901 Token->Type = KEYWORD;
902 }
903 else if (IsRegister(Token->Value))
904 {
905 Token->Type = REGISTER;
906 }
907 else if (IsVariableType(Token->Value))
908 {
909 Token->Type = SCRIPT_VARIABLE_TYPE;
910 }
911 else
912 {
913 BOOLEAN WasFound = FALSE;
914 BOOLEAN HasBang = strstr(Token->Value, "!") != 0;
915 UINT64 Address = 0;
916
917 if (HasBang)
918 {
919 Address = ScriptEngineConvertNameToAddress(Token->Value, &WasFound);
920 }
921
922 if (WasFound)
923 {
924 RemoveToken(&Token);
925 char HexStr[20] = {0};
926 sprintf(HexStr, "%llx", Address);
927 Token = NewToken(HEX, HexStr);
928 }
929 else
930 {
931 if (HasBang)
932 {
933 Token->Type = UNKNOWN;
934 return Token;
935 }
936 else
937 {
939 {
940 Token->Type = FUNCTION_ID;
941 }
942 else if (GetFunctionParameterIdentifier(Token) != -1)
943 {
945 }
946 else if (GetLocalIdentifierVal(Token) != -1)
947 {
948 Token->Type = LOCAL_ID;
950 }
951 else
952 {
953 Token->Type = LOCAL_UNRESOLVED_ID;
954 }
955 }
956 }
957 }
958 return Token;
959 }
960
961 Token->Type = UNKNOWN;
962 *c = sgetc(str);
963 return Token;
964 }
965 return Token;
966}
UCHAR BOOLEAN
Definition BasicTypes.h:35
int INT
Definition BasicTypes.h:43
#define FALSE
Definition BasicTypes.h:113
unsigned char UINT8
Definition BasicTypes.h:52
char CHAR
Definition BasicTypes.h:33
#define INVALID
Definition ScriptEngineCommonDefinitions.h:92
IMPORT_EXPORT_HYPERDBG_SCRIPT_ENGINE UINT64 ScriptEngineConvertNameToAddress(const CHAR *FunctionOrVariableName, PBOOLEAN WasFound)
Converts name to address.
Definition script-engine.c:69
@ Num
Definition commands.h:167
unsigned int InputIdx
number of read characters from input
Definition globals.c:18
char IsVariableType(char *str)
Check if string is variable type or not.
Definition scanner.c:1107
char IsId(char *str)
Check if string is Id or not.
Definition scanner.c:1127
char IsRegister(char *str)
Check if string is register or not.
Definition scanner.c:1093
char IsKeyword(char *str)
Check whether a string is a keyword or not.
Definition scanner.c:1064
char sgetc(char *str)
Returns the next character in the input string.
Definition scanner.c:1042
char IsUnderscore(char c)
Checks whether input char is underscore (_) or not.
Definition common.c:606
char IsLetter(char c)
Checks whether input char belongs to alphabet set or not.
Definition common.c:589
void RotateLeftStringOnce(char *str)
Rotate a character array to the left by one time.
Definition common.c:1536
void RemoveToken(PSCRIPT_ENGINE_TOKEN *Token)
Removes allocated memory of a token.
Definition common.c:116
PSCRIPT_ENGINE_TOKEN NewToken(SCRIPT_ENGINE_TOKEN_TYPE Type, char *Value)
Allocates a new token with given type and value.
Definition common.c:69
char IsOctal(char c)
Checks whether input char belongs to octal digit-set or not.
Definition common.c:640
void AppendByte(PSCRIPT_ENGINE_TOKEN Token, char c)
Appends char to the token value.
Definition common.c:243
void AppendWchar(PSCRIPT_ENGINE_TOKEN Token, wchar_t c)
Appends wchar_t to the token value.
Definition common.c:285
char IsBinary(char c)
Checks whether input char belongs to binary digit-set or not.
Definition common.c:623
PSCRIPT_ENGINE_TOKEN NewUnknownToken()
Allocates a new token.
Definition common.c:20
char IsDecimal(char c)
Checks whether input char belongs to decimal digit-set or not.
Definition common.c:574
char IsHex(char c)
Checks whether input char belongs to hexadecimal digit-set or not.
Definition common.c:559
struct _SCRIPT_ENGINE_TOKEN * PSCRIPT_ENGINE_TOKEN
@ KEYWORD
Definition common.h:48
@ LOCAL_UNRESOLVED_ID
Definition common.h:39
@ SCRIPT_VARIABLE_TYPE
Definition common.h:62
@ UNKNOWN
Definition common.h:64
@ 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
PUSER_DEFINED_FUNCTION_NODE GetUserDefinedFunctionNode(PSCRIPT_ENGINE_TOKEN Token)
Definition script-engine.c:4549
VARIABLE_TYPE * GetLocalIdentifierVariableType(PSCRIPT_ENGINE_TOKEN Token)
Definition script-engine.c:4493
unsigned long long int RegisterToInt(char *str)
Converts register string to integer.
Definition script-engine.c:4112
int GetGlobalIdentifierVal(PSCRIPT_ENGINE_TOKEN Token)
Returns the integer assigned to global variable.
Definition script-engine.c:4362
int GetLocalIdentifierVal(PSCRIPT_ENGINE_TOKEN Token)
Returns the integer assigned to local variable.
Definition script-engine.c:4383
VARIABLE_TYPE * GetGlobalIdentifierVariableType(PSCRIPT_ENGINE_TOKEN Token)
Definition script-engine.c:4436
unsigned long long int PseudoRegToInt(char *str)
Converts pseudo register string to integer.
Definition script-engine.c:4213
int GetFunctionParameterIdentifier(PSCRIPT_ENGINE_TOKEN Token)
Definition script-engine.c:4528
unsigned int Len
Definition common.h:74
SCRIPT_ENGINE_TOKEN_TYPE Type
Definition common.h:72
char * Value
Definition common.h:73
VARIABLE_TYPE * VariableType
Definition common.h:76

◆ IsId()

char IsId ( char * str)

Check if string is Id or not.

Parameters
str
Returns
char
1128{
1129 // TODO: Check the str is a id or not
1130 return 0;
1131}

◆ IsKeyword()

char IsKeyword ( char * str)

Check whether a string is a keyword or not.

Parameters
str
Returns
char
1065{
1066 int n = KEYWORD_LIST_LENGTH;
1067 for (int i = 0; i < n; i++)
1068 {
1069 if (!strcmp(str, KeywordList[i]))
1070 {
1071 return 1;
1072 }
1073 }
1074 n = TERMINAL_COUNT;
1075 for (int i = 0; i < n; i++)
1076 {
1077 if (!strcmp(str, TerminalMap[i]))
1078 {
1079 return 1;
1080 }
1081 }
1082
1083 return 0;
1084}
const char * TerminalMap[TERMINAL_COUNT]
Definition parse-table.c:929
const char * KeywordList[]
Definition parse-table.c:1126
#define TERMINAL_COUNT
Definition parse-table.h:5
#define KEYWORD_LIST_LENGTH
Definition parse-table.h:9

◆ IsRegister()

char IsRegister ( char * str)

Check if string is register or not.

Parameters
str
Returns
char
1094{
1095 if (RegisterToInt(str) == INVALID)
1096 return 0;
1097 return 1;
1098}

◆ IsVariableType()

char IsVariableType ( char * str)

Check if string is variable type or not.

Parameters
str
Returns
char
1108{
1109 for (int i = 0; i < SCRIPT_VARIABLE_TYPE_LIST_LENGTH; i++)
1110 {
1111 if (!strcmp(str, ScriptVariableTypeList[i]))
1112 {
1113 return 1;
1114 }
1115 }
1116
1117 return 0;
1118}
const char * ScriptVariableTypeList[]
Definition parse-table.c:1694
#define SCRIPT_VARIABLE_TYPE_LIST_LENGTH
Definition parse-table.h:14

◆ Scan()

PSCRIPT_ENGINE_TOKEN Scan ( char * str,
char * c )

Perform scanning the script engine.

Parameters
str
c
Returns
PSCRIPT_ENGINE_TOKEN
977{
978 static BOOLEAN ReturnEndOfString;
980
981 if (InputIdx <= 1)
982 {
983 ReturnEndOfString = FALSE;
984 }
985
986 if (ReturnEndOfString)
987 {
988 Token = NewToken(END_OF_STACK, "$");
989 return Token;
990 }
991
992 if (str[InputIdx - 1] == '\0')
993 {
994 }
995 while (1)
996 {
998
999 Token = GetToken(c, str);
1000
1001 if ((int)*c == EOF)
1002 {
1003 ReturnEndOfString = TRUE;
1004 }
1005
1006 if (Token->Type == WHITE_SPACE)
1007 {
1008 if (!strcmp(Token->Value, "\n"))
1009 {
1010 CurrentLine++;
1012 }
1013 RemoveToken(&Token);
1014 if (ReturnEndOfString)
1015 {
1016 Token = NewToken(END_OF_STACK, "$");
1017 return Token;
1018 }
1019 continue;
1020 }
1021 else if (Token->Type == COMMENT)
1022 {
1023 RemoveToken(&Token);
1024 if (ReturnEndOfString)
1025 {
1026 Token = NewToken(END_OF_STACK, "$");
1027 return Token;
1028 }
1029 continue;
1030 }
1031 return Token;
1032 }
1033}
#define TRUE
Definition BasicTypes.h:114
unsigned int CurrentTokenIdx
Definition globals.c:21
unsigned int CurrentLine
number of current reading line
Definition globals.c:19
unsigned int CurrentLineIdx
Definition globals.c:20
PSCRIPT_ENGINE_TOKEN GetToken(char *c, char *str)
reads a token from the input string
Definition scanner.c:22
@ END_OF_STACK
Definition common.h:55

◆ sgetc()

char sgetc ( char * str)

Returns the next character in the input string.

Parameters
str
Returns
CHAR the next character at the current position in the string
1043{
1044 char c = str[InputIdx];
1045
1046 if (c)
1047 {
1048 InputIdx++;
1049 return c;
1050 }
1051 else
1052 {
1053 return EOF;
1054 }
1055}