9 MEM_VEC_FUNCTIONS(token, char, value)
10 MEM_VEC_FUNCTIONS(lex_file, frame_macro, frames)
12 VECTOR_MAKE(char*, lex_filenames);
14 void lexerror(lex_file *lex, const char *fmt, ...)
19 vprintmsg(LVL_ERROR, lex->name, lex->sline, "parse error", fmt, ap);
23 bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...)
26 int lvl = LVL_WARNING;
28 if (!OPTS_WARN(warntype))
35 vprintmsg(lvl, lex->name, lex->sline, "warning", fmt, ap);
45 token *tok = (token*)mem_a(sizeof(token));
48 memset(tok, 0, sizeof(*tok));
52 void token_delete(token *self)
54 if (self->next && self->next->prev == self)
55 self->next->prev = self->prev;
56 if (self->prev && self->prev->next == self)
57 self->prev->next = self->next;
58 MEM_VECTOR_CLEAR(self, value);
62 token* token_copy(const token *cp)
64 token* self = token_new();
68 self->value_alloc = cp->value_count + 1;
69 self->value_count = cp->value_count;
70 self->value = (char*)mem_a(self->value_alloc);
75 memcpy(self->value, cp->value, cp->value_count);
76 self->value[self->value_alloc-1] = 0;
80 self->ttype = cp->ttype;
81 memcpy(&self->constval, &cp->constval, sizeof(self->constval));
85 void token_delete_all(token *t)
96 token* token_copy_all(const token *cp)
101 out = cur = token_copy(cp);
107 cur->next = token_copy(cp);
109 token_delete_all(out);
112 cur->next->prev = cur;
119 static void lex_token_new(lex_file *lex)
123 token_delete(lex->tok);
124 lex->tok = token_new();
126 lex->tok.value_count = 0;
127 lex->tok.constval.t = 0;
128 lex->tok.ctx.line = lex->sline;
129 lex->tok.ctx.file = lex->name;
134 lex_file* lex_open(const char *file)
137 FILE *in = util_fopen(file, "rb");
140 lexerror(NULL, "open failed: '%s'\n", file);
144 lex = (lex_file*)mem_a(sizeof(*lex));
147 lexerror(NULL, "out of memory\n");
151 memset(lex, 0, sizeof(*lex));
154 lex->name = util_strdup(file);
155 lex->line = 1; /* we start counting at 1 */
160 lex_filenames_add(lex->name);
165 void lex_cleanup(void)
168 for (i = 0; i < lex_filenames_elements; ++i)
169 mem_d(lex_filenames_data[i]);
170 mem_d(lex_filenames_data);
173 void lex_close(lex_file *lex)
176 for (i = 0; i < lex->frames_count; ++i)
177 mem_d(lex->frames[i].name);
178 MEM_VECTOR_CLEAR(lex, frames);
181 mem_d(lex->modelname);
187 token_delete(lex->tok);
189 MEM_VECTOR_CLEAR(&(lex->tok), value);
191 /* mem_d(lex->name); collected in lex_filenames */
195 /* Get or put-back data
196 * The following to functions do NOT understand what kind of data they
198 * The are merely wrapping get/put in order to count line numbers.
200 static void lex_ungetch(lex_file *lex, int ch);
201 static int lex_try_trigraph(lex_file *lex, int old)
204 c2 = fgetc(lex->file);
206 lex_ungetch(lex, c2);
210 c3 = fgetc(lex->file);
212 case '=': return '#';
213 case '/': return '\\';
214 case '\'': return '^';
215 case '(': return '[';
216 case ')': return ']';
217 case '!': return '|';
218 case '<': return '{';
219 case '>': return '}';
220 case '-': return '~';
222 lex_ungetch(lex, c3);
223 lex_ungetch(lex, c2);
228 static int lex_try_digraph(lex_file *lex, int ch)
231 c2 = fgetc(lex->file);
232 if (ch == '<' && c2 == ':')
234 else if (ch == ':' && c2 == '>')
236 else if (ch == '<' && c2 == '%')
238 else if (ch == '%' && c2 == '>')
240 else if (ch == '%' && c2 == ':')
242 lex_ungetch(lex, c2);
246 static int lex_getch(lex_file *lex)
252 if (lex->peek[lex->peekpos] == '\n')
254 return lex->peek[lex->peekpos];
257 ch = fgetc(lex->file);
261 return lex_try_trigraph(lex, ch);
262 else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
263 return lex_try_digraph(lex, ch);
267 static void lex_ungetch(lex_file *lex, int ch)
269 lex->peek[lex->peekpos++] = ch;
274 /* classify characters
275 * some additions to the is*() functions of ctype.h
278 /* Idents are alphanumberic, but they start with alpha or _ */
279 static bool isident_start(int ch)
281 return isalpha(ch) || ch == '_';
284 static bool isident(int ch)
286 return isident_start(ch) || isdigit(ch);
289 /* isxdigit_only is used when we already know it's not a digit
290 * and want to see if it's a hex digit anyway.
292 static bool isxdigit_only(int ch)
294 return (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
297 /* Append a character to the token buffer */
298 static bool GMQCC_WARN lex_tokench(lex_file *lex, int ch)
300 if (!token_value_add(&lex->tok, ch)) {
301 lexerror(lex, "out of memory");
307 /* Append a trailing null-byte */
308 static bool GMQCC_WARN lex_endtoken(lex_file *lex)
310 if (!token_value_add(&lex->tok, 0)) {
311 lexerror(lex, "out of memory");
314 lex->tok.value_count--;
318 /* Skip whitespace and comments and return the first
319 * non-white character.
320 * As this makes use of the above getch() ungetch() functions,
321 * we don't need to care at all about line numbering anymore.
323 * In theory, this function should only be used at the beginning
324 * of lexing, or when we *know* the next character is part of the token.
325 * Otherwise, if the parser throws an error, the linenumber may not be
326 * the line of the error, but the line of the next token AFTER the error.
328 * This is currently only problematic when using c-like string-continuation,
329 * since comments and whitespaces are allowed between 2 such strings.
333 "A continuation of the previous string"
334 // This line is skipped
337 * In this case, if the parse decides it didn't actually want a string,
338 * and uses lex->line to print an error, it will show the ', foo);' line's
341 * On the other hand, the parser is supposed to remember the line of the next
342 * token's beginning. In this case we would want skipwhite() to be called
343 * AFTER reading a token, so that the parser, before reading the NEXT token,
344 * doesn't store teh *comment's* linenumber, but the actual token's linenumber.
347 * here is to store the line of the first character after skipping
348 * the initial whitespace in lex->sline, this happens in lex_do.
350 static int lex_skipwhite(lex_file *lex)
353 bool haswhite = false;
358 while (ch != EOF && isspace(ch)) {
359 if (lex->flags.preprocessing) {
362 /* see if there was whitespace first */
363 if (haswhite) { /* (lex->tok.value_count) { */
364 lex_ungetch(lex, ch);
365 if (!lex_endtoken(lex))
369 /* otherwise return EOL */
373 if (!lex_tokench(lex, ch))
383 /* one line comment */
386 if (lex->flags.preprocessing) {
388 if (!lex_tokench(lex, '/') ||
389 !lex_tokench(lex, '/'))
395 while (ch != EOF && ch != '\n') {
396 if (lex->flags.preprocessing && !lex_tokench(lex, ch))
400 if (lex->flags.preprocessing) {
401 lex_ungetch(lex, '\n');
402 if (!lex_endtoken(lex))
410 /* multiline comment */
411 if (lex->flags.preprocessing) {
413 if (!lex_tokench(lex, '/') ||
414 !lex_tokench(lex, '*'))
426 if (lex->flags.preprocessing) {
427 if (!lex_tokench(lex, '*') ||
428 !lex_tokench(lex, '/'))
436 if (lex->flags.preprocessing) {
437 if (!lex_tokench(lex, ch))
441 ch = ' '; /* cause TRUE in the isspace check */
444 /* Otherwise roll back to the slash and break out of the loop */
445 lex_ungetch(lex, ch);
449 } while (ch != EOF && isspace(ch));
452 if (!lex_endtoken(lex))
454 lex_ungetch(lex, ch);
461 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
466 while (ch != EOF && isident(ch))
468 if (!lex_tokench(lex, ch))
469 return (lex->tok.ttype = TOKEN_FATAL);
473 /* last ch was not an ident ch: */
474 lex_ungetch(lex, ch);
479 /* read one ident for the frame list */
480 static int lex_parse_frame(lex_file *lex)
487 while (ch != EOF && ch != '\n' && isspace(ch))
493 if (!isident_start(ch)) {
494 lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
498 if (!lex_tokench(lex, ch))
500 if (!lex_finish_ident(lex))
502 if (!lex_endtoken(lex))
507 /* read a list of $frames */
508 static bool lex_finish_frames(lex_file *lex)
515 rc = lex_parse_frame(lex);
516 if (rc > 0) /* end of line */
518 if (rc < 0) /* error */
521 for (i = 0; i < lex->frames_count; ++i) {
522 if (!strcmp(lex->tok.value, lex->frames[i].name)) {
523 lex->frames[i].value = lex->framevalue++;
524 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
529 if (i < lex->frames_count)
532 m.value = lex->framevalue++;
533 m.name = lex->tok.value;
534 lex->tok.value = NULL;
535 lex->tok.value_alloc = lex->tok.value_count = 0;
536 if (!lex_file_frames_add(lex, m)) {
537 lexerror(lex, "out of memory");
543 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
551 return TOKEN_STRINGCONST;
553 if (!lex->flags.preprocessing && ch == '\\') {
556 lexerror(lex, "unexpected end of file");
557 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
558 return (lex->tok.ttype = TOKEN_ERROR);
563 case 'a': ch = '\a'; break;
564 case 'b': ch = '\b'; break;
565 case 'r': ch = '\r'; break;
566 case 'n': ch = '\n'; break;
567 case 't': ch = '\t'; break;
568 case 'f': ch = '\f'; break;
569 case 'v': ch = '\v'; break;
571 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
572 /* so we just add the character plus backslash no matter what it actually is */
573 if (!lex_tokench(lex, '\\'))
574 return (lex->tok.ttype = TOKEN_FATAL);
576 /* add the character finally */
577 if (!lex_tokench(lex, ch))
578 return (lex->tok.ttype = TOKEN_FATAL);
580 else if (!lex_tokench(lex, ch))
581 return (lex->tok.ttype = TOKEN_FATAL);
583 lexerror(lex, "unexpected end of file within string constant");
584 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
585 return (lex->tok.ttype = TOKEN_ERROR);
588 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
594 /* parse a number... */
595 lex->tok.ttype = TOKEN_INTCONST;
597 if (!lex_tokench(lex, ch))
598 return (lex->tok.ttype = TOKEN_FATAL);
601 if (ch != '.' && !isdigit(ch))
603 if (lastch != '0' || ch != 'x')
605 /* end of the number or EOF */
606 lex_ungetch(lex, ch);
607 if (!lex_endtoken(lex))
608 return (lex->tok.ttype = TOKEN_FATAL);
610 lex->tok.constval.i = lastch - '0';
611 return lex->tok.ttype;
617 /* EOF would have been caught above */
621 if (!lex_tokench(lex, ch))
622 return (lex->tok.ttype = TOKEN_FATAL);
624 while (isdigit(ch) || (ishex && isxdigit_only(ch)))
626 if (!lex_tokench(lex, ch))
627 return (lex->tok.ttype = TOKEN_FATAL);
631 /* NOT else, '.' can come from above as well */
632 if (ch == '.' && !ishex)
634 /* Allow floating comma in non-hex mode */
635 lex->tok.ttype = TOKEN_FLOATCONST;
636 if (!lex_tokench(lex, ch))
637 return (lex->tok.ttype = TOKEN_FATAL);
639 /* continue digits-only */
643 if (!lex_tokench(lex, ch))
644 return (lex->tok.ttype = TOKEN_FATAL);
648 /* put back the last character */
649 /* but do not put back the trailing 'f' or a float */
650 if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
653 /* generally we don't want words to follow numbers: */
655 lexerror(lex, "unexpected trailing characters after number");
656 return (lex->tok.ttype = TOKEN_ERROR);
658 lex_ungetch(lex, ch);
660 if (!lex_endtoken(lex))
661 return (lex->tok.ttype = TOKEN_FATAL);
662 if (lex->tok.ttype == TOKEN_FLOATCONST)
663 lex->tok.constval.f = strtod(lex->tok.value, NULL);
665 lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
666 return lex->tok.ttype;
669 int lex_do(lex_file *lex)
679 ch = lex_skipwhite(lex);
680 lex->sline = lex->line;
681 lex->tok.ctx.line = lex->sline;
682 lex->tok.ctx.file = lex->name;
684 if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
685 return (lex->tok.ttype = ch);
689 return (lex->tok.ttype = TOKEN_FATAL);
693 return (lex->tok.ttype = TOKEN_EOF);
696 /* modelgen / spiritgen commands */
702 if (!isident_start(ch)) {
703 lexerror(lex, "hanging '$' modelgen/spritegen command line");
706 if (!lex_tokench(lex, ch))
707 return (lex->tok.ttype = TOKEN_FATAL);
708 if (!lex_finish_ident(lex))
709 return (lex->tok.ttype = TOKEN_ERROR);
710 if (!lex_endtoken(lex))
711 return (lex->tok.ttype = TOKEN_FATAL);
712 /* skip the known commands */
715 if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
717 /* frame/framesave command works like an enum
718 * similar to fteqcc we handle this in the lexer.
719 * The reason for this is that it is sensitive to newlines,
720 * which the parser is unaware of
722 if (!lex_finish_frames(lex))
723 return (lex->tok.ttype = TOKEN_ERROR);
727 if (!strcmp(v, "framevalue"))
730 while (ch != EOF && isspace(ch) && ch != '\n')
734 lexerror(lex, "$framevalue requires an integer parameter");
739 lex->tok.ttype = lex_finish_digit(lex, ch);
740 if (!lex_endtoken(lex))
741 return (lex->tok.ttype = TOKEN_FATAL);
742 if (lex->tok.ttype != TOKEN_INTCONST) {
743 lexerror(lex, "$framevalue requires an integer parameter");
746 lex->framevalue = lex->tok.constval.i;
750 if (!strcmp(v, "framerestore"))
756 rc = lex_parse_frame(lex);
759 lexerror(lex, "$framerestore requires a framename parameter");
763 return (lex->tok.ttype = TOKEN_FATAL);
766 for (frame = 0; frame < lex->frames_count; ++frame) {
767 if (!strcmp(v, lex->frames[frame].name)) {
768 lex->framevalue = lex->frames[frame].value;
772 lexerror(lex, "unknown framename `%s`", v);
776 if (!strcmp(v, "modelname"))
782 rc = lex_parse_frame(lex);
785 lexerror(lex, "$framerestore requires a framename parameter");
789 return (lex->tok.ttype = TOKEN_FATAL);
792 if (lex->modelname) {
794 m.value = lex->framevalue;
795 m.name = lex->modelname;
796 lex->modelname = NULL;
797 if (!lex_file_frames_add(lex, m)) {
798 lexerror(lex, "out of memory");
799 return (lex->tok.ttype = TOKEN_FATAL);
802 lex->modelname = lex->tok.value;
803 lex->tok.value = NULL;
804 lex->tok.value_alloc = lex->tok.value_count = 0;
805 for (frame = 0; frame < lex->frames_count; ++frame) {
806 if (!strcmp(v, lex->frames[frame].name)) {
807 lex->framevalue = lex->frames[frame].value;
814 if (!strcmp(v, "flush"))
817 for (frame = 0; frame < lex->frames_count; ++frame)
818 mem_d(lex->frames[frame].name);
819 MEM_VECTOR_CLEAR(lex, frames);
820 /* skip line (fteqcc does it too) */
822 while (ch != EOF && ch != '\n')
827 if (!strcmp(v, "cd") ||
828 !strcmp(v, "origin") ||
829 !strcmp(v, "base") ||
830 !strcmp(v, "flags") ||
831 !strcmp(v, "scale") ||
836 while (ch != EOF && ch != '\n')
841 for (frame = 0; frame < lex->frames_count; ++frame) {
842 if (!strcmp(v, lex->frames[frame].name)) {
843 lex->tok.constval.i = lex->frames[frame].value;
844 return (lex->tok.ttype = TOKEN_INTCONST);
848 lexerror(lex, "invalid frame macro");
852 /* single-character tokens */
857 if (!lex_tokench(lex, ch) ||
860 return (lex->tok.ttype = TOKEN_FATAL);
862 if (lex->flags.noops)
863 return (lex->tok.ttype = ch);
865 return (lex->tok.ttype = TOKEN_OPERATOR);
873 if (!lex_tokench(lex, ch) ||
876 return (lex->tok.ttype = TOKEN_FATAL);
878 return (lex->tok.ttype = ch);
883 if (lex->flags.noops)
885 /* Detect characters early which are normally
886 * operators OR PART of an operator.
903 if (!lex_tokench(lex, ch) ||
906 return (lex->tok.ttype = TOKEN_FATAL);
908 return (lex->tok.ttype = ch);
915 if (!lex_tokench(lex, ch))
916 return (lex->tok.ttype = TOKEN_FATAL);
917 /* peak ahead once */
918 nextch = lex_getch(lex);
920 lex_ungetch(lex, nextch);
921 if (!lex_endtoken(lex))
922 return (lex->tok.ttype = TOKEN_FATAL);
923 return (lex->tok.ttype = ch);
925 /* peak ahead again */
926 nextch = lex_getch(lex);
928 lex_ungetch(lex, nextch);
929 lex_ungetch(lex, nextch);
930 if (!lex_endtoken(lex))
931 return (lex->tok.ttype = TOKEN_FATAL);
932 return (lex->tok.ttype = ch);
934 /* fill the token to be "..." */
935 if (!lex_tokench(lex, ch) ||
936 !lex_tokench(lex, ch) ||
939 return (lex->tok.ttype = TOKEN_FATAL);
941 return (lex->tok.ttype = TOKEN_DOTS);
945 if (ch == ',' || ch == '.') {
946 if (!lex_tokench(lex, ch) ||
949 return (lex->tok.ttype = TOKEN_FATAL);
951 return (lex->tok.ttype = TOKEN_OPERATOR);
954 if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */
955 ch == '>' || ch == '<' || /* <<, >>, <=, >= */
956 ch == '=' || ch == '!' || /* ==, != */
957 ch == '&' || ch == '|') /* &&, ||, &=, |= */
959 if (!lex_tokench(lex, ch))
960 return (lex->tok.ttype = TOKEN_FATAL);
962 nextch = lex_getch(lex);
963 if (nextch == ch || nextch == '=') {
964 if (!lex_tokench(lex, nextch))
965 return (lex->tok.ttype = TOKEN_FATAL);
966 } else if (ch == '-' && nextch == '>') {
967 if (!lex_tokench(lex, nextch))
968 return (lex->tok.ttype = TOKEN_FATAL);
970 lex_ungetch(lex, nextch);
972 if (!lex_endtoken(lex))
973 return (lex->tok.ttype = TOKEN_FATAL);
974 return (lex->tok.ttype = TOKEN_OPERATOR);
978 if (ch == '^' || ch == '~' || ch == '!')
980 if (!lex_tokench(lex, ch) ||
983 return (lex->tok.ttype = TOKEN_FATAL);
985 return (lex->tok.ttype = TOKEN_OPERATOR);
989 if (ch == '*' || ch == '/') /* *=, /= */
991 if (!lex_tokench(lex, ch))
992 return (lex->tok.ttype = TOKEN_FATAL);
994 nextch = lex_getch(lex);
996 if (!lex_tokench(lex, nextch))
997 return (lex->tok.ttype = TOKEN_FATAL);
999 lex_ungetch(lex, nextch);
1001 if (!lex_endtoken(lex))
1002 return (lex->tok.ttype = TOKEN_FATAL);
1003 return (lex->tok.ttype = TOKEN_OPERATOR);
1006 if (isident_start(ch))
1010 if (!lex_tokench(lex, ch))
1011 return (lex->tok.ttype = TOKEN_FATAL);
1012 if (!lex_finish_ident(lex)) {
1014 return (lex->tok.ttype = TOKEN_ERROR);
1016 if (!lex_endtoken(lex))
1017 return (lex->tok.ttype = TOKEN_FATAL);
1018 lex->tok.ttype = TOKEN_IDENT;
1021 if (!strcmp(v, "void")) {
1022 lex->tok.ttype = TOKEN_TYPENAME;
1023 lex->tok.constval.t = TYPE_VOID;
1024 } else if (!strcmp(v, "int")) {
1025 lex->tok.ttype = TOKEN_TYPENAME;
1026 lex->tok.constval.t = TYPE_INTEGER;
1027 } else if (!strcmp(v, "float")) {
1028 lex->tok.ttype = TOKEN_TYPENAME;
1029 lex->tok.constval.t = TYPE_FLOAT;
1030 } else if (!strcmp(v, "string")) {
1031 lex->tok.ttype = TOKEN_TYPENAME;
1032 lex->tok.constval.t = TYPE_STRING;
1033 } else if (!strcmp(v, "entity")) {
1034 lex->tok.ttype = TOKEN_TYPENAME;
1035 lex->tok.constval.t = TYPE_ENTITY;
1036 } else if (!strcmp(v, "vector")) {
1037 lex->tok.ttype = TOKEN_TYPENAME;
1038 lex->tok.constval.t = TYPE_VECTOR;
1039 } else if (!strcmp(v, "for") ||
1040 !strcmp(v, "while") ||
1043 !strcmp(v, "else") ||
1044 !strcmp(v, "local") ||
1045 !strcmp(v, "return") ||
1046 !strcmp(v, "not") ||
1047 !strcmp(v, "const"))
1049 lex->tok.ttype = TOKEN_KEYWORD;
1051 else if (opts_standard != COMPILER_QCC)
1053 /* other standards reserve these keywords */
1054 if (!strcmp(v, "switch") ||
1055 !strcmp(v, "struct") ||
1056 !strcmp(v, "union") ||
1057 !strcmp(v, "break") ||
1058 !strcmp(v, "continue") ||
1061 lex->tok.ttype = TOKEN_KEYWORD;
1065 return lex->tok.ttype;
1070 lex->flags.nodigraphs = true;
1071 if (lex->flags.preprocessing && !lex_tokench(lex, ch))
1073 lex->tok.ttype = lex_finish_string(lex, '"');
1074 if (lex->flags.preprocessing && !lex_tokench(lex, ch))
1076 while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
1078 /* Allow c style "string" "continuation" */
1079 ch = lex_skipwhite(lex);
1081 lex_ungetch(lex, ch);
1085 lex->tok.ttype = lex_finish_string(lex, '"');
1087 lex->flags.nodigraphs = false;
1088 if (!lex_endtoken(lex))
1089 return (lex->tok.ttype = TOKEN_FATAL);
1090 return lex->tok.ttype;
1095 /* we parse character constants like string,
1096 * but return TOKEN_CHARCONST, or a vector type if it fits...
1097 * Likewise actual unescaping has to be done by the parser.
1098 * The difference is we don't allow 'char' 'continuation'.
1100 if (lex->flags.preprocessing && !lex_tokench(lex, ch))
1102 lex->tok.ttype = lex_finish_string(lex, '\'');
1103 if (lex->flags.preprocessing && !lex_tokench(lex, ch))
1105 if (!lex_endtoken(lex))
1106 return (lex->tok.ttype = TOKEN_FATAL);
1108 /* It's a vector if we can successfully scan 3 floats */
1110 if (sscanf_s(lex->tok.value, " %f %f %f ",
1111 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1113 if (sscanf(lex->tok.value, " %f %f %f ",
1114 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1118 lex->tok.ttype = TOKEN_VECTORCONST;
1121 return lex->tok.ttype;
1126 lex->tok.ttype = lex_finish_digit(lex, ch);
1127 if (!lex_endtoken(lex))
1128 return (lex->tok.ttype = TOKEN_FATAL);
1129 return lex->tok.ttype;
1132 lexerror(lex, "unknown token");
1133 return (lex->tok.ttype = TOKEN_ERROR);