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[] = {
25 "switch", "case", "default",
29 static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]);
37 void lexerror(lex_file *lex, const char *fmt, ...)
43 con_vprintmsg(LVL_ERROR, lex->name, lex->sline, "parse error", fmt, ap);
45 con_vprintmsg(LVL_ERROR, "", 0, "parse error", fmt, ap);
49 bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...)
52 int lvl = LVL_WARNING;
54 if (!OPTS_WARN(warntype))
61 con_vprintmsg(lvl, lex->name, lex->sline, "warning", fmt, ap);
71 token *tok = (token*)mem_a(sizeof(token));
74 memset(tok, 0, sizeof(*tok));
78 void token_delete(token *self)
80 if (self->next && self->next->prev == self)
81 self->next->prev = self->prev;
82 if (self->prev && self->prev->next == self)
83 self->prev->next = self->next;
84 MEM_VECTOR_CLEAR(self, value);
88 token* token_copy(const token *cp)
90 token* self = token_new();
94 self->value_alloc = cp->value_count + 1;
95 self->value_count = cp->value_count;
96 self->value = (char*)mem_a(self->value_alloc);
101 memcpy(self->value, cp->value, cp->value_count);
102 self->value[self->value_alloc-1] = 0;
106 self->ttype = cp->ttype;
107 memcpy(&self->constval, &cp->constval, sizeof(self->constval));
111 void token_delete_all(token *t)
122 token* token_copy_all(const token *cp)
127 out = cur = token_copy(cp);
133 cur->next = token_copy(cp);
135 token_delete_all(out);
138 cur->next->prev = cur;
145 static void lex_token_new(lex_file *lex)
149 token_delete(lex->tok);
150 lex->tok = token_new();
153 vec_shrinkto(lex->tok.value, 0);
154 lex->tok.constval.t = 0;
155 lex->tok.ctx.line = lex->sline;
156 lex->tok.ctx.file = lex->name;
161 lex_file* lex_open(const char *file)
164 FILE *in = util_fopen(file, "rb");
167 lexerror(NULL, "open failed: '%s'\n", file);
171 lex = (lex_file*)mem_a(sizeof(*lex));
174 lexerror(NULL, "out of memory\n");
178 memset(lex, 0, sizeof(*lex));
181 lex->name = util_strdup(file);
182 lex->line = 1; /* we start counting at 1 */
187 vec_push(lex_filenames, lex->name);
191 lex_file* lex_open_string(const char *str, size_t len, const char *name)
195 lex = (lex_file*)mem_a(sizeof(*lex));
197 lexerror(NULL, "out of memory\n");
201 memset(lex, 0, sizeof(*lex));
204 lex->open_string = str;
205 lex->open_string_length = len;
206 lex->open_string_pos = 0;
208 lex->name = util_strdup(name ? name : "<string-source>");
209 lex->line = 1; /* we start counting at 1 */
214 vec_push(lex_filenames, lex->name);
219 void lex_cleanup(void)
222 for (i = 0; i < vec_size(lex_filenames); ++i)
223 mem_d(lex_filenames[i]);
224 vec_free(lex_filenames);
227 void lex_close(lex_file *lex)
230 for (i = 0; i < vec_size(lex->frames); ++i)
231 mem_d(lex->frames[i].name);
232 vec_free(lex->frames);
235 vec_free(lex->modelname);
241 token_delete(lex->tok);
243 vec_free(lex->tok.value);
245 /* mem_d(lex->name); collected in lex_filenames */
249 static int lex_fgetc(lex_file *lex)
252 return fgetc(lex->file);
253 if (lex->open_string) {
254 if (lex->open_string_pos >= lex->open_string_length)
256 return lex->open_string[lex->open_string_pos++];
261 /* Get or put-back data
262 * The following to functions do NOT understand what kind of data they
264 * The are merely wrapping get/put in order to count line numbers.
266 static void lex_ungetch(lex_file *lex, int ch);
267 static int lex_try_trigraph(lex_file *lex, int old)
272 lex_ungetch(lex, c2);
278 case '=': return '#';
279 case '/': return '\\';
280 case '\'': return '^';
281 case '(': return '[';
282 case ')': return ']';
283 case '!': return '|';
284 case '<': return '{';
285 case '>': return '}';
286 case '-': return '~';
288 lex_ungetch(lex, c3);
289 lex_ungetch(lex, c2);
294 static int lex_try_digraph(lex_file *lex, int ch)
298 if (ch == '<' && c2 == ':')
300 else if (ch == ':' && c2 == '>')
302 else if (ch == '<' && c2 == '%')
304 else if (ch == '%' && c2 == '>')
306 else if (ch == '%' && c2 == ':')
308 lex_ungetch(lex, c2);
312 static int lex_getch(lex_file *lex)
318 if (!lex->push_line && lex->peek[lex->peekpos] == '\n')
320 return lex->peek[lex->peekpos];
324 if (!lex->push_line && ch == '\n')
327 return lex_try_trigraph(lex, ch);
328 else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
329 return lex_try_digraph(lex, ch);
333 static void lex_ungetch(lex_file *lex, int ch)
335 lex->peek[lex->peekpos++] = ch;
336 if (!lex->push_line && ch == '\n')
340 /* classify characters
341 * some additions to the is*() functions of ctype.h
344 /* Idents are alphanumberic, but they start with alpha or _ */
345 static bool isident_start(int ch)
347 return isalpha(ch) || ch == '_';
350 static bool isident(int ch)
352 return isident_start(ch) || isdigit(ch);
355 /* isxdigit_only is used when we already know it's not a digit
356 * and want to see if it's a hex digit anyway.
358 static bool isxdigit_only(int ch)
360 return (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
363 /* Append a character to the token buffer */
364 static void lex_tokench(lex_file *lex, int ch)
366 vec_push(lex->tok.value, ch);
369 /* Append a trailing null-byte */
370 static void lex_endtoken(lex_file *lex)
372 vec_push(lex->tok.value, 0);
373 vec_shrinkby(lex->tok.value, 1);
376 static bool lex_try_pragma(lex_file *lex)
380 char *command = NULL;
384 if (lex->flags.preprocessing)
391 lex_ungetch(lex, ch);
395 for (ch = lex_getch(lex); vec_size(pragma) < 8 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
396 vec_push(pragma, ch);
399 if (ch != ' ' || strcmp(pragma, "pragma")) {
400 lex_ungetch(lex, ch);
404 for (ch = lex_getch(lex); vec_size(command) < 32 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
405 vec_push(command, ch);
406 vec_push(command, 0);
409 lex_ungetch(lex, ch);
413 for (ch = lex_getch(lex); vec_size(param) < 32 && ch != ')' && ch != '\n'; ch = lex_getch(lex))
418 lex_ungetch(lex, ch);
422 if (!strcmp(command, "push")) {
423 if (!strcmp(param, "line")) {
430 else if (!strcmp(command, "pop")) {
431 if (!strcmp(param, "line")) {
439 else if (!strcmp(command, "file")) {
440 lex->name = util_strdup(param);
441 vec_push(lex_filenames, lex->name);
443 else if (!strcmp(command, "line")) {
444 line = strtol(param, NULL, 0)-1;
450 while (ch != '\n' && ch != EOF)
457 while (vec_size(command)) {
458 lex_ungetch(lex, vec_last(command));
465 while (vec_size(command)) {
466 lex_ungetch(lex, vec_last(command));
473 while (vec_size(pragma)) {
474 lex_ungetch(lex, vec_last(pragma));
479 lex_ungetch(lex, '#');
485 /* Skip whitespace and comments and return the first
486 * non-white character.
487 * As this makes use of the above getch() ungetch() functions,
488 * we don't need to care at all about line numbering anymore.
490 * In theory, this function should only be used at the beginning
491 * of lexing, or when we *know* the next character is part of the token.
492 * Otherwise, if the parser throws an error, the linenumber may not be
493 * the line of the error, but the line of the next token AFTER the error.
495 * This is currently only problematic when using c-like string-continuation,
496 * since comments and whitespaces are allowed between 2 such strings.
500 "A continuation of the previous string"
501 // This line is skipped
504 * In this case, if the parse decides it didn't actually want a string,
505 * and uses lex->line to print an error, it will show the ', foo);' line's
508 * On the other hand, the parser is supposed to remember the line of the next
509 * token's beginning. In this case we would want skipwhite() to be called
510 * AFTER reading a token, so that the parser, before reading the NEXT token,
511 * doesn't store teh *comment's* linenumber, but the actual token's linenumber.
514 * here is to store the line of the first character after skipping
515 * the initial whitespace in lex->sline, this happens in lex_do.
517 static int lex_skipwhite(lex_file *lex)
520 bool haswhite = false;
525 while (ch != EOF && isspace(ch)) {
527 if (lex_try_pragma(lex))
530 if (lex->flags.preprocessing) {
533 /* see if there was whitespace first */
534 if (haswhite) { /* (vec_size(lex->tok.value)) { */
535 lex_ungetch(lex, ch);
539 /* otherwise return EOL */
543 lex_tokench(lex, ch);
552 /* one line comment */
555 if (lex->flags.preprocessing) {
558 lex_tokench(lex, '/');
559 lex_tokench(lex, '/');
561 lex_tokench(lex, ' ');
562 lex_tokench(lex, ' ');
565 while (ch != EOF && ch != '\n') {
566 if (lex->flags.preprocessing)
567 lex_tokench(lex, ' '); /* ch); */
570 if (lex->flags.preprocessing) {
571 lex_ungetch(lex, '\n');
579 /* multiline comment */
580 if (lex->flags.preprocessing) {
583 lex_tokench(lex, '/');
584 lex_tokench(lex, '*');
586 lex_tokench(lex, ' ');
587 lex_tokench(lex, ' ');
596 if (lex->flags.preprocessing) {
598 lex_tokench(lex, '*');
599 lex_tokench(lex, '/');
601 lex_tokench(lex, ' ');
602 lex_tokench(lex, ' ');
606 lex_ungetch(lex, ch);
608 if (lex->flags.preprocessing) {
610 lex_tokench(lex, '\n');
612 lex_tokench(lex, ' '); /* ch); */
615 ch = ' '; /* cause TRUE in the isspace check */
618 /* Otherwise roll back to the slash and break out of the loop */
619 lex_ungetch(lex, ch);
623 } while (ch != EOF && isspace(ch));
627 lex_ungetch(lex, ch);
634 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
639 while (ch != EOF && isident(ch))
641 lex_tokench(lex, ch);
645 /* last ch was not an ident ch: */
646 lex_ungetch(lex, ch);
651 /* read one ident for the frame list */
652 static int lex_parse_frame(lex_file *lex)
659 while (ch != EOF && ch != '\n' && isspace(ch))
665 if (!isident_start(ch)) {
666 lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
670 lex_tokench(lex, ch);
671 if (!lex_finish_ident(lex))
677 /* read a list of $frames */
678 static bool lex_finish_frames(lex_file *lex)
685 rc = lex_parse_frame(lex);
686 if (rc > 0) /* end of line */
688 if (rc < 0) /* error */
691 for (i = 0; i < vec_size(lex->frames); ++i) {
692 if (!strcmp(lex->tok.value, lex->frames[i].name)) {
693 lex->frames[i].value = lex->framevalue++;
694 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
699 if (i < vec_size(lex->frames))
702 m.value = lex->framevalue++;
703 m.name = util_strdup(lex->tok.value);
704 vec_shrinkto(lex->tok.value, 0);
705 vec_push(lex->frames, m);
709 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
717 return TOKEN_STRINGCONST;
719 if (lex->flags.preprocessing && ch == '\\') {
720 lex_tokench(lex, ch);
723 lexerror(lex, "unexpected end of file");
724 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
725 return (lex->tok.ttype = TOKEN_ERROR);
727 lex_tokench(lex, ch);
729 else if (ch == '\\') {
732 lexerror(lex, "unexpected end of file");
733 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
734 return (lex->tok.ttype = TOKEN_ERROR);
741 case 'a': ch = '\a'; break;
742 case 'b': ch = '\b'; break;
743 case 'r': ch = '\r'; break;
744 case 'n': ch = '\n'; break;
745 case 't': ch = '\t'; break;
746 case 'f': ch = '\f'; break;
747 case 'v': ch = '\v'; break;
749 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
750 /* so we just add the character plus backslash no matter what it actually is */
751 lex_tokench(lex, '\\');
753 /* add the character finally */
754 lex_tokench(lex, ch);
757 lex_tokench(lex, ch);
759 lexerror(lex, "unexpected end of file within string constant");
760 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
761 return (lex->tok.ttype = TOKEN_ERROR);
764 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
770 /* parse a number... */
771 lex->tok.ttype = TOKEN_INTCONST;
773 lex_tokench(lex, ch);
776 if (ch != '.' && !isdigit(ch))
778 if (lastch != '0' || ch != 'x')
780 /* end of the number or EOF */
781 lex_ungetch(lex, ch);
784 lex->tok.constval.i = lastch - '0';
785 return lex->tok.ttype;
791 /* EOF would have been caught above */
795 lex_tokench(lex, ch);
797 while (isdigit(ch) || (ishex && isxdigit_only(ch)))
799 lex_tokench(lex, ch);
803 /* NOT else, '.' can come from above as well */
804 if (ch == '.' && !ishex)
806 /* Allow floating comma in non-hex mode */
807 lex->tok.ttype = TOKEN_FLOATCONST;
808 lex_tokench(lex, ch);
810 /* continue digits-only */
814 lex_tokench(lex, ch);
818 /* put back the last character */
819 /* but do not put back the trailing 'f' or a float */
820 if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
823 /* generally we don't want words to follow numbers: */
825 lexerror(lex, "unexpected trailing characters after number");
826 return (lex->tok.ttype = TOKEN_ERROR);
828 lex_ungetch(lex, ch);
831 if (lex->tok.ttype == TOKEN_FLOATCONST)
832 lex->tok.constval.f = strtod(lex->tok.value, NULL);
834 lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
835 return lex->tok.ttype;
838 int lex_do(lex_file *lex)
840 int ch, nextch, thirdch;
849 ch = lex_skipwhite(lex);
850 if (!lex->flags.mergelines || ch != '\\')
854 lex_ungetch(lex, ch);
858 /* we reached a linemerge */
859 lex_tokench(lex, '\n');
863 lex->sline = lex->line;
864 lex->tok.ctx.line = lex->sline;
865 lex->tok.ctx.file = lex->name;
867 if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
868 return (lex->tok.ttype = ch);
872 return (lex->tok.ttype = TOKEN_FATAL);
876 return (lex->tok.ttype = TOKEN_EOF);
879 /* modelgen / spiritgen commands */
885 if (!isident_start(ch)) {
886 lexerror(lex, "hanging '$' modelgen/spritegen command line");
889 lex_tokench(lex, ch);
890 if (!lex_finish_ident(lex))
891 return (lex->tok.ttype = TOKEN_ERROR);
893 /* skip the known commands */
896 if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
898 /* frame/framesave command works like an enum
899 * similar to fteqcc we handle this in the lexer.
900 * The reason for this is that it is sensitive to newlines,
901 * which the parser is unaware of
903 if (!lex_finish_frames(lex))
904 return (lex->tok.ttype = TOKEN_ERROR);
908 if (!strcmp(v, "framevalue"))
911 while (ch != EOF && isspace(ch) && ch != '\n')
915 lexerror(lex, "$framevalue requires an integer parameter");
920 lex->tok.ttype = lex_finish_digit(lex, ch);
922 if (lex->tok.ttype != TOKEN_INTCONST) {
923 lexerror(lex, "$framevalue requires an integer parameter");
926 lex->framevalue = lex->tok.constval.i;
930 if (!strcmp(v, "framerestore"))
936 rc = lex_parse_frame(lex);
939 lexerror(lex, "$framerestore requires a framename parameter");
943 return (lex->tok.ttype = TOKEN_FATAL);
946 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
947 if (!strcmp(v, lex->frames[frame].name)) {
948 lex->framevalue = lex->frames[frame].value;
952 lexerror(lex, "unknown framename `%s`", v);
956 if (!strcmp(v, "modelname"))
962 rc = lex_parse_frame(lex);
965 lexerror(lex, "$modelname requires a parameter");
969 return (lex->tok.ttype = TOKEN_FATAL);
972 if (lex->modelname) {
974 m.value = lex->framevalue;
975 m.name = lex->modelname;
976 lex->modelname = NULL;
977 vec_push(lex->frames, m);
979 lex->modelname = lex->tok.value;
980 lex->tok.value = NULL;
984 if (!strcmp(v, "flush"))
987 for (fi = 0; fi < vec_size(lex->frames); ++fi)
988 mem_d(lex->frames[fi].name);
989 vec_free(lex->frames);
990 /* skip line (fteqcc does it too) */
992 while (ch != EOF && ch != '\n')
997 if (!strcmp(v, "cd") ||
998 !strcmp(v, "origin") ||
999 !strcmp(v, "base") ||
1000 !strcmp(v, "flags") ||
1001 !strcmp(v, "scale") ||
1005 ch = lex_getch(lex);
1006 while (ch != EOF && ch != '\n')
1007 ch = lex_getch(lex);
1011 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
1012 if (!strcmp(v, lex->frames[frame].name)) {
1013 lex->tok.constval.i = lex->frames[frame].value;
1014 return (lex->tok.ttype = TOKEN_INTCONST);
1018 lexerror(lex, "invalid frame macro");
1022 /* single-character tokens */
1029 lex_tokench(lex, ch);
1031 if (lex->flags.noops)
1032 return (lex->tok.ttype = ch);
1034 return (lex->tok.ttype = TOKEN_OPERATOR);
1042 lex_tokench(lex, ch);
1044 return (lex->tok.ttype = ch);
1049 if (lex->flags.noops)
1051 /* Detect characters early which are normally
1052 * operators OR PART of an operator.
1069 lex_tokench(lex, ch);
1071 return (lex->tok.ttype = ch);
1078 lex_tokench(lex, ch);
1079 /* peak ahead once */
1080 nextch = lex_getch(lex);
1081 if (nextch != '.') {
1082 lex_ungetch(lex, nextch);
1084 return (lex->tok.ttype = ch);
1086 /* peak ahead again */
1087 nextch = lex_getch(lex);
1088 if (nextch != '.') {
1089 lex_ungetch(lex, nextch);
1090 lex_ungetch(lex, nextch);
1092 return (lex->tok.ttype = ch);
1094 /* fill the token to be "..." */
1095 lex_tokench(lex, ch);
1096 lex_tokench(lex, ch);
1098 return (lex->tok.ttype = TOKEN_DOTS);
1102 if (ch == ',' || ch == '.') {
1103 lex_tokench(lex, ch);
1105 return (lex->tok.ttype = TOKEN_OPERATOR);
1108 if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */
1109 ch == '>' || ch == '<' || /* <<, >>, <=, >= */
1110 ch == '=' || ch == '!' || /* ==, != */
1111 ch == '&' || ch == '|') /* &&, ||, &=, |= */
1113 lex_tokench(lex, ch);
1115 nextch = lex_getch(lex);
1116 if (nextch == ch || nextch == '=') {
1117 lex_tokench(lex, nextch);
1118 } else if (ch == '-' && nextch == '>') {
1119 lex_tokench(lex, nextch);
1120 } else if (ch == '&' && nextch == '~') {
1121 thirdch = lex_getch(lex);
1122 if (thirdch != '=') {
1123 lex_ungetch(lex, thirdch);
1124 lex_ungetch(lex, nextch);
1127 lex_tokench(lex, nextch);
1128 lex_tokench(lex, thirdch);
1131 lex_ungetch(lex, nextch);
1134 return (lex->tok.ttype = TOKEN_OPERATOR);
1138 if (ch == '^' || ch == '~' || ch == '!')
1140 lex_tokench(lex, ch);
1142 return (lex->tok.ttype = TOKEN_OPERATOR);
1146 if (ch == '*' || ch == '/') /* *=, /= */
1148 lex_tokench(lex, ch);
1150 nextch = lex_getch(lex);
1151 if (nextch == '=') {
1152 lex_tokench(lex, nextch);
1154 lex_ungetch(lex, nextch);
1157 return (lex->tok.ttype = TOKEN_OPERATOR);
1160 if (isident_start(ch))
1164 lex_tokench(lex, ch);
1165 if (!lex_finish_ident(lex)) {
1167 return (lex->tok.ttype = TOKEN_ERROR);
1170 lex->tok.ttype = TOKEN_IDENT;
1173 if (!strcmp(v, "void")) {
1174 lex->tok.ttype = TOKEN_TYPENAME;
1175 lex->tok.constval.t = TYPE_VOID;
1176 } else if (!strcmp(v, "int")) {
1177 lex->tok.ttype = TOKEN_TYPENAME;
1178 lex->tok.constval.t = TYPE_INTEGER;
1179 } else if (!strcmp(v, "float")) {
1180 lex->tok.ttype = TOKEN_TYPENAME;
1181 lex->tok.constval.t = TYPE_FLOAT;
1182 } else if (!strcmp(v, "string")) {
1183 lex->tok.ttype = TOKEN_TYPENAME;
1184 lex->tok.constval.t = TYPE_STRING;
1185 } else if (!strcmp(v, "entity")) {
1186 lex->tok.ttype = TOKEN_TYPENAME;
1187 lex->tok.constval.t = TYPE_ENTITY;
1188 } else if (!strcmp(v, "vector")) {
1189 lex->tok.ttype = TOKEN_TYPENAME;
1190 lex->tok.constval.t = TYPE_VECTOR;
1193 for (kw = 0; kw < num_keywords_qc; ++kw) {
1194 if (!strcmp(v, keywords_qc[kw]))
1195 return (lex->tok.ttype = TOKEN_KEYWORD);
1197 if (opts_standard != COMPILER_QCC) {
1198 for (kw = 0; kw < num_keywords_fg; ++kw) {
1199 if (!strcmp(v, keywords_fg[kw]))
1200 return (lex->tok.ttype = TOKEN_KEYWORD);
1205 return lex->tok.ttype;
1210 lex->flags.nodigraphs = true;
1211 if (lex->flags.preprocessing)
1212 lex_tokench(lex, ch);
1213 lex->tok.ttype = lex_finish_string(lex, '"');
1214 if (lex->flags.preprocessing)
1215 lex_tokench(lex, ch);
1216 while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
1218 /* Allow c style "string" "continuation" */
1219 ch = lex_skipwhite(lex);
1221 lex_ungetch(lex, ch);
1225 lex->tok.ttype = lex_finish_string(lex, '"');
1227 lex->flags.nodigraphs = false;
1229 return lex->tok.ttype;
1234 /* we parse character constants like string,
1235 * but return TOKEN_CHARCONST, or a vector type if it fits...
1236 * Likewise actual unescaping has to be done by the parser.
1237 * The difference is we don't allow 'char' 'continuation'.
1239 if (lex->flags.preprocessing)
1240 lex_tokench(lex, ch);
1241 lex->tok.ttype = lex_finish_string(lex, '\'');
1242 if (lex->flags.preprocessing)
1243 lex_tokench(lex, ch);
1246 /* It's a vector if we can successfully scan 3 floats */
1248 if (sscanf_s(lex->tok.value, " %f %f %f ",
1249 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1251 if (sscanf(lex->tok.value, " %f %f %f ",
1252 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1256 lex->tok.ttype = TOKEN_VECTORCONST;
1259 return lex->tok.ttype;
1264 lex->tok.ttype = lex_finish_digit(lex, ch);
1266 return lex->tok.ttype;
1269 lexerror(lex, "unknown token");
1270 return (lex->tok.ttype = TOKEN_ERROR);