14 static const char *keywords_qc[] = {
21 static size_t num_keywords_qc = sizeof(keywords_qc) / sizeof(keywords_qc[0]);
24 static const char *keywords_fg[] = {
26 "switch", "case", "default",
30 static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]);
38 void lexerror(lex_file *lex, const char *fmt, ...)
44 con_vprintmsg(LVL_ERROR, lex->name, lex->sline, "parse error", fmt, ap);
46 con_vprintmsg(LVL_ERROR, "", 0, "parse error", fmt, ap);
50 bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...)
53 int lvl = LVL_WARNING;
55 if (!OPTS_WARN(warntype))
62 con_vprintmsg(lvl, lex->name, lex->sline, "warning", fmt, ap);
72 token *tok = (token*)mem_a(sizeof(token));
75 memset(tok, 0, sizeof(*tok));
79 void token_delete(token *self)
81 if (self->next && self->next->prev == self)
82 self->next->prev = self->prev;
83 if (self->prev && self->prev->next == self)
84 self->prev->next = self->next;
85 MEM_VECTOR_CLEAR(self, value);
89 token* token_copy(const token *cp)
91 token* self = token_new();
95 self->value_alloc = cp->value_count + 1;
96 self->value_count = cp->value_count;
97 self->value = (char*)mem_a(self->value_alloc);
102 memcpy(self->value, cp->value, cp->value_count);
103 self->value[self->value_alloc-1] = 0;
107 self->ttype = cp->ttype;
108 memcpy(&self->constval, &cp->constval, sizeof(self->constval));
112 void token_delete_all(token *t)
123 token* token_copy_all(const token *cp)
128 out = cur = token_copy(cp);
134 cur->next = token_copy(cp);
136 token_delete_all(out);
139 cur->next->prev = cur;
146 static void lex_token_new(lex_file *lex)
150 token_delete(lex->tok);
151 lex->tok = token_new();
154 vec_shrinkto(lex->tok.value, 0);
155 lex->tok.constval.t = 0;
156 lex->tok.ctx.line = lex->sline;
157 lex->tok.ctx.file = lex->name;
162 lex_file* lex_open(const char *file)
165 FILE *in = util_fopen(file, "rb");
168 lexerror(NULL, "open failed: '%s'\n", file);
172 lex = (lex_file*)mem_a(sizeof(*lex));
175 lexerror(NULL, "out of memory\n");
179 memset(lex, 0, sizeof(*lex));
182 lex->name = util_strdup(file);
183 lex->line = 1; /* we start counting at 1 */
188 vec_push(lex_filenames, lex->name);
192 lex_file* lex_open_string(const char *str, size_t len, const char *name)
196 lex = (lex_file*)mem_a(sizeof(*lex));
198 lexerror(NULL, "out of memory\n");
202 memset(lex, 0, sizeof(*lex));
205 lex->open_string = str;
206 lex->open_string_length = len;
207 lex->open_string_pos = 0;
209 lex->name = util_strdup(name ? name : "<string-source>");
210 lex->line = 1; /* we start counting at 1 */
215 vec_push(lex_filenames, lex->name);
220 void lex_cleanup(void)
223 for (i = 0; i < vec_size(lex_filenames); ++i)
224 mem_d(lex_filenames[i]);
225 vec_free(lex_filenames);
228 void lex_close(lex_file *lex)
231 for (i = 0; i < vec_size(lex->frames); ++i)
232 mem_d(lex->frames[i].name);
233 vec_free(lex->frames);
236 vec_free(lex->modelname);
242 token_delete(lex->tok);
244 vec_free(lex->tok.value);
246 /* mem_d(lex->name); collected in lex_filenames */
250 static int lex_fgetc(lex_file *lex)
253 return fgetc(lex->file);
254 if (lex->open_string) {
255 if (lex->open_string_pos >= lex->open_string_length)
257 return lex->open_string[lex->open_string_pos++];
262 /* Get or put-back data
263 * The following to functions do NOT understand what kind of data they
265 * The are merely wrapping get/put in order to count line numbers.
267 static void lex_ungetch(lex_file *lex, int ch);
268 static int lex_try_trigraph(lex_file *lex, int old)
273 lex_ungetch(lex, c2);
279 case '=': return '#';
280 case '/': return '\\';
281 case '\'': return '^';
282 case '(': return '[';
283 case ')': return ']';
284 case '!': return '|';
285 case '<': return '{';
286 case '>': return '}';
287 case '-': return '~';
289 lex_ungetch(lex, c3);
290 lex_ungetch(lex, c2);
295 static int lex_try_digraph(lex_file *lex, int ch)
299 if (ch == '<' && c2 == ':')
301 else if (ch == ':' && c2 == '>')
303 else if (ch == '<' && c2 == '%')
305 else if (ch == '%' && c2 == '>')
307 else if (ch == '%' && c2 == ':')
309 lex_ungetch(lex, c2);
313 static int lex_getch(lex_file *lex)
319 if (!lex->push_line && lex->peek[lex->peekpos] == '\n')
321 return lex->peek[lex->peekpos];
325 if (!lex->push_line && ch == '\n')
328 return lex_try_trigraph(lex, ch);
329 else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
330 return lex_try_digraph(lex, ch);
334 static void lex_ungetch(lex_file *lex, int ch)
336 lex->peek[lex->peekpos++] = ch;
337 if (!lex->push_line && ch == '\n')
341 /* classify characters
342 * some additions to the is*() functions of ctype.h
345 /* Idents are alphanumberic, but they start with alpha or _ */
346 static bool isident_start(int ch)
348 return isalpha(ch) || ch == '_';
351 static bool isident(int ch)
353 return isident_start(ch) || isdigit(ch);
356 /* isxdigit_only is used when we already know it's not a digit
357 * and want to see if it's a hex digit anyway.
359 static bool isxdigit_only(int ch)
361 return (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
364 /* Append a character to the token buffer */
365 static void lex_tokench(lex_file *lex, int ch)
367 vec_push(lex->tok.value, ch);
370 /* Append a trailing null-byte */
371 static void lex_endtoken(lex_file *lex)
373 vec_push(lex->tok.value, 0);
374 vec_shrinkby(lex->tok.value, 1);
377 static bool lex_try_pragma(lex_file *lex)
381 char *command = NULL;
385 if (lex->flags.preprocessing)
392 lex_ungetch(lex, ch);
396 for (ch = lex_getch(lex); vec_size(pragma) < 8 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
397 vec_push(pragma, ch);
400 if (ch != ' ' || strcmp(pragma, "pragma")) {
401 lex_ungetch(lex, ch);
405 for (ch = lex_getch(lex); vec_size(command) < 32 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
406 vec_push(command, ch);
407 vec_push(command, 0);
410 lex_ungetch(lex, ch);
414 for (ch = lex_getch(lex); vec_size(param) < 32 && ch != ')' && ch != '\n'; ch = lex_getch(lex))
419 lex_ungetch(lex, ch);
423 if (!strcmp(command, "push")) {
424 if (!strcmp(param, "line")) {
431 else if (!strcmp(command, "pop")) {
432 if (!strcmp(param, "line")) {
440 else if (!strcmp(command, "file")) {
441 lex->name = util_strdup(param);
442 vec_push(lex_filenames, lex->name);
444 else if (!strcmp(command, "line")) {
445 line = strtol(param, NULL, 0)-1;
451 while (ch != '\n' && ch != EOF)
458 while (vec_size(command)) {
459 lex_ungetch(lex, vec_last(command));
466 while (vec_size(command)) {
467 lex_ungetch(lex, vec_last(command));
474 while (vec_size(pragma)) {
475 lex_ungetch(lex, vec_last(pragma));
480 lex_ungetch(lex, '#');
486 /* Skip whitespace and comments and return the first
487 * non-white character.
488 * As this makes use of the above getch() ungetch() functions,
489 * we don't need to care at all about line numbering anymore.
491 * In theory, this function should only be used at the beginning
492 * of lexing, or when we *know* the next character is part of the token.
493 * Otherwise, if the parser throws an error, the linenumber may not be
494 * the line of the error, but the line of the next token AFTER the error.
496 * This is currently only problematic when using c-like string-continuation,
497 * since comments and whitespaces are allowed between 2 such strings.
501 "A continuation of the previous string"
502 // This line is skipped
505 * In this case, if the parse decides it didn't actually want a string,
506 * and uses lex->line to print an error, it will show the ', foo);' line's
509 * On the other hand, the parser is supposed to remember the line of the next
510 * token's beginning. In this case we would want skipwhite() to be called
511 * AFTER reading a token, so that the parser, before reading the NEXT token,
512 * doesn't store teh *comment's* linenumber, but the actual token's linenumber.
515 * here is to store the line of the first character after skipping
516 * the initial whitespace in lex->sline, this happens in lex_do.
518 static int lex_skipwhite(lex_file *lex)
521 bool haswhite = false;
526 while (ch != EOF && isspace(ch)) {
528 if (lex_try_pragma(lex))
531 if (lex->flags.preprocessing) {
534 /* see if there was whitespace first */
535 if (haswhite) { /* (vec_size(lex->tok.value)) { */
536 lex_ungetch(lex, ch);
540 /* otherwise return EOL */
544 lex_tokench(lex, ch);
553 /* one line comment */
556 if (lex->flags.preprocessing) {
559 lex_tokench(lex, '/');
560 lex_tokench(lex, '/');
562 lex_tokench(lex, ' ');
563 lex_tokench(lex, ' ');
566 while (ch != EOF && ch != '\n') {
567 if (lex->flags.preprocessing)
568 lex_tokench(lex, ' '); /* ch); */
571 if (lex->flags.preprocessing) {
572 lex_ungetch(lex, '\n');
580 /* multiline comment */
581 if (lex->flags.preprocessing) {
584 lex_tokench(lex, '/');
585 lex_tokench(lex, '*');
587 lex_tokench(lex, ' ');
588 lex_tokench(lex, ' ');
597 if (lex->flags.preprocessing) {
599 lex_tokench(lex, '*');
600 lex_tokench(lex, '/');
602 lex_tokench(lex, ' ');
603 lex_tokench(lex, ' ');
607 lex_ungetch(lex, ch);
609 if (lex->flags.preprocessing) {
610 lex_tokench(lex, ' '); /* ch); */
613 ch = ' '; /* cause TRUE in the isspace check */
616 /* Otherwise roll back to the slash and break out of the loop */
617 lex_ungetch(lex, ch);
621 } while (ch != EOF && isspace(ch));
625 lex_ungetch(lex, ch);
632 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
637 while (ch != EOF && isident(ch))
639 lex_tokench(lex, ch);
643 /* last ch was not an ident ch: */
644 lex_ungetch(lex, ch);
649 /* read one ident for the frame list */
650 static int lex_parse_frame(lex_file *lex)
657 while (ch != EOF && ch != '\n' && isspace(ch))
663 if (!isident_start(ch)) {
664 lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
668 lex_tokench(lex, ch);
669 if (!lex_finish_ident(lex))
675 /* read a list of $frames */
676 static bool lex_finish_frames(lex_file *lex)
683 rc = lex_parse_frame(lex);
684 if (rc > 0) /* end of line */
686 if (rc < 0) /* error */
689 for (i = 0; i < vec_size(lex->frames); ++i) {
690 if (!strcmp(lex->tok.value, lex->frames[i].name)) {
691 lex->frames[i].value = lex->framevalue++;
692 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
697 if (i < vec_size(lex->frames))
700 m.value = lex->framevalue++;
701 m.name = util_strdup(lex->tok.value);
702 vec_shrinkto(lex->tok.value, 0);
703 vec_push(lex->frames, m);
707 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
715 return TOKEN_STRINGCONST;
717 if (lex->flags.preprocessing && ch == '\\') {
718 lex_tokench(lex, ch);
721 lexerror(lex, "unexpected end of file");
722 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
723 return (lex->tok.ttype = TOKEN_ERROR);
725 lex_tokench(lex, ch);
727 else if (ch == '\\') {
730 lexerror(lex, "unexpected end of file");
731 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
732 return (lex->tok.ttype = TOKEN_ERROR);
739 case 'a': ch = '\a'; break;
740 case 'b': ch = '\b'; break;
741 case 'r': ch = '\r'; break;
742 case 'n': ch = '\n'; break;
743 case 't': ch = '\t'; break;
744 case 'f': ch = '\f'; break;
745 case 'v': ch = '\v'; break;
747 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
748 /* so we just add the character plus backslash no matter what it actually is */
749 lex_tokench(lex, '\\');
751 /* add the character finally */
752 lex_tokench(lex, ch);
755 lex_tokench(lex, ch);
757 lexerror(lex, "unexpected end of file within string constant");
758 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
759 return (lex->tok.ttype = TOKEN_ERROR);
762 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
768 /* parse a number... */
769 lex->tok.ttype = TOKEN_INTCONST;
771 lex_tokench(lex, ch);
774 if (ch != '.' && !isdigit(ch))
776 if (lastch != '0' || ch != 'x')
778 /* end of the number or EOF */
779 lex_ungetch(lex, ch);
782 lex->tok.constval.i = lastch - '0';
783 return lex->tok.ttype;
789 /* EOF would have been caught above */
793 lex_tokench(lex, ch);
795 while (isdigit(ch) || (ishex && isxdigit_only(ch)))
797 lex_tokench(lex, ch);
801 /* NOT else, '.' can come from above as well */
802 if (ch == '.' && !ishex)
804 /* Allow floating comma in non-hex mode */
805 lex->tok.ttype = TOKEN_FLOATCONST;
806 lex_tokench(lex, ch);
808 /* continue digits-only */
812 lex_tokench(lex, ch);
816 /* put back the last character */
817 /* but do not put back the trailing 'f' or a float */
818 if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
821 /* generally we don't want words to follow numbers: */
823 lexerror(lex, "unexpected trailing characters after number");
824 return (lex->tok.ttype = TOKEN_ERROR);
826 lex_ungetch(lex, ch);
829 if (lex->tok.ttype == TOKEN_FLOATCONST)
830 lex->tok.constval.f = strtod(lex->tok.value, NULL);
832 lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
833 return lex->tok.ttype;
836 int lex_do(lex_file *lex)
838 int ch, nextch, thirdch;
847 ch = lex_skipwhite(lex);
848 if (!lex->flags.mergelines || ch != '\\')
852 lex_ungetch(lex, ch);
856 /* we reached a linemerge */
857 lex_tokench(lex, '\n');
861 lex->sline = lex->line;
862 lex->tok.ctx.line = lex->sline;
863 lex->tok.ctx.file = lex->name;
865 if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
866 return (lex->tok.ttype = ch);
870 return (lex->tok.ttype = TOKEN_FATAL);
874 return (lex->tok.ttype = TOKEN_EOF);
877 /* modelgen / spiritgen commands */
883 if (!isident_start(ch)) {
884 lexerror(lex, "hanging '$' modelgen/spritegen command line");
887 lex_tokench(lex, ch);
888 if (!lex_finish_ident(lex))
889 return (lex->tok.ttype = TOKEN_ERROR);
891 /* skip the known commands */
894 if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
896 /* frame/framesave command works like an enum
897 * similar to fteqcc we handle this in the lexer.
898 * The reason for this is that it is sensitive to newlines,
899 * which the parser is unaware of
901 if (!lex_finish_frames(lex))
902 return (lex->tok.ttype = TOKEN_ERROR);
906 if (!strcmp(v, "framevalue"))
909 while (ch != EOF && isspace(ch) && ch != '\n')
913 lexerror(lex, "$framevalue requires an integer parameter");
918 lex->tok.ttype = lex_finish_digit(lex, ch);
920 if (lex->tok.ttype != TOKEN_INTCONST) {
921 lexerror(lex, "$framevalue requires an integer parameter");
924 lex->framevalue = lex->tok.constval.i;
928 if (!strcmp(v, "framerestore"))
934 rc = lex_parse_frame(lex);
937 lexerror(lex, "$framerestore requires a framename parameter");
941 return (lex->tok.ttype = TOKEN_FATAL);
944 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
945 if (!strcmp(v, lex->frames[frame].name)) {
946 lex->framevalue = lex->frames[frame].value;
950 lexerror(lex, "unknown framename `%s`", v);
954 if (!strcmp(v, "modelname"))
960 rc = lex_parse_frame(lex);
963 lexerror(lex, "$modelname requires a parameter");
967 return (lex->tok.ttype = TOKEN_FATAL);
970 if (lex->modelname) {
972 m.value = lex->framevalue;
973 m.name = lex->modelname;
974 lex->modelname = NULL;
975 vec_push(lex->frames, m);
977 lex->modelname = lex->tok.value;
978 lex->tok.value = NULL;
982 if (!strcmp(v, "flush"))
985 for (fi = 0; fi < vec_size(lex->frames); ++fi)
986 mem_d(lex->frames[fi].name);
987 vec_free(lex->frames);
988 /* skip line (fteqcc does it too) */
990 while (ch != EOF && ch != '\n')
995 if (!strcmp(v, "cd") ||
996 !strcmp(v, "origin") ||
997 !strcmp(v, "base") ||
998 !strcmp(v, "flags") ||
999 !strcmp(v, "scale") ||
1003 ch = lex_getch(lex);
1004 while (ch != EOF && ch != '\n')
1005 ch = lex_getch(lex);
1009 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
1010 if (!strcmp(v, lex->frames[frame].name)) {
1011 lex->tok.constval.i = lex->frames[frame].value;
1012 return (lex->tok.ttype = TOKEN_INTCONST);
1016 lexerror(lex, "invalid frame macro");
1020 /* single-character tokens */
1027 lex_tokench(lex, ch);
1029 if (lex->flags.noops)
1030 return (lex->tok.ttype = ch);
1032 return (lex->tok.ttype = TOKEN_OPERATOR);
1040 lex_tokench(lex, ch);
1042 return (lex->tok.ttype = ch);
1047 if (lex->flags.noops)
1049 /* Detect characters early which are normally
1050 * operators OR PART of an operator.
1067 lex_tokench(lex, ch);
1069 return (lex->tok.ttype = ch);
1076 lex_tokench(lex, ch);
1077 /* peak ahead once */
1078 nextch = lex_getch(lex);
1079 if (nextch != '.') {
1080 lex_ungetch(lex, nextch);
1082 return (lex->tok.ttype = ch);
1084 /* peak ahead again */
1085 nextch = lex_getch(lex);
1086 if (nextch != '.') {
1087 lex_ungetch(lex, nextch);
1088 lex_ungetch(lex, nextch);
1090 return (lex->tok.ttype = ch);
1092 /* fill the token to be "..." */
1093 lex_tokench(lex, ch);
1094 lex_tokench(lex, ch);
1096 return (lex->tok.ttype = TOKEN_DOTS);
1100 if (ch == ',' || ch == '.') {
1101 lex_tokench(lex, ch);
1103 return (lex->tok.ttype = TOKEN_OPERATOR);
1106 if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */
1107 ch == '>' || ch == '<' || /* <<, >>, <=, >= */
1108 ch == '=' || ch == '!' || /* ==, != */
1109 ch == '&' || ch == '|') /* &&, ||, &=, |= */
1111 lex_tokench(lex, ch);
1113 nextch = lex_getch(lex);
1114 if (nextch == ch || nextch == '=') {
1115 lex_tokench(lex, nextch);
1116 } else if (ch == '-' && nextch == '>') {
1117 lex_tokench(lex, nextch);
1118 } else if (ch == '&' && nextch == '~') {
1119 thirdch = lex_getch(lex);
1120 if (thirdch != '=') {
1121 lex_ungetch(lex, thirdch);
1122 lex_ungetch(lex, nextch);
1125 lex_tokench(lex, nextch);
1126 lex_tokench(lex, thirdch);
1129 lex_ungetch(lex, nextch);
1132 return (lex->tok.ttype = TOKEN_OPERATOR);
1136 if (ch == '^' || ch == '~' || ch == '!')
1138 lex_tokench(lex, ch);
1140 return (lex->tok.ttype = TOKEN_OPERATOR);
1144 if (ch == '*' || ch == '/') /* *=, /= */
1146 lex_tokench(lex, ch);
1148 nextch = lex_getch(lex);
1149 if (nextch == '=') {
1150 lex_tokench(lex, nextch);
1152 lex_ungetch(lex, nextch);
1155 return (lex->tok.ttype = TOKEN_OPERATOR);
1158 if (isident_start(ch))
1162 lex_tokench(lex, ch);
1163 if (!lex_finish_ident(lex)) {
1165 return (lex->tok.ttype = TOKEN_ERROR);
1168 lex->tok.ttype = TOKEN_IDENT;
1171 if (!strcmp(v, "void")) {
1172 lex->tok.ttype = TOKEN_TYPENAME;
1173 lex->tok.constval.t = TYPE_VOID;
1174 } else if (!strcmp(v, "int")) {
1175 lex->tok.ttype = TOKEN_TYPENAME;
1176 lex->tok.constval.t = TYPE_INTEGER;
1177 } else if (!strcmp(v, "float")) {
1178 lex->tok.ttype = TOKEN_TYPENAME;
1179 lex->tok.constval.t = TYPE_FLOAT;
1180 } else if (!strcmp(v, "string")) {
1181 lex->tok.ttype = TOKEN_TYPENAME;
1182 lex->tok.constval.t = TYPE_STRING;
1183 } else if (!strcmp(v, "entity")) {
1184 lex->tok.ttype = TOKEN_TYPENAME;
1185 lex->tok.constval.t = TYPE_ENTITY;
1186 } else if (!strcmp(v, "vector")) {
1187 lex->tok.ttype = TOKEN_TYPENAME;
1188 lex->tok.constval.t = TYPE_VECTOR;
1191 for (kw = 0; kw < num_keywords_qc; ++kw) {
1192 if (!strcmp(v, keywords_qc[kw]))
1193 return (lex->tok.ttype = TOKEN_KEYWORD);
1195 if (opts_standard != COMPILER_QCC) {
1196 for (kw = 0; kw < num_keywords_fg; ++kw) {
1197 if (!strcmp(v, keywords_fg[kw]))
1198 return (lex->tok.ttype = TOKEN_KEYWORD);
1203 return lex->tok.ttype;
1208 lex->flags.nodigraphs = true;
1209 if (lex->flags.preprocessing)
1210 lex_tokench(lex, ch);
1211 lex->tok.ttype = lex_finish_string(lex, '"');
1212 if (lex->flags.preprocessing)
1213 lex_tokench(lex, ch);
1214 while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
1216 /* Allow c style "string" "continuation" */
1217 ch = lex_skipwhite(lex);
1219 lex_ungetch(lex, ch);
1223 lex->tok.ttype = lex_finish_string(lex, '"');
1225 lex->flags.nodigraphs = false;
1227 return lex->tok.ttype;
1232 /* we parse character constants like string,
1233 * but return TOKEN_CHARCONST, or a vector type if it fits...
1234 * Likewise actual unescaping has to be done by the parser.
1235 * The difference is we don't allow 'char' 'continuation'.
1237 if (lex->flags.preprocessing)
1238 lex_tokench(lex, ch);
1239 lex->tok.ttype = lex_finish_string(lex, '\'');
1240 if (lex->flags.preprocessing)
1241 lex_tokench(lex, ch);
1244 /* It's a vector if we can successfully scan 3 floats */
1246 if (sscanf_s(lex->tok.value, " %f %f %f ",
1247 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1249 if (sscanf(lex->tok.value, " %f %f %f ",
1250 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1254 lex->tok.ttype = TOKEN_VECTORCONST;
1257 return lex->tok.ttype;
1262 lex->tok.ttype = lex_finish_digit(lex, ch);
1264 return lex->tok.ttype;
1267 lexerror(lex, "unknown token");
1268 return (lex->tok.ttype = TOKEN_ERROR);