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, ' ');
608 if (lex->flags.preprocessing) {
609 lex_tokench(lex, ' '); /* ch); */
612 ch = ' '; /* cause TRUE in the isspace check */
615 /* Otherwise roll back to the slash and break out of the loop */
616 lex_ungetch(lex, ch);
620 } while (ch != EOF && isspace(ch));
624 lex_ungetch(lex, ch);
631 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
636 while (ch != EOF && isident(ch))
638 lex_tokench(lex, ch);
642 /* last ch was not an ident ch: */
643 lex_ungetch(lex, ch);
648 /* read one ident for the frame list */
649 static int lex_parse_frame(lex_file *lex)
656 while (ch != EOF && ch != '\n' && isspace(ch))
662 if (!isident_start(ch)) {
663 lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
667 lex_tokench(lex, ch);
668 if (!lex_finish_ident(lex))
674 /* read a list of $frames */
675 static bool lex_finish_frames(lex_file *lex)
682 rc = lex_parse_frame(lex);
683 if (rc > 0) /* end of line */
685 if (rc < 0) /* error */
688 for (i = 0; i < vec_size(lex->frames); ++i) {
689 if (!strcmp(lex->tok.value, lex->frames[i].name)) {
690 lex->frames[i].value = lex->framevalue++;
691 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
696 if (i < vec_size(lex->frames))
699 m.value = lex->framevalue++;
700 m.name = util_strdup(lex->tok.value);
701 vec_shrinkto(lex->tok.value, 0);
702 vec_push(lex->frames, m);
706 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
714 return TOKEN_STRINGCONST;
716 if (lex->flags.preprocessing && ch == '\\') {
717 lex_tokench(lex, ch);
720 lexerror(lex, "unexpected end of file");
721 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
722 return (lex->tok.ttype = TOKEN_ERROR);
724 lex_tokench(lex, ch);
726 else if (ch == '\\') {
729 lexerror(lex, "unexpected end of file");
730 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
731 return (lex->tok.ttype = TOKEN_ERROR);
738 case 'a': ch = '\a'; break;
739 case 'b': ch = '\b'; break;
740 case 'r': ch = '\r'; break;
741 case 'n': ch = '\n'; break;
742 case 't': ch = '\t'; break;
743 case 'f': ch = '\f'; break;
744 case 'v': ch = '\v'; break;
746 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
747 /* so we just add the character plus backslash no matter what it actually is */
748 lex_tokench(lex, '\\');
750 /* add the character finally */
751 lex_tokench(lex, ch);
754 lex_tokench(lex, ch);
756 lexerror(lex, "unexpected end of file within string constant");
757 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
758 return (lex->tok.ttype = TOKEN_ERROR);
761 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
767 /* parse a number... */
768 lex->tok.ttype = TOKEN_INTCONST;
770 lex_tokench(lex, ch);
773 if (ch != '.' && !isdigit(ch))
775 if (lastch != '0' || ch != 'x')
777 /* end of the number or EOF */
778 lex_ungetch(lex, ch);
781 lex->tok.constval.i = lastch - '0';
782 return lex->tok.ttype;
788 /* EOF would have been caught above */
792 lex_tokench(lex, ch);
794 while (isdigit(ch) || (ishex && isxdigit_only(ch)))
796 lex_tokench(lex, ch);
800 /* NOT else, '.' can come from above as well */
801 if (ch == '.' && !ishex)
803 /* Allow floating comma in non-hex mode */
804 lex->tok.ttype = TOKEN_FLOATCONST;
805 lex_tokench(lex, ch);
807 /* continue digits-only */
811 lex_tokench(lex, ch);
815 /* put back the last character */
816 /* but do not put back the trailing 'f' or a float */
817 if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
820 /* generally we don't want words to follow numbers: */
822 lexerror(lex, "unexpected trailing characters after number");
823 return (lex->tok.ttype = TOKEN_ERROR);
825 lex_ungetch(lex, ch);
828 if (lex->tok.ttype == TOKEN_FLOATCONST)
829 lex->tok.constval.f = strtod(lex->tok.value, NULL);
831 lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
832 return lex->tok.ttype;
835 int lex_do(lex_file *lex)
846 ch = lex_skipwhite(lex);
847 if (!lex->flags.mergelines || ch != '\\')
851 lex_ungetch(lex, ch);
855 /* we reached a linemerge */
856 lex_tokench(lex, '\n');
860 lex->sline = lex->line;
861 lex->tok.ctx.line = lex->sline;
862 lex->tok.ctx.file = lex->name;
864 if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
865 return (lex->tok.ttype = ch);
869 return (lex->tok.ttype = TOKEN_FATAL);
873 return (lex->tok.ttype = TOKEN_EOF);
876 /* modelgen / spiritgen commands */
882 if (!isident_start(ch)) {
883 lexerror(lex, "hanging '$' modelgen/spritegen command line");
886 lex_tokench(lex, ch);
887 if (!lex_finish_ident(lex))
888 return (lex->tok.ttype = TOKEN_ERROR);
890 /* skip the known commands */
893 if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
895 /* frame/framesave command works like an enum
896 * similar to fteqcc we handle this in the lexer.
897 * The reason for this is that it is sensitive to newlines,
898 * which the parser is unaware of
900 if (!lex_finish_frames(lex))
901 return (lex->tok.ttype = TOKEN_ERROR);
905 if (!strcmp(v, "framevalue"))
908 while (ch != EOF && isspace(ch) && ch != '\n')
912 lexerror(lex, "$framevalue requires an integer parameter");
917 lex->tok.ttype = lex_finish_digit(lex, ch);
919 if (lex->tok.ttype != TOKEN_INTCONST) {
920 lexerror(lex, "$framevalue requires an integer parameter");
923 lex->framevalue = lex->tok.constval.i;
927 if (!strcmp(v, "framerestore"))
933 rc = lex_parse_frame(lex);
936 lexerror(lex, "$framerestore requires a framename parameter");
940 return (lex->tok.ttype = TOKEN_FATAL);
943 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
944 if (!strcmp(v, lex->frames[frame].name)) {
945 lex->framevalue = lex->frames[frame].value;
949 lexerror(lex, "unknown framename `%s`", v);
953 if (!strcmp(v, "modelname"))
959 rc = lex_parse_frame(lex);
962 lexerror(lex, "$modelname requires a parameter");
966 return (lex->tok.ttype = TOKEN_FATAL);
969 if (lex->modelname) {
971 m.value = lex->framevalue;
972 m.name = lex->modelname;
973 lex->modelname = NULL;
974 vec_push(lex->frames, m);
976 lex->modelname = lex->tok.value;
977 lex->tok.value = NULL;
981 if (!strcmp(v, "flush"))
984 for (fi = 0; fi < vec_size(lex->frames); ++fi)
985 mem_d(lex->frames[fi].name);
986 vec_free(lex->frames);
987 /* skip line (fteqcc does it too) */
989 while (ch != EOF && ch != '\n')
994 if (!strcmp(v, "cd") ||
995 !strcmp(v, "origin") ||
996 !strcmp(v, "base") ||
997 !strcmp(v, "flags") ||
998 !strcmp(v, "scale") ||
1002 ch = lex_getch(lex);
1003 while (ch != EOF && ch != '\n')
1004 ch = lex_getch(lex);
1008 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
1009 if (!strcmp(v, lex->frames[frame].name)) {
1010 lex->tok.constval.i = lex->frames[frame].value;
1011 return (lex->tok.ttype = TOKEN_INTCONST);
1015 lexerror(lex, "invalid frame macro");
1019 /* single-character tokens */
1026 lex_tokench(lex, ch);
1028 if (lex->flags.noops)
1029 return (lex->tok.ttype = ch);
1031 return (lex->tok.ttype = TOKEN_OPERATOR);
1039 lex_tokench(lex, ch);
1041 return (lex->tok.ttype = ch);
1046 if (lex->flags.noops)
1048 /* Detect characters early which are normally
1049 * operators OR PART of an operator.
1066 lex_tokench(lex, ch);
1068 return (lex->tok.ttype = ch);
1075 lex_tokench(lex, ch);
1076 /* peak ahead once */
1077 nextch = lex_getch(lex);
1078 if (nextch != '.') {
1079 lex_ungetch(lex, nextch);
1081 return (lex->tok.ttype = ch);
1083 /* peak ahead again */
1084 nextch = lex_getch(lex);
1085 if (nextch != '.') {
1086 lex_ungetch(lex, nextch);
1087 lex_ungetch(lex, nextch);
1089 return (lex->tok.ttype = ch);
1091 /* fill the token to be "..." */
1092 lex_tokench(lex, ch);
1093 lex_tokench(lex, ch);
1095 return (lex->tok.ttype = TOKEN_DOTS);
1099 if (ch == ',' || ch == '.') {
1100 lex_tokench(lex, ch);
1102 return (lex->tok.ttype = TOKEN_OPERATOR);
1105 if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */
1106 ch == '>' || ch == '<' || /* <<, >>, <=, >= */
1107 ch == '=' || ch == '!' || /* ==, != */
1108 ch == '&' || ch == '|') /* &&, ||, &=, |= */
1110 lex_tokench(lex, ch);
1112 nextch = lex_getch(lex);
1113 if (nextch == ch || nextch == '=') {
1114 lex_tokench(lex, nextch);
1115 } else if (ch == '-' && nextch == '>') {
1116 lex_tokench(lex, nextch);
1118 lex_ungetch(lex, nextch);
1121 return (lex->tok.ttype = TOKEN_OPERATOR);
1125 if (ch == '^' || ch == '~' || ch == '!')
1127 lex_tokench(lex, ch);
1129 return (lex->tok.ttype = TOKEN_OPERATOR);
1133 if (ch == '*' || ch == '/') /* *=, /= */
1135 lex_tokench(lex, ch);
1137 nextch = lex_getch(lex);
1138 if (nextch == '=') {
1139 lex_tokench(lex, nextch);
1141 lex_ungetch(lex, nextch);
1144 return (lex->tok.ttype = TOKEN_OPERATOR);
1147 if (isident_start(ch))
1151 lex_tokench(lex, ch);
1152 if (!lex_finish_ident(lex)) {
1154 return (lex->tok.ttype = TOKEN_ERROR);
1157 lex->tok.ttype = TOKEN_IDENT;
1160 if (!strcmp(v, "void")) {
1161 lex->tok.ttype = TOKEN_TYPENAME;
1162 lex->tok.constval.t = TYPE_VOID;
1163 } else if (!strcmp(v, "int")) {
1164 lex->tok.ttype = TOKEN_TYPENAME;
1165 lex->tok.constval.t = TYPE_INTEGER;
1166 } else if (!strcmp(v, "float")) {
1167 lex->tok.ttype = TOKEN_TYPENAME;
1168 lex->tok.constval.t = TYPE_FLOAT;
1169 } else if (!strcmp(v, "string")) {
1170 lex->tok.ttype = TOKEN_TYPENAME;
1171 lex->tok.constval.t = TYPE_STRING;
1172 } else if (!strcmp(v, "entity")) {
1173 lex->tok.ttype = TOKEN_TYPENAME;
1174 lex->tok.constval.t = TYPE_ENTITY;
1175 } else if (!strcmp(v, "vector")) {
1176 lex->tok.ttype = TOKEN_TYPENAME;
1177 lex->tok.constval.t = TYPE_VECTOR;
1180 for (kw = 0; kw < num_keywords_qc; ++kw) {
1181 if (!strcmp(v, keywords_qc[kw]))
1182 return (lex->tok.ttype = TOKEN_KEYWORD);
1184 if (opts_standard != COMPILER_QCC) {
1185 for (kw = 0; kw < num_keywords_fg; ++kw) {
1186 if (!strcmp(v, keywords_fg[kw]))
1187 return (lex->tok.ttype = TOKEN_KEYWORD);
1192 return lex->tok.ttype;
1197 lex->flags.nodigraphs = true;
1198 if (lex->flags.preprocessing)
1199 lex_tokench(lex, ch);
1200 lex->tok.ttype = lex_finish_string(lex, '"');
1201 if (lex->flags.preprocessing)
1202 lex_tokench(lex, ch);
1203 while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
1205 /* Allow c style "string" "continuation" */
1206 ch = lex_skipwhite(lex);
1208 lex_ungetch(lex, ch);
1212 lex->tok.ttype = lex_finish_string(lex, '"');
1214 lex->flags.nodigraphs = false;
1216 return lex->tok.ttype;
1221 /* we parse character constants like string,
1222 * but return TOKEN_CHARCONST, or a vector type if it fits...
1223 * Likewise actual unescaping has to be done by the parser.
1224 * The difference is we don't allow 'char' 'continuation'.
1226 if (lex->flags.preprocessing)
1227 lex_tokench(lex, ch);
1228 lex->tok.ttype = lex_finish_string(lex, '\'');
1229 if (lex->flags.preprocessing)
1230 lex_tokench(lex, ch);
1233 /* It's a vector if we can successfully scan 3 floats */
1235 if (sscanf_s(lex->tok.value, " %f %f %f ",
1236 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1238 if (sscanf(lex->tok.value, " %f %f %f ",
1239 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1243 lex->tok.ttype = TOKEN_VECTORCONST;
1246 return lex->tok.ttype;
1251 lex->tok.ttype = lex_finish_digit(lex, ch);
1253 return lex->tok.ttype;
1256 lexerror(lex, "unknown token");
1257 return (lex->tok.ttype = TOKEN_ERROR);