5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do
10 * so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 static const char *keywords_qc[] = {
43 static size_t num_keywords_qc = sizeof(keywords_qc) / sizeof(keywords_qc[0]);
46 static const char *keywords_fg[] = {
47 "switch", "case", "default",
51 static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]);
59 void lexerror(lex_file *lex, const char *fmt, ...)
65 con_vprintmsg(LVL_ERROR, lex->name, lex->sline, "parse error", fmt, ap);
67 con_vprintmsg(LVL_ERROR, "", 0, "parse error", fmt, ap);
71 bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...)
74 int lvl = LVL_WARNING;
76 if (!OPTS_WARN(warntype))
83 con_vprintmsg(lvl, lex->name, lex->sline, "warning", fmt, ap);
93 token *tok = (token*)mem_a(sizeof(token));
96 memset(tok, 0, sizeof(*tok));
100 void token_delete(token *self)
102 if (self->next && self->next->prev == self)
103 self->next->prev = self->prev;
104 if (self->prev && self->prev->next == self)
105 self->prev->next = self->next;
106 MEM_VECTOR_CLEAR(self, value);
110 token* token_copy(const token *cp)
112 token* self = token_new();
116 self->value_alloc = cp->value_count + 1;
117 self->value_count = cp->value_count;
118 self->value = (char*)mem_a(self->value_alloc);
123 memcpy(self->value, cp->value, cp->value_count);
124 self->value[self->value_alloc-1] = 0;
128 self->ttype = cp->ttype;
129 memcpy(&self->constval, &cp->constval, sizeof(self->constval));
133 void token_delete_all(token *t)
144 token* token_copy_all(const token *cp)
149 out = cur = token_copy(cp);
155 cur->next = token_copy(cp);
157 token_delete_all(out);
160 cur->next->prev = cur;
167 static void lex_token_new(lex_file *lex)
171 token_delete(lex->tok);
172 lex->tok = token_new();
175 vec_shrinkto(lex->tok.value, 0);
176 lex->tok.constval.t = 0;
177 lex->tok.ctx.line = lex->sline;
178 lex->tok.ctx.file = lex->name;
183 lex_file* lex_open(const char *file)
186 FILE *in = util_fopen(file, "rb");
189 lexerror(NULL, "open failed: '%s'\n", file);
193 lex = (lex_file*)mem_a(sizeof(*lex));
196 lexerror(NULL, "out of memory\n");
200 memset(lex, 0, sizeof(*lex));
203 lex->name = util_strdup(file);
204 lex->line = 1; /* we start counting at 1 */
209 vec_push(lex_filenames, lex->name);
213 lex_file* lex_open_string(const char *str, size_t len, const char *name)
217 lex = (lex_file*)mem_a(sizeof(*lex));
219 lexerror(NULL, "out of memory\n");
223 memset(lex, 0, sizeof(*lex));
226 lex->open_string = str;
227 lex->open_string_length = len;
228 lex->open_string_pos = 0;
230 lex->name = util_strdup(name ? name : "<string-source>");
231 lex->line = 1; /* we start counting at 1 */
236 vec_push(lex_filenames, lex->name);
241 void lex_cleanup(void)
244 for (i = 0; i < vec_size(lex_filenames); ++i)
245 mem_d(lex_filenames[i]);
246 vec_free(lex_filenames);
249 void lex_close(lex_file *lex)
252 for (i = 0; i < vec_size(lex->frames); ++i)
253 mem_d(lex->frames[i].name);
254 vec_free(lex->frames);
257 vec_free(lex->modelname);
263 token_delete(lex->tok);
265 vec_free(lex->tok.value);
267 /* mem_d(lex->name); collected in lex_filenames */
271 static int lex_fgetc(lex_file *lex)
274 return fgetc(lex->file);
275 if (lex->open_string) {
276 if (lex->open_string_pos >= lex->open_string_length)
278 return lex->open_string[lex->open_string_pos++];
283 /* Get or put-back data
284 * The following to functions do NOT understand what kind of data they
286 * The are merely wrapping get/put in order to count line numbers.
288 static void lex_ungetch(lex_file *lex, int ch);
289 static int lex_try_trigraph(lex_file *lex, int old)
294 lex_ungetch(lex, c2);
300 case '=': return '#';
301 case '/': return '\\';
302 case '\'': return '^';
303 case '(': return '[';
304 case ')': return ']';
305 case '!': return '|';
306 case '<': return '{';
307 case '>': return '}';
308 case '-': return '~';
310 lex_ungetch(lex, c3);
311 lex_ungetch(lex, c2);
316 static int lex_try_digraph(lex_file *lex, int ch)
320 if (ch == '<' && c2 == ':')
322 else if (ch == ':' && c2 == '>')
324 else if (ch == '<' && c2 == '%')
326 else if (ch == '%' && c2 == '>')
328 else if (ch == '%' && c2 == ':')
330 lex_ungetch(lex, c2);
334 static int lex_getch(lex_file *lex)
340 if (!lex->push_line && lex->peek[lex->peekpos] == '\n')
342 return lex->peek[lex->peekpos];
346 if (!lex->push_line && ch == '\n')
349 return lex_try_trigraph(lex, ch);
350 else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
351 return lex_try_digraph(lex, ch);
355 static void lex_ungetch(lex_file *lex, int ch)
357 lex->peek[lex->peekpos++] = ch;
358 if (!lex->push_line && ch == '\n')
362 /* classify characters
363 * some additions to the is*() functions of ctype.h
366 /* Idents are alphanumberic, but they start with alpha or _ */
367 static bool isident_start(int ch)
369 return isalpha(ch) || ch == '_';
372 static bool isident(int ch)
374 return isident_start(ch) || isdigit(ch);
377 /* isxdigit_only is used when we already know it's not a digit
378 * and want to see if it's a hex digit anyway.
380 static bool isxdigit_only(int ch)
382 return (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
385 /* Append a character to the token buffer */
386 static void lex_tokench(lex_file *lex, int ch)
388 vec_push(lex->tok.value, ch);
391 /* Append a trailing null-byte */
392 static void lex_endtoken(lex_file *lex)
394 vec_push(lex->tok.value, 0);
395 vec_shrinkby(lex->tok.value, 1);
398 static bool lex_try_pragma(lex_file *lex)
402 char *command = NULL;
406 if (lex->flags.preprocessing)
413 lex_ungetch(lex, ch);
417 for (ch = lex_getch(lex); vec_size(pragma) < 8 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
418 vec_push(pragma, ch);
421 if (ch != ' ' || strcmp(pragma, "pragma")) {
422 lex_ungetch(lex, ch);
426 for (ch = lex_getch(lex); vec_size(command) < 32 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
427 vec_push(command, ch);
428 vec_push(command, 0);
431 lex_ungetch(lex, ch);
435 for (ch = lex_getch(lex); vec_size(param) < 32 && ch != ')' && ch != '\n'; ch = lex_getch(lex))
440 lex_ungetch(lex, ch);
444 if (!strcmp(command, "push")) {
445 if (!strcmp(param, "line")) {
452 else if (!strcmp(command, "pop")) {
453 if (!strcmp(param, "line")) {
461 else if (!strcmp(command, "file")) {
462 lex->name = util_strdup(param);
463 vec_push(lex_filenames, lex->name);
465 else if (!strcmp(command, "line")) {
466 line = strtol(param, NULL, 0)-1;
472 while (ch != '\n' && ch != EOF)
479 while (vec_size(command)) {
480 lex_ungetch(lex, vec_last(command));
487 while (vec_size(command)) {
488 lex_ungetch(lex, vec_last(command));
495 while (vec_size(pragma)) {
496 lex_ungetch(lex, vec_last(pragma));
501 lex_ungetch(lex, '#');
507 /* Skip whitespace and comments and return the first
508 * non-white character.
509 * As this makes use of the above getch() ungetch() functions,
510 * we don't need to care at all about line numbering anymore.
512 * In theory, this function should only be used at the beginning
513 * of lexing, or when we *know* the next character is part of the token.
514 * Otherwise, if the parser throws an error, the linenumber may not be
515 * the line of the error, but the line of the next token AFTER the error.
517 * This is currently only problematic when using c-like string-continuation,
518 * since comments and whitespaces are allowed between 2 such strings.
522 "A continuation of the previous string"
523 // This line is skipped
526 * In this case, if the parse decides it didn't actually want a string,
527 * and uses lex->line to print an error, it will show the ', foo);' line's
530 * On the other hand, the parser is supposed to remember the line of the next
531 * token's beginning. In this case we would want skipwhite() to be called
532 * AFTER reading a token, so that the parser, before reading the NEXT token,
533 * doesn't store teh *comment's* linenumber, but the actual token's linenumber.
536 * here is to store the line of the first character after skipping
537 * the initial whitespace in lex->sline, this happens in lex_do.
539 static int lex_skipwhite(lex_file *lex)
542 bool haswhite = false;
547 while (ch != EOF && isspace(ch)) {
549 if (lex_try_pragma(lex))
552 if (lex->flags.preprocessing) {
555 /* see if there was whitespace first */
556 if (haswhite) { /* (vec_size(lex->tok.value)) { */
557 lex_ungetch(lex, ch);
561 /* otherwise return EOL */
565 lex_tokench(lex, ch);
574 /* one line comment */
577 if (lex->flags.preprocessing) {
580 lex_tokench(lex, '/');
581 lex_tokench(lex, '/');
583 lex_tokench(lex, ' ');
584 lex_tokench(lex, ' ');
587 while (ch != EOF && ch != '\n') {
588 if (lex->flags.preprocessing)
589 lex_tokench(lex, ' '); /* ch); */
592 if (lex->flags.preprocessing) {
593 lex_ungetch(lex, '\n');
601 /* multiline comment */
602 if (lex->flags.preprocessing) {
605 lex_tokench(lex, '/');
606 lex_tokench(lex, '*');
608 lex_tokench(lex, ' ');
609 lex_tokench(lex, ' ');
618 if (lex->flags.preprocessing) {
620 lex_tokench(lex, '*');
621 lex_tokench(lex, '/');
623 lex_tokench(lex, ' ');
624 lex_tokench(lex, ' ');
628 lex_ungetch(lex, ch);
630 if (lex->flags.preprocessing) {
632 lex_tokench(lex, '\n');
634 lex_tokench(lex, ' '); /* ch); */
637 ch = ' '; /* cause TRUE in the isspace check */
640 /* Otherwise roll back to the slash and break out of the loop */
641 lex_ungetch(lex, ch);
645 } while (ch != EOF && isspace(ch));
649 lex_ungetch(lex, ch);
656 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
661 while (ch != EOF && isident(ch))
663 lex_tokench(lex, ch);
667 /* last ch was not an ident ch: */
668 lex_ungetch(lex, ch);
673 /* read one ident for the frame list */
674 static int lex_parse_frame(lex_file *lex)
681 while (ch != EOF && ch != '\n' && isspace(ch))
687 if (!isident_start(ch)) {
688 lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
692 lex_tokench(lex, ch);
693 if (!lex_finish_ident(lex))
699 /* read a list of $frames */
700 static bool lex_finish_frames(lex_file *lex)
707 rc = lex_parse_frame(lex);
708 if (rc > 0) /* end of line */
710 if (rc < 0) /* error */
713 for (i = 0; i < vec_size(lex->frames); ++i) {
714 if (!strcmp(lex->tok.value, lex->frames[i].name)) {
715 lex->frames[i].value = lex->framevalue++;
716 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
721 if (i < vec_size(lex->frames))
724 m.value = lex->framevalue++;
725 m.name = util_strdup(lex->tok.value);
726 vec_shrinkto(lex->tok.value, 0);
727 vec_push(lex->frames, m);
731 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
739 return TOKEN_STRINGCONST;
741 if (lex->flags.preprocessing && ch == '\\') {
742 lex_tokench(lex, ch);
745 lexerror(lex, "unexpected end of file");
746 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
747 return (lex->tok.ttype = TOKEN_ERROR);
749 lex_tokench(lex, ch);
751 else if (ch == '\\') {
754 lexerror(lex, "unexpected end of file");
755 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
756 return (lex->tok.ttype = TOKEN_ERROR);
763 case 'a': ch = '\a'; break;
764 case 'b': ch = '\b'; break;
765 case 'r': ch = '\r'; break;
766 case 'n': ch = '\n'; break;
767 case 't': ch = '\t'; break;
768 case 'f': ch = '\f'; break;
769 case 'v': ch = '\v'; break;
771 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
772 /* so we just add the character plus backslash no matter what it actually is */
773 lex_tokench(lex, '\\');
775 /* add the character finally */
776 lex_tokench(lex, ch);
779 lex_tokench(lex, ch);
781 lexerror(lex, "unexpected end of file within string constant");
782 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
783 return (lex->tok.ttype = TOKEN_ERROR);
786 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
792 /* parse a number... */
793 lex->tok.ttype = TOKEN_INTCONST;
795 lex_tokench(lex, ch);
798 if (ch != '.' && !isdigit(ch))
800 if (lastch != '0' || ch != 'x')
802 /* end of the number or EOF */
803 lex_ungetch(lex, ch);
806 lex->tok.constval.i = lastch - '0';
807 return lex->tok.ttype;
813 /* EOF would have been caught above */
817 lex_tokench(lex, ch);
819 while (isdigit(ch) || (ishex && isxdigit_only(ch)))
821 lex_tokench(lex, ch);
825 /* NOT else, '.' can come from above as well */
826 if (ch == '.' && !ishex)
828 /* Allow floating comma in non-hex mode */
829 lex->tok.ttype = TOKEN_FLOATCONST;
830 lex_tokench(lex, ch);
832 /* continue digits-only */
836 lex_tokench(lex, ch);
840 /* put back the last character */
841 /* but do not put back the trailing 'f' or a float */
842 if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
845 /* generally we don't want words to follow numbers: */
847 lexerror(lex, "unexpected trailing characters after number");
848 return (lex->tok.ttype = TOKEN_ERROR);
850 lex_ungetch(lex, ch);
853 if (lex->tok.ttype == TOKEN_FLOATCONST)
854 lex->tok.constval.f = strtod(lex->tok.value, NULL);
856 lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
857 return lex->tok.ttype;
860 int lex_do(lex_file *lex)
862 int ch, nextch, thirdch;
871 ch = lex_skipwhite(lex);
872 if (!lex->flags.mergelines || ch != '\\')
876 lex_ungetch(lex, ch);
880 /* we reached a linemerge */
881 lex_tokench(lex, '\n');
885 lex->sline = lex->line;
886 lex->tok.ctx.line = lex->sline;
887 lex->tok.ctx.file = lex->name;
889 if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
890 return (lex->tok.ttype = ch);
894 return (lex->tok.ttype = TOKEN_FATAL);
898 return (lex->tok.ttype = TOKEN_EOF);
901 /* modelgen / spiritgen commands */
907 if (!isident_start(ch)) {
908 lexerror(lex, "hanging '$' modelgen/spritegen command line");
911 lex_tokench(lex, ch);
912 if (!lex_finish_ident(lex))
913 return (lex->tok.ttype = TOKEN_ERROR);
915 /* skip the known commands */
918 if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
920 /* frame/framesave command works like an enum
921 * similar to fteqcc we handle this in the lexer.
922 * The reason for this is that it is sensitive to newlines,
923 * which the parser is unaware of
925 if (!lex_finish_frames(lex))
926 return (lex->tok.ttype = TOKEN_ERROR);
930 if (!strcmp(v, "framevalue"))
933 while (ch != EOF && isspace(ch) && ch != '\n')
937 lexerror(lex, "$framevalue requires an integer parameter");
942 lex->tok.ttype = lex_finish_digit(lex, ch);
944 if (lex->tok.ttype != TOKEN_INTCONST) {
945 lexerror(lex, "$framevalue requires an integer parameter");
948 lex->framevalue = lex->tok.constval.i;
952 if (!strcmp(v, "framerestore"))
958 rc = lex_parse_frame(lex);
961 lexerror(lex, "$framerestore requires a framename parameter");
965 return (lex->tok.ttype = TOKEN_FATAL);
968 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
969 if (!strcmp(v, lex->frames[frame].name)) {
970 lex->framevalue = lex->frames[frame].value;
974 lexerror(lex, "unknown framename `%s`", v);
978 if (!strcmp(v, "modelname"))
984 rc = lex_parse_frame(lex);
987 lexerror(lex, "$modelname requires a parameter");
991 return (lex->tok.ttype = TOKEN_FATAL);
994 if (lex->modelname) {
996 m.value = lex->framevalue;
997 m.name = lex->modelname;
998 lex->modelname = NULL;
999 vec_push(lex->frames, m);
1001 lex->modelname = lex->tok.value;
1002 lex->tok.value = NULL;
1006 if (!strcmp(v, "flush"))
1009 for (fi = 0; fi < vec_size(lex->frames); ++fi)
1010 mem_d(lex->frames[fi].name);
1011 vec_free(lex->frames);
1012 /* skip line (fteqcc does it too) */
1013 ch = lex_getch(lex);
1014 while (ch != EOF && ch != '\n')
1015 ch = lex_getch(lex);
1019 if (!strcmp(v, "cd") ||
1020 !strcmp(v, "origin") ||
1021 !strcmp(v, "base") ||
1022 !strcmp(v, "flags") ||
1023 !strcmp(v, "scale") ||
1027 ch = lex_getch(lex);
1028 while (ch != EOF && ch != '\n')
1029 ch = lex_getch(lex);
1033 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
1034 if (!strcmp(v, lex->frames[frame].name)) {
1035 lex->tok.constval.i = lex->frames[frame].value;
1036 return (lex->tok.ttype = TOKEN_INTCONST);
1040 lexerror(lex, "invalid frame macro");
1044 /* single-character tokens */
1051 lex_tokench(lex, ch);
1053 if (lex->flags.noops)
1054 return (lex->tok.ttype = ch);
1056 return (lex->tok.ttype = TOKEN_OPERATOR);
1064 lex_tokench(lex, ch);
1066 return (lex->tok.ttype = ch);
1071 if (lex->flags.noops)
1073 /* Detect characters early which are normally
1074 * operators OR PART of an operator.
1091 lex_tokench(lex, ch);
1093 return (lex->tok.ttype = ch);
1100 lex_tokench(lex, ch);
1101 /* peak ahead once */
1102 nextch = lex_getch(lex);
1103 if (nextch != '.') {
1104 lex_ungetch(lex, nextch);
1106 return (lex->tok.ttype = ch);
1108 /* peak ahead again */
1109 nextch = lex_getch(lex);
1110 if (nextch != '.') {
1111 lex_ungetch(lex, nextch);
1112 lex_ungetch(lex, nextch);
1114 return (lex->tok.ttype = ch);
1116 /* fill the token to be "..." */
1117 lex_tokench(lex, ch);
1118 lex_tokench(lex, ch);
1120 return (lex->tok.ttype = TOKEN_DOTS);
1124 if (ch == ',' || ch == '.') {
1125 lex_tokench(lex, ch);
1127 return (lex->tok.ttype = TOKEN_OPERATOR);
1130 if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */
1131 ch == '>' || ch == '<' || /* <<, >>, <=, >= */
1132 ch == '=' || ch == '!' || /* ==, != */
1133 ch == '&' || ch == '|') /* &&, ||, &=, |= */
1135 lex_tokench(lex, ch);
1137 nextch = lex_getch(lex);
1138 if (nextch == ch || nextch == '=') {
1139 lex_tokench(lex, nextch);
1140 } else if (ch == '-' && nextch == '>') {
1141 lex_tokench(lex, nextch);
1142 } else if (ch == '&' && nextch == '~') {
1143 thirdch = lex_getch(lex);
1144 if (thirdch != '=') {
1145 lex_ungetch(lex, thirdch);
1146 lex_ungetch(lex, nextch);
1149 lex_tokench(lex, nextch);
1150 lex_tokench(lex, thirdch);
1153 lex_ungetch(lex, nextch);
1156 return (lex->tok.ttype = TOKEN_OPERATOR);
1160 if (ch == '^' || ch == '~' || ch == '!')
1162 lex_tokench(lex, ch);
1164 return (lex->tok.ttype = TOKEN_OPERATOR);
1168 if (ch == '*' || ch == '/') /* *=, /= */
1170 lex_tokench(lex, ch);
1172 nextch = lex_getch(lex);
1173 if (nextch == '=') {
1174 lex_tokench(lex, nextch);
1176 lex_ungetch(lex, nextch);
1179 return (lex->tok.ttype = TOKEN_OPERATOR);
1182 if (isident_start(ch))
1186 lex_tokench(lex, ch);
1187 if (!lex_finish_ident(lex)) {
1189 return (lex->tok.ttype = TOKEN_ERROR);
1192 lex->tok.ttype = TOKEN_IDENT;
1195 if (!strcmp(v, "void")) {
1196 lex->tok.ttype = TOKEN_TYPENAME;
1197 lex->tok.constval.t = TYPE_VOID;
1198 } else if (!strcmp(v, "int")) {
1199 lex->tok.ttype = TOKEN_TYPENAME;
1200 lex->tok.constval.t = TYPE_INTEGER;
1201 } else if (!strcmp(v, "float")) {
1202 lex->tok.ttype = TOKEN_TYPENAME;
1203 lex->tok.constval.t = TYPE_FLOAT;
1204 } else if (!strcmp(v, "string")) {
1205 lex->tok.ttype = TOKEN_TYPENAME;
1206 lex->tok.constval.t = TYPE_STRING;
1207 } else if (!strcmp(v, "entity")) {
1208 lex->tok.ttype = TOKEN_TYPENAME;
1209 lex->tok.constval.t = TYPE_ENTITY;
1210 } else if (!strcmp(v, "vector")) {
1211 lex->tok.ttype = TOKEN_TYPENAME;
1212 lex->tok.constval.t = TYPE_VECTOR;
1215 for (kw = 0; kw < num_keywords_qc; ++kw) {
1216 if (!strcmp(v, keywords_qc[kw]))
1217 return (lex->tok.ttype = TOKEN_KEYWORD);
1219 if (opts_standard != COMPILER_QCC) {
1220 for (kw = 0; kw < num_keywords_fg; ++kw) {
1221 if (!strcmp(v, keywords_fg[kw]))
1222 return (lex->tok.ttype = TOKEN_KEYWORD);
1227 return lex->tok.ttype;
1232 lex->flags.nodigraphs = true;
1233 if (lex->flags.preprocessing)
1234 lex_tokench(lex, ch);
1235 lex->tok.ttype = lex_finish_string(lex, '"');
1236 if (lex->flags.preprocessing)
1237 lex_tokench(lex, ch);
1238 while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
1240 /* Allow c style "string" "continuation" */
1241 ch = lex_skipwhite(lex);
1243 lex_ungetch(lex, ch);
1247 lex->tok.ttype = lex_finish_string(lex, '"');
1249 lex->flags.nodigraphs = false;
1251 return lex->tok.ttype;
1256 /* we parse character constants like string,
1257 * but return TOKEN_CHARCONST, or a vector type if it fits...
1258 * Likewise actual unescaping has to be done by the parser.
1259 * The difference is we don't allow 'char' 'continuation'.
1261 if (lex->flags.preprocessing)
1262 lex_tokench(lex, ch);
1263 lex->tok.ttype = lex_finish_string(lex, '\'');
1264 if (lex->flags.preprocessing)
1265 lex_tokench(lex, ch);
1268 /* It's a vector if we can successfully scan 3 floats */
1270 if (sscanf_s(lex->tok.value, " %f %f %f ",
1271 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1273 if (sscanf(lex->tok.value, " %f %f %f ",
1274 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1278 lex->tok.ttype = TOKEN_VECTORCONST;
1281 return lex->tok.ttype;
1286 lex->tok.ttype = lex_finish_digit(lex, ch);
1288 return lex->tok.ttype;
1291 lexerror(lex, "unknown token");
1292 return (lex->tok.ttype = TOKEN_ERROR);