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

Go to the source code of this file.

Macros

#define SCANNER_H
 

Functions

PTOKEN GetToken (char *c, char *str)
 reads a token from the input string
 
PTOKEN Scan (char *str, char *c)
 Perform scanning the script engine.
 
char sgetc (char *str)
 returns last character of string
 
char IsKeyword (char *str)
 Check whether a string is a keyword or not.
 
char IsId (char *str)
 eck if string is Id or not
 
char IsRegister (char *str)
 Check if string is register or not.
 

Variables

PTOKEN_LIST IdTable
 lookup table for storing Ids
 
PTOKEN_LIST FunctionParameterIdTable
 
unsigned int InputIdx
 number of read characters from input
 
unsigned int CurrentLine
 number of current reading line
 
unsigned int CurrentLineIdx
 
unsigned int CurrentTokenIdx
 

Detailed Description

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

Scanner headers

Version
0.1
Date
2020-10-22

Macro Definition Documentation

◆ SCANNER_H

#define SCANNER_H

Function Documentation

◆ GetToken()

PTOKEN GetToken ( char * c,
char * str )

reads a token from the input string

Parameters
c
str
Returns
PTOKEN
23{
24 PTOKEN Token = NewUnknownToken();
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 strcpy(Token->Value, ">>");
175 Token->Type = SPECIAL_TOKEN;
176 *c = sgetc(str);
177 return Token;
178 }
179 else if (*c == '=')
180 {
181 strcpy(Token->Value, ">=");
182 Token->Type = SPECIAL_TOKEN;
183 *c = sgetc(str);
184 return Token;
185 }
186 else
187 {
188 strcpy(Token->Value, ">");
189 Token->Type = SPECIAL_TOKEN;
190 return Token;
191 }
192 case '<':
193 *c = sgetc(str);
194 if (*c == '<')
195 {
196 strcpy(Token->Value, "<<");
197 Token->Type = SPECIAL_TOKEN;
198 *c = sgetc(str);
199 return Token;
200 }
201 else if (*c == '=')
202 {
203 strcpy(Token->Value, "<=");
204 Token->Type = SPECIAL_TOKEN;
205 *c = sgetc(str);
206 return Token;
207 }
208 else
209 {
210 strcpy(Token->Value, "<");
211 Token->Type = SPECIAL_TOKEN;
212 return Token;
213 }
214 case '/':
215 *c = sgetc(str);
216 if (*c == '=')
217 {
218 strcpy(Token->Value, "/=");
219 Token->Type = SPECIAL_TOKEN;
220 *c = sgetc(str);
221
222 return Token;
223 }
224 else if (*c == '/')
225 {
226 do
227 {
228 *c = sgetc(str);
229 } while (*c != '\n' && (int)*c != EOF);
230
231 Token->Type = COMMENT;
232 *c = sgetc(str);
233 return Token;
234 }
235 else if (*c == '*')
236 {
237 do
238 {
239 *c = sgetc(str);
240 if (*c == '*')
241 {
242 *c = sgetc(str);
243 if (*c == '/')
244 {
245 Token->Type = COMMENT;
246 *c = sgetc(str);
247 return Token;
248 }
249 }
250 if ((int)*c == EOF)
251 break;
252 } while (1);
253
254 Token->Type = UNKNOWN;
255 *c = sgetc(str);
256 return Token;
257 }
258 else
259 {
260 strcpy(Token->Value, "/");
261 Token->Type = SPECIAL_TOKEN;
262 return Token;
263 }
264
265 case '=':
266 *c = sgetc(str);
267 if (*c == '=')
268 {
269 strcpy(Token->Value, "==");
270 Token->Type = SPECIAL_TOKEN;
271 *c = sgetc(str);
272 return Token;
273 }
274 else
275 {
276 strcpy(Token->Value, "=");
277 Token->Type = SPECIAL_TOKEN;
278 return Token;
279 }
280 case '!':
281 *c = sgetc(str);
282 if (*c == '=')
283 {
284 strcpy(Token->Value, "!=");
285 Token->Type = SPECIAL_TOKEN;
286 *c = sgetc(str);
287 return Token;
288 }
289 else
290 {
291 strcpy(Token->Value, "!");
292 Token->Type = UNKNOWN;
293 return Token;
294 }
295 case '%':
296 strcpy(Token->Value, "%");
297 Token->Type = SPECIAL_TOKEN;
298 *c = sgetc(str);
299 return Token;
300
301 case ',':
302 strcpy(Token->Value, ",");
303 Token->Type = SPECIAL_TOKEN;
304 *c = sgetc(str);
305 return Token;
306
307 case ';':
308 strcpy(Token->Value, ";");
309 Token->Type = SPECIAL_TOKEN;
310 *c = sgetc(str);
311 return Token;
312
313 case ':':
314 strcpy(Token->Value, ":");
315 Token->Type = SPECIAL_TOKEN;
316 *c = sgetc(str);
317 return Token;
318
319 case '(':
320 strcpy(Token->Value, "(");
321 Token->Type = SPECIAL_TOKEN;
322 *c = sgetc(str);
323 return Token;
324 case ')':
325 strcpy(Token->Value, ")");
326 Token->Type = SPECIAL_TOKEN;
327 *c = sgetc(str);
328 return Token;
329 case '{':
330 strcpy(Token->Value, "{");
331 Token->Type = SPECIAL_TOKEN;
332 *c = sgetc(str);
333 return Token;
334 case '}':
335 strcpy(Token->Value, "}");
336 Token->Type = SPECIAL_TOKEN;
337 *c = sgetc(str);
338 return Token;
339 case '|':
340 *c = sgetc(str);
341 if (*c == '|')
342 {
343 strcpy(Token->Value, "||");
344 Token->Type = SPECIAL_TOKEN;
345 *c = sgetc(str);
346 return Token;
347 }
348 else
349 {
350 strcpy(Token->Value, "|");
351 Token->Type = SPECIAL_TOKEN;
352 return Token;
353 }
354 case '&':
355 *c = sgetc(str);
356 if (*c == '&')
357 {
358 strcpy(Token->Value, "&&");
359 Token->Type = SPECIAL_TOKEN;
360 *c = sgetc(str);
361 return Token;
362 }
363 else
364 {
365 strcpy(Token->Value, "&");
366 Token->Type = SPECIAL_TOKEN;
367 return Token;
368 }
369
370 case '^':
371 strcpy(Token->Value, "^");
372 Token->Type = SPECIAL_TOKEN;
373 *c = sgetc(str);
374 return Token;
375 case '@':
376 *c = sgetc(str);
377 if (IsLetter(*c))
378 {
379 while (IsLetter(*c) || IsDecimal(*c) || IsUnderscore(*c))
380 {
381 AppendByte(Token, *c);
382 *c = sgetc(str);
383 }
384 if (RegisterToInt(Token->Value) != INVALID)
385 {
386 Token->Type = REGISTER;
387 }
388 else
389 {
390 Token->Type = UNKNOWN;
391 }
392 return Token;
393 }
394
395 case '$':
396 *c = sgetc(str);
397 if (IsLetter(*c))
398 {
399 //
400 // Append valid characters for pseudo registers' name
401 //
402 while (IsLetter(*c) || IsDecimal(*c) || *c == '_')
403 {
404 AppendByte(Token, *c);
405 *c = sgetc(str);
406 }
407 if (PseudoRegToInt(Token->Value) != INVALID)
408 {
409 Token->Type = PSEUDO_REGISTER;
410 }
411 else
412 {
413 Token->Type = UNKNOWN;
414 }
415
416 return Token;
417 }
418
419 case '.':
420 AppendByte(Token, *c);
421 *c = sgetc(str);
422 if (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'))
423 {
424 do
425 {
426 AppendByte(Token, *c);
427 *c = sgetc(str);
428 } while (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'));
429
431 BOOLEAN HasBang = strstr(Token->Value, "!") != 0;
432 UINT64 Address = 0;
433
434 if (HasBang)
435 {
437 }
438
439 if (WasFound)
440 {
441 RemoveToken(&Token);
442 char str[20] = {0};
443 sprintf(str, "%llx", Address);
444 Token = NewToken(HEX, str);
445 }
446 else
447 {
448 if (HasBang)
449 {
450 Token->Type = UNKNOWN;
451 return Token;
452 }
453 else
454 {
455 if (GetGlobalIdentifierVal(Token) != -1)
456 {
457 Token->Type = GLOBAL_ID;
458 }
459 else
460 {
461 Token->Type = GLOBAL_UNRESOLVED_ID;
462 }
463 }
464 }
465 }
466 else
467 {
468 Token->Type = UNKNOWN;
469 return Token;
470 }
471 return Token;
472
473 case ' ':
474 case '\t':
475 strcpy(Token->Value, "");
476 Token->Type = WHITE_SPACE;
477 *c = sgetc(str);
478 return Token;
479 case '\n':
480 strcpy(Token->Value, "\n");
481 Token->Type = WHITE_SPACE;
482 *c = sgetc(str);
483 return Token;
484
485 case '0':
486 *c = sgetc(str);
487 if (*c == 'x')
488 {
489 *c = sgetc(str);
490 while (IsHex(*c) || *c == '`')
491 {
492 if (*c != '`')
493 AppendByte(Token, *c);
494 *c = sgetc(str);
495 }
496 Token->Type = HEX;
497 return Token;
498 }
499 else if (*c == 'o')
500 {
501 *c = sgetc(str);
502 while (IsOctal(*c) || *c == '`')
503 {
504 if (*c != '`')
505 AppendByte(Token, *c);
506 *c = sgetc(str);
507 }
508 Token->Type = OCTAL;
509 return Token;
510 }
511 else if (*c == 'n')
512 {
513 *c = sgetc(str);
514 while (IsDecimal(*c) || *c == '`')
515 {
516 if (*c != '`')
517 AppendByte(Token, *c);
518 *c = sgetc(str);
519 }
520 Token->Type = DECIMAL;
521 return Token;
522 }
523 else if (*c == 'y')
524 {
525 *c = sgetc(str);
526 while (IsBinary(*c) || *c == '`')
527 {
528 if (*c != '`')
529 AppendByte(Token, *c);
530 *c = sgetc(str);
531 }
532 Token->Type = BINARY;
533 return Token;
534 }
535
536 else if (IsHex(*c))
537 {
538 do
539 {
540 if (*c != '`')
541 AppendByte(Token, *c);
542 *c = sgetc(str);
543 } while (IsHex(*c) || *c == '`');
544 Token->Type = HEX;
545 return Token;
546 }
547 else
548 {
549 strcpy(Token->Value, "0");
550 Token->Type = HEX;
551 return Token;
552 }
553
554 case 'L':
555 if (*(str + InputIdx) == '"')
556 {
557 InputIdx++;
558 do
559 {
560 *c = sgetc(str);
561
562 if (*c == '\\')
563 {
564 *c = sgetc(str);
565 if (*c == 'n')
566 {
567 AppendWchar(Token, L'\n');
568 continue;
569 }
570 if (*c == '\\')
571 {
572 AppendWchar(Token, L'\\');
573 continue;
574 }
575 else if (*c == 't')
576 {
577 AppendWchar(Token, L'\t');
578 continue;
579 }
580 else if (*c == 'x')
581 {
582 char ByteString[] = "00000";
583 int len = (int)strlen(ByteString);
584 int i = 0;
585 for (; i < len; i++)
586 {
587 *c = sgetc(str);
588 if (!IsHex(*c))
589 break;
590
591 RotateLeftStringOnce(ByteString);
592 ByteString[len - 1] = *c;
593 }
594
595 if (i == 0 || i == 5)
596 {
597 Token->Type = UNKNOWN;
598 *c = sgetc(str);
599 return Token;
600 }
601 else
602 {
603 InputIdx--;
604 wchar_t num = (wchar_t)strtol(ByteString, NULL, 16);
605 AppendWchar(Token, num);
606 }
607 }
608 else if (*c == '"')
609 {
610 AppendWchar(Token, L'"');
611 continue;
612 }
613 else
614 {
615 Token->Type = UNKNOWN;
616 *c = sgetc(str);
617 return Token;
618 }
619 }
620 else if (*c == '"')
621 {
622 break;
623 }
624 else
625 {
626 AppendWchar(Token, (wchar_t)*c);
627 }
628 } while (1);
629
630 Token->Len += 2;
631 Token->Type = WSTRING;
632 *c = sgetc(str);
633 return Token;
634 }
635
636 default:
637 if (*c >= '0' && *c <= '9')
638 {
639 do
640 {
641 if (*c != '`')
642 AppendByte(Token, *c);
643 *c = sgetc(str);
644 } while (IsHex(*c) || *c == '`');
645 Token->Type = HEX;
646 return Token;
647 }
648 else if ((*c >= 'a' && *c <= 'f') || (*c >= 'A' && *c <= 'F') || (*c == '_') || (*c == '!'))
649 {
650 uint8_t NotHex = 0;
651 do
652 {
653 if (*c != '`')
654 AppendByte(Token, *c);
655
656 *c = sgetc(str);
657 if (IsHex(*c) || *c == '`')
658 {
659 // Nothing
660 }
661 else if ((*c >= 'G' && *c <= 'Z') || (*c >= 'g' && *c <= 'z'))
662 {
663 NotHex = 1;
664 break;
665 }
666 else
667 {
668 break;
669 }
670 } while (1);
671 if (NotHex)
672 {
673 do
674 {
675 if (*c != '`')
676 AppendByte(Token, *c);
677 *c = sgetc(str);
678 } while (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'));
679 if (IsKeyword(Token->Value))
680 {
681 Token->Type = KEYWORD;
682 }
683 else if (IsRegister(Token->Value))
684 {
685 Token->Type = REGISTER;
686 }
687 else
688 {
690 BOOLEAN HasBang = strstr(Token->Value, "!") != 0;
691 UINT64 Address = 0;
692
693 if (HasBang)
694 {
696 }
697
698 if (WasFound)
699 {
700 RemoveToken(&Token);
701 char str[20] = {0};
702 sprintf(str, "%llx", Address);
703 Token = NewToken(HEX, str);
704 }
705 else
706 {
707 if (HasBang)
708 {
709 Token->Type = UNKNOWN;
710 return Token;
711 }
712 else
713 {
714 if (GetFunctionParameterIdentifier(Token) != -1)
715 {
717 }
718 else
719 {
720 if (GetLocalIdentifierVal(Token) != -1)
721 {
722 Token->Type = LOCAL_ID;
723 }
724 else
725 {
726 Token->Type = LOCAL_UNRESOLVED_ID;
727 }
728 }
729 }
730 }
731 }
732 return Token;
733 }
734 else
735 {
736 if (IsKeyword(Token->Value))
737 {
738 Token->Type = KEYWORD;
739 }
740 else if (IsRegister(Token->Value))
741 {
742 Token->Type = REGISTER;
743 }
744 else if (IsId(Token->Value))
745 {
747 BOOLEAN HasBang = strstr(Token->Value, "!") != 0;
748 UINT64 Address = 0;
749
750 if (HasBang)
751 {
753 }
754
755 if (WasFound)
756 {
757 RemoveToken(&Token);
758 char str[20] = {0};
759 sprintf(str, "%llx", Address);
760 Token = NewToken(HEX, str);
761 }
762 else
763 {
764 if (HasBang)
765 {
766 Token->Type = UNKNOWN;
767 return Token;
768 }
769 else
770 {
771 if (GetFunctionParameterIdentifier(Token) != -1)
772 {
774 }
775 else
776 {
777 if (GetLocalIdentifierVal(Token) != -1)
778 {
779 Token->Type = LOCAL_ID;
780 }
781 else
782 {
783 Token->Type = LOCAL_UNRESOLVED_ID;
784 }
785 }
786 }
787 }
788 }
789 else
790 {
791 Token->Type = HEX;
792 }
793 return Token;
794 }
795 }
796 else if ((*c >= 'G' && *c <= 'Z') || (*c >= 'g' && *c <= 'z') || (*c == '_') || (*c == '!'))
797 {
798 do
799 {
800 if (*c != '`')
801 AppendByte(Token, *c);
802 *c = sgetc(str);
803 } while (IsLetter(*c) || IsHex(*c) || (*c == '_') || (*c == '!'));
804 if (IsKeyword(Token->Value))
805 {
806 Token->Type = KEYWORD;
807 }
808 else if (IsRegister(Token->Value))
809 {
810 Token->Type = REGISTER;
811 }
812 else
813 {
815 BOOLEAN HasBang = strstr(Token->Value, "!") != 0;
816 UINT64 Address = 0;
817
818 if (HasBang)
819 {
821 }
822
823 if (WasFound)
824 {
825 RemoveToken(&Token);
826 char str[20] = {0};
827 sprintf(str, "%llx", Address);
828 Token = NewToken(HEX, str);
829 }
830 else
831 {
832 if (HasBang)
833 {
834 Token->Type = UNKNOWN;
835 return Token;
836 }
837 else
838 {
839 if (GetFunctionParameterIdentifier(Token) != -1)
840 {
842 }
843 else
844 {
845 if (GetLocalIdentifierVal(Token) != -1)
846 {
847 Token->Type = LOCAL_ID;
848 }
849 else
850 {
851 Token->Type = LOCAL_UNRESOLVED_ID;
852 }
853 }
854 }
855 }
856 }
857 return Token;
858 }
859
860 Token->Type = UNKNOWN;
861 *c = sgetc(str);
862 return Token;
863 }
864 return Token;
865}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
UINT64 Address
Definition HyperDbgScriptImports.h:67
PBOOLEAN WasFound
Definition HyperDbgScriptImports.h:45
#define INVALID
Definition ScriptEngineCommonDefinitions.h:96
char IsId(char *str)
eck if string is Id or not
Definition scanner.c:1006
char IsRegister(char *str)
Check if string is register or not.
Definition scanner.c:992
char IsKeyword(char *str)
Check whether a string is a keyword or not.
Definition scanner.c:963
char sgetc(char *str)
returns last character of string
Definition scanner.c:941
unsigned int InputIdx
number of read characters from input
Definition scanner.h:30
char IsUnderscore(char c)
Checks whether input char is underscore (_) or not.
Definition common.c:572
char IsLetter(char c)
Checks whether input char belongs to alphabet set or not.
Definition common.c:555
void AppendWchar(PTOKEN Token, wchar_t c)
Appends wchar_t to the token value.
Definition common.c:272
void RotateLeftStringOnce(char *str)
Rotate a character array to the left by one time.
Definition common.c:1524
void AppendByte(PTOKEN Token, char c)
Appends char to the token value.
Definition common.c:231
char IsOctal(char c)
Checks whether input char belongs to octal digit-set or not.
Definition common.c:606
void RemoveToken(PTOKEN *Token)
Removes allocated memory of a token.
Definition common.c:104
PTOKEN NewUnknownToken()
Allocates a new token.
Definition common.c:20
char IsBinary(char c)
Checks whether input char belongs to binary digit-set or not.
Definition common.c:589
PTOKEN NewToken(TOKEN_TYPE Type, char *Value)
Definition common.c:60
char IsDecimal(char c)
Checks whether input char belongs to decimal digit-set or not.
Definition common.c:540
char IsHex(char c)
Checks whether input char belongs to hexadecimal digit-set or not.
Definition common.c:525
@ KEYWORD
Definition common.h:48
@ LOCAL_UNRESOLVED_ID
Definition common.h:39
@ UNKNOWN
Definition common.h:65
@ 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
@ OCTAL
Definition common.h:45
@ HEX
Definition common.h:44
@ GLOBAL_ID
Definition common.h:40
@ FUNCTION_PARAMETER_ID
Definition common.h:63
@ BINARY
Definition common.h:46
@ STRING
Definition common.h:58
@ DECIMAL
Definition common.h:42
int GetFunctionParameterIdentifier(PTOKEN Token)
Definition script-engine.c:3222
UINT64 ScriptEngineConvertNameToAddress(const char *FunctionOrVariableName, PBOOLEAN WasFound)
Converts name to address.
Definition script-engine.c:33
unsigned long long int RegisterToInt(char *str)
Converts register string to integer.
Definition script-engine.c:2888
int GetGlobalIdentifierVal(PTOKEN Token)
Returns the integer assigned to global variable.
Definition script-engine.c:3138
int GetLocalIdentifierVal(PTOKEN Token)
Returns the integer assigned to local variable.
Definition script-engine.c:3159
unsigned long long int PseudoRegToInt(char *str)
Converts pseudo register string to integer.
Definition script-engine.c:2989
read tokens from input stored in this structure
Definition common.h:72
unsigned int Len
Definition common.h:75
char * Value
Definition common.h:74
TOKEN_TYPE Type
Definition common.h:73

◆ IsId()

char IsId ( char * str)

eck if string is Id or not

Parameters
str
Returns
char
1007{
1008 // TODO: Check the str is a id or not
1009 return 0;
1010}

◆ IsKeyword()

char IsKeyword ( char * str)

Check whether a string is a keyword or not.

Parameters
str
Returns
char
964{
965 int n = KEYWORD_LIST_LENGTH;
966 for (int i = 0; i < n; i++)
967 {
968 if (!strcmp(str, KeywordList[i]))
969 {
970 return 1;
971 }
972 }
973 n = TERMINAL_COUNT;
974 for (int i = 0; i < n; i++)
975 {
976 if (!strcmp(str, TerminalMap[i]))
977 {
978 return 1;
979 }
980 }
981
982 return 0;
983}
const char * TerminalMap[TERMINAL_COUNT]
Definition parse-table.c:681
const char * KeywordList[]
Definition parse-table.c:839
#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
993{
994 if (RegisterToInt(str) == INVALID)
995 return 0;
996 return 1;
997}

◆ Scan()

PTOKEN Scan ( char * str,
char * c )

Perform scanning the script engine.

Parameters
str
c
Returns
PTOKEN
876{
877 static BOOLEAN ReturnEndOfString;
878 PTOKEN Token;
879
880 if (InputIdx <= 1)
881 {
882 ReturnEndOfString = FALSE;
883 }
884
885 if (ReturnEndOfString)
886 {
887 Token = NewToken(END_OF_STACK, "$");
888 return Token;
889 }
890
891 if (str[InputIdx - 1] == '\0')
892 {
893 }
894 while (1)
895 {
897
898 Token = GetToken(c, str);
899
900 if ((int)*c == EOF)
901 {
902 ReturnEndOfString = TRUE;
903 }
904
905 if (Token->Type == WHITE_SPACE)
906 {
907 if (!strcmp(Token->Value, "\n"))
908 {
909 CurrentLine++;
911 }
912 RemoveToken(&Token);
913 if (ReturnEndOfString)
914 {
915 Token = NewToken(END_OF_STACK, "$");
916 return Token;
917 }
918 continue;
919 }
920 else if (Token->Type == COMMENT)
921 {
922 RemoveToken(&Token);
923 if (ReturnEndOfString)
924 {
925 Token = NewToken(END_OF_STACK, "$");
926 return Token;
927 }
928 continue;
929 }
930 return Token;
931 }
932}
#define TRUE
Definition BasicTypes.h:55
PTOKEN GetToken(char *c, char *str)
reads a token from the input string
Definition scanner.c:22
unsigned int CurrentTokenIdx
Definition scanner.h:45
unsigned int CurrentLine
number of current reading line
Definition scanner.h:35
unsigned int CurrentLineIdx
Definition scanner.h:40
@ END_OF_STACK
Definition common.h:55

◆ sgetc()

char sgetc ( char * str)

returns last character of string

Parameters
str
Returns
last character
942{
943 char c = str[InputIdx];
944
945 if (c)
946 {
947 InputIdx++;
948 return c;
949 }
950 else
951 {
952 return EOF;
953 }
954}

Variable Documentation

◆ CurrentLine

unsigned int CurrentLine

number of current reading line

◆ CurrentLineIdx

unsigned int CurrentLineIdx

◆ CurrentTokenIdx

unsigned int CurrentTokenIdx

◆ FunctionParameterIdTable

PTOKEN_LIST FunctionParameterIdTable

◆ IdTable

PTOKEN_LIST IdTable

lookup table for storing Ids

◆ InputIdx

unsigned int InputIdx

number of read characters from input