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) {
611 lex_tokench(lex, '\n');
613 lex_tokench(lex, ' '); /* ch); */
616 ch = ' '; /* cause TRUE in the isspace check */
619 /* Otherwise roll back to the slash and break out of the loop */
620 lex_ungetch(lex, ch);
624 } while (ch != EOF && isspace(ch));
628 lex_ungetch(lex, ch);
635 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
640 while (ch != EOF && isident(ch))
642 lex_tokench(lex, ch);
646 /* last ch was not an ident ch: */
647 lex_ungetch(lex, ch);
652 /* read one ident for the frame list */
653 static int lex_parse_frame(lex_file *lex)
660 while (ch != EOF && ch != '\n' && isspace(ch))
666 if (!isident_start(ch)) {
667 lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
671 lex_tokench(lex, ch);
672 if (!lex_finish_ident(lex))
678 /* read a list of $frames */
679 static bool lex_finish_frames(lex_file *lex)
686 rc = lex_parse_frame(lex);
687 if (rc > 0) /* end of line */
689 if (rc < 0) /* error */
692 for (i = 0; i < vec_size(lex->frames); ++i) {
693 if (!strcmp(lex->tok.value, lex->frames[i].name)) {
694 lex->frames[i].value = lex->framevalue++;
695 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
700 if (i < vec_size(lex->frames))
703 m.value = lex->framevalue++;
704 m.name = util_strdup(lex->tok.value);
705 vec_shrinkto(lex->tok.value, 0);
706 vec_push(lex->frames, m);
710 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
718 return TOKEN_STRINGCONST;
720 if (lex->flags.preprocessing && ch == '\\') {
721 lex_tokench(lex, ch);
724 lexerror(lex, "unexpected end of file");
725 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
726 return (lex->tok.ttype = TOKEN_ERROR);
728 lex_tokench(lex, ch);
730 else if (ch == '\\') {
733 lexerror(lex, "unexpected end of file");
734 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
735 return (lex->tok.ttype = TOKEN_ERROR);
742 case 'a': ch = '\a'; break;
743 case 'b': ch = '\b'; break;
744 case 'r': ch = '\r'; break;
745 case 'n': ch = '\n'; break;
746 case 't': ch = '\t'; break;
747 case 'f': ch = '\f'; break;
748 case 'v': ch = '\v'; break;
750 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
751 /* so we just add the character plus backslash no matter what it actually is */
752 lex_tokench(lex, '\\');
754 /* add the character finally */
755 lex_tokench(lex, ch);
758 lex_tokench(lex, ch);
760 lexerror(lex, "unexpected end of file within string constant");
761 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
762 return (lex->tok.ttype = TOKEN_ERROR);
765 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
771 /* parse a number... */
772 lex->tok.ttype = TOKEN_INTCONST;
774 lex_tokench(lex, ch);
777 if (ch != '.' && !isdigit(ch))
779 if (lastch != '0' || ch != 'x')
781 /* end of the number or EOF */
782 lex_ungetch(lex, ch);
785 lex->tok.constval.i = lastch - '0';
786 return lex->tok.ttype;
792 /* EOF would have been caught above */
796 lex_tokench(lex, ch);
798 while (isdigit(ch) || (ishex && isxdigit_only(ch)))
800 lex_tokench(lex, ch);
804 /* NOT else, '.' can come from above as well */
805 if (ch == '.' && !ishex)
807 /* Allow floating comma in non-hex mode */
808 lex->tok.ttype = TOKEN_FLOATCONST;
809 lex_tokench(lex, ch);
811 /* continue digits-only */
815 lex_tokench(lex, ch);
819 /* put back the last character */
820 /* but do not put back the trailing 'f' or a float */
821 if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
824 /* generally we don't want words to follow numbers: */
826 lexerror(lex, "unexpected trailing characters after number");
827 return (lex->tok.ttype = TOKEN_ERROR);
829 lex_ungetch(lex, ch);
832 if (lex->tok.ttype == TOKEN_FLOATCONST)
833 lex->tok.constval.f = strtod(lex->tok.value, NULL);
835 lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
836 return lex->tok.ttype;
839 int lex_do(lex_file *lex)
841 int ch, nextch, thirdch;
850 ch = lex_skipwhite(lex);
851 if (!lex->flags.mergelines || ch != '\\')
855 lex_ungetch(lex, ch);
859 /* we reached a linemerge */
860 lex_tokench(lex, '\n');
864 lex->sline = lex->line;
865 lex->tok.ctx.line = lex->sline;
866 lex->tok.ctx.file = lex->name;
868 if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
869 return (lex->tok.ttype = ch);
873 return (lex->tok.ttype = TOKEN_FATAL);
877 return (lex->tok.ttype = TOKEN_EOF);
880 /* modelgen / spiritgen commands */
886 if (!isident_start(ch)) {
887 lexerror(lex, "hanging '$' modelgen/spritegen command line");
890 lex_tokench(lex, ch);
891 if (!lex_finish_ident(lex))
892 return (lex->tok.ttype = TOKEN_ERROR);
894 /* skip the known commands */
897 if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
899 /* frame/framesave command works like an enum
900 * similar to fteqcc we handle this in the lexer.
901 * The reason for this is that it is sensitive to newlines,
902 * which the parser is unaware of
904 if (!lex_finish_frames(lex))
905 return (lex->tok.ttype = TOKEN_ERROR);
909 if (!strcmp(v, "framevalue"))
912 while (ch != EOF && isspace(ch) && ch != '\n')
916 lexerror(lex, "$framevalue requires an integer parameter");
921 lex->tok.ttype = lex_finish_digit(lex, ch);
923 if (lex->tok.ttype != TOKEN_INTCONST) {
924 lexerror(lex, "$framevalue requires an integer parameter");
927 lex->framevalue = lex->tok.constval.i;
931 if (!strcmp(v, "framerestore"))
937 rc = lex_parse_frame(lex);
940 lexerror(lex, "$framerestore requires a framename parameter");
944 return (lex->tok.ttype = TOKEN_FATAL);
947 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
948 if (!strcmp(v, lex->frames[frame].name)) {
949 lex->framevalue = lex->frames[frame].value;
953 lexerror(lex, "unknown framename `%s`", v);
957 if (!strcmp(v, "modelname"))
963 rc = lex_parse_frame(lex);
966 lexerror(lex, "$modelname requires a parameter");
970 return (lex->tok.ttype = TOKEN_FATAL);
973 if (lex->modelname) {
975 m.value = lex->framevalue;
976 m.name = lex->modelname;
977 lex->modelname = NULL;
978 vec_push(lex->frames, m);
980 lex->modelname = lex->tok.value;
981 lex->tok.value = NULL;
985 if (!strcmp(v, "flush"))
988 for (fi = 0; fi < vec_size(lex->frames); ++fi)
989 mem_d(lex->frames[fi].name);
990 vec_free(lex->frames);
991 /* skip line (fteqcc does it too) */
993 while (ch != EOF && ch != '\n')
998 if (!strcmp(v, "cd") ||
999 !strcmp(v, "origin") ||
1000 !strcmp(v, "base") ||
1001 !strcmp(v, "flags") ||
1002 !strcmp(v, "scale") ||
1006 ch = lex_getch(lex);
1007 while (ch != EOF && ch != '\n')
1008 ch = lex_getch(lex);
1012 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
1013 if (!strcmp(v, lex->frames[frame].name)) {
1014 lex->tok.constval.i = lex->frames[frame].value;
1015 return (lex->tok.ttype = TOKEN_INTCONST);
1019 lexerror(lex, "invalid frame macro");
1023 /* single-character tokens */
1030 lex_tokench(lex, ch);
1032 if (lex->flags.noops)
1033 return (lex->tok.ttype = ch);
1035 return (lex->tok.ttype = TOKEN_OPERATOR);
1043 lex_tokench(lex, ch);
1045 return (lex->tok.ttype = ch);
1050 if (lex->flags.noops)
1052 /* Detect characters early which are normally
1053 * operators OR PART of an operator.
1070 lex_tokench(lex, ch);
1072 return (lex->tok.ttype = ch);
1079 lex_tokench(lex, ch);
1080 /* peak ahead once */
1081 nextch = lex_getch(lex);
1082 if (nextch != '.') {
1083 lex_ungetch(lex, nextch);
1085 return (lex->tok.ttype = ch);
1087 /* peak ahead again */
1088 nextch = lex_getch(lex);
1089 if (nextch != '.') {
1090 lex_ungetch(lex, nextch);
1091 lex_ungetch(lex, nextch);
1093 return (lex->tok.ttype = ch);
1095 /* fill the token to be "..." */
1096 lex_tokench(lex, ch);
1097 lex_tokench(lex, ch);
1099 return (lex->tok.ttype = TOKEN_DOTS);
1103 if (ch == ',' || ch == '.') {
1104 lex_tokench(lex, ch);
1106 return (lex->tok.ttype = TOKEN_OPERATOR);
1109 if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */
1110 ch == '>' || ch == '<' || /* <<, >>, <=, >= */
1111 ch == '=' || ch == '!' || /* ==, != */
1112 ch == '&' || ch == '|') /* &&, ||, &=, |= */
1114 lex_tokench(lex, ch);
1116 nextch = lex_getch(lex);
1117 if (nextch == ch || nextch == '=') {
1118 lex_tokench(lex, nextch);
1119 } else if (ch == '-' && nextch == '>') {
1120 lex_tokench(lex, nextch);
1121 } else if (ch == '&' && nextch == '~') {
1122 thirdch = lex_getch(lex);
1123 if (thirdch != '=') {
1124 lex_ungetch(lex, thirdch);
1125 lex_ungetch(lex, nextch);
1128 lex_tokench(lex, nextch);
1129 lex_tokench(lex, thirdch);
1132 lex_ungetch(lex, nextch);
1135 return (lex->tok.ttype = TOKEN_OPERATOR);
1139 if (ch == '^' || ch == '~' || ch == '!')
1141 lex_tokench(lex, ch);
1143 return (lex->tok.ttype = TOKEN_OPERATOR);
1147 if (ch == '*' || ch == '/') /* *=, /= */
1149 lex_tokench(lex, ch);
1151 nextch = lex_getch(lex);
1152 if (nextch == '=') {
1153 lex_tokench(lex, nextch);
1155 lex_ungetch(lex, nextch);
1158 return (lex->tok.ttype = TOKEN_OPERATOR);
1161 if (isident_start(ch))
1165 lex_tokench(lex, ch);
1166 if (!lex_finish_ident(lex)) {
1168 return (lex->tok.ttype = TOKEN_ERROR);
1171 lex->tok.ttype = TOKEN_IDENT;
1174 if (!strcmp(v, "void")) {
1175 lex->tok.ttype = TOKEN_TYPENAME;
1176 lex->tok.constval.t = TYPE_VOID;
1177 } else if (!strcmp(v, "int")) {
1178 lex->tok.ttype = TOKEN_TYPENAME;
1179 lex->tok.constval.t = TYPE_INTEGER;
1180 } else if (!strcmp(v, "float")) {
1181 lex->tok.ttype = TOKEN_TYPENAME;
1182 lex->tok.constval.t = TYPE_FLOAT;
1183 } else if (!strcmp(v, "string")) {
1184 lex->tok.ttype = TOKEN_TYPENAME;
1185 lex->tok.constval.t = TYPE_STRING;
1186 } else if (!strcmp(v, "entity")) {
1187 lex->tok.ttype = TOKEN_TYPENAME;
1188 lex->tok.constval.t = TYPE_ENTITY;
1189 } else if (!strcmp(v, "vector")) {
1190 lex->tok.ttype = TOKEN_TYPENAME;
1191 lex->tok.constval.t = TYPE_VECTOR;
1194 for (kw = 0; kw < num_keywords_qc; ++kw) {
1195 if (!strcmp(v, keywords_qc[kw]))
1196 return (lex->tok.ttype = TOKEN_KEYWORD);
1198 if (opts_standard != COMPILER_QCC) {
1199 for (kw = 0; kw < num_keywords_fg; ++kw) {
1200 if (!strcmp(v, keywords_fg[kw]))
1201 return (lex->tok.ttype = TOKEN_KEYWORD);
1206 return lex->tok.ttype;
1211 lex->flags.nodigraphs = true;
1212 if (lex->flags.preprocessing)
1213 lex_tokench(lex, ch);
1214 lex->tok.ttype = lex_finish_string(lex, '"');
1215 if (lex->flags.preprocessing)
1216 lex_tokench(lex, ch);
1217 while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
1219 /* Allow c style "string" "continuation" */
1220 ch = lex_skipwhite(lex);
1222 lex_ungetch(lex, ch);
1226 lex->tok.ttype = lex_finish_string(lex, '"');
1228 lex->flags.nodigraphs = false;
1230 return lex->tok.ttype;
1235 /* we parse character constants like string,
1236 * but return TOKEN_CHARCONST, or a vector type if it fits...
1237 * Likewise actual unescaping has to be done by the parser.
1238 * The difference is we don't allow 'char' 'continuation'.
1240 if (lex->flags.preprocessing)
1241 lex_tokench(lex, ch);
1242 lex->tok.ttype = lex_finish_string(lex, '\'');
1243 if (lex->flags.preprocessing)
1244 lex_tokench(lex, ch);
1247 /* It's a vector if we can successfully scan 3 floats */
1249 if (sscanf_s(lex->tok.value, " %f %f %f ",
1250 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1252 if (sscanf(lex->tok.value, " %f %f %f ",
1253 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1257 lex->tok.ttype = TOKEN_VECTORCONST;
1260 return lex->tok.ttype;
1265 lex->tok.ttype = lex_finish_digit(lex, ch);
1267 return lex->tok.ttype;
1270 lexerror(lex, "unknown token");
1271 return (lex->tok.ttype = TOKEN_ERROR);