11 void lexerror(lex_file *lex, const char *fmt, ...)
17 con_vprintmsg(LVL_ERROR, lex->name, lex->sline, "parse error", fmt, ap);
19 con_vprintmsg(LVL_ERROR, "", 0, "parse error", fmt, ap);
23 bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...)
26 int lvl = LVL_WARNING;
28 if (!OPTS_WARN(warntype))
35 con_vprintmsg(lvl, lex->name, lex->sline, "warning", fmt, ap);
45 token *tok = (token*)mem_a(sizeof(token));
48 memset(tok, 0, sizeof(*tok));
52 void token_delete(token *self)
54 if (self->next && self->next->prev == self)
55 self->next->prev = self->prev;
56 if (self->prev && self->prev->next == self)
57 self->prev->next = self->next;
58 MEM_VECTOR_CLEAR(self, value);
62 token* token_copy(const token *cp)
64 token* self = token_new();
68 self->value_alloc = cp->value_count + 1;
69 self->value_count = cp->value_count;
70 self->value = (char*)mem_a(self->value_alloc);
75 memcpy(self->value, cp->value, cp->value_count);
76 self->value[self->value_alloc-1] = 0;
80 self->ttype = cp->ttype;
81 memcpy(&self->constval, &cp->constval, sizeof(self->constval));
85 void token_delete_all(token *t)
96 token* token_copy_all(const token *cp)
101 out = cur = token_copy(cp);
107 cur->next = token_copy(cp);
109 token_delete_all(out);
112 cur->next->prev = cur;
119 static void lex_token_new(lex_file *lex)
123 token_delete(lex->tok);
124 lex->tok = token_new();
127 vec_shrinkto(lex->tok.value, 0);
128 lex->tok.constval.t = 0;
129 lex->tok.ctx.line = lex->sline;
130 lex->tok.ctx.file = lex->name;
135 lex_file* lex_open(const char *file)
138 FILE *in = util_fopen(file, "rb");
141 lexerror(NULL, "open failed: '%s'\n", file);
145 lex = (lex_file*)mem_a(sizeof(*lex));
148 lexerror(NULL, "out of memory\n");
152 memset(lex, 0, sizeof(*lex));
155 lex->name = util_strdup(file);
156 lex->line = 1; /* we start counting at 1 */
161 vec_push(lex_filenames, lex->name);
165 lex_file* lex_open_string(const char *str, size_t len, const char *name)
169 lex = (lex_file*)mem_a(sizeof(*lex));
171 lexerror(NULL, "out of memory\n");
175 memset(lex, 0, sizeof(*lex));
178 lex->open_string = str;
179 lex->open_string_length = len;
180 lex->open_string_pos = 0;
182 lex->name = util_strdup(name ? name : "<string-source>");
183 lex->line = 1; /* we start counting at 1 */
188 vec_push(lex_filenames, lex->name);
193 void lex_cleanup(void)
196 for (i = 0; i < vec_size(lex_filenames); ++i)
197 mem_d(lex_filenames[i]);
198 vec_free(lex_filenames);
201 void lex_close(lex_file *lex)
204 for (i = 0; i < vec_size(lex->frames); ++i)
205 mem_d(lex->frames[i].name);
206 vec_free(lex->frames);
209 vec_free(lex->modelname);
215 token_delete(lex->tok);
217 vec_free(lex->tok.value);
219 /* mem_d(lex->name); collected in lex_filenames */
223 static int lex_fgetc(lex_file *lex)
226 return fgetc(lex->file);
227 if (lex->open_string) {
228 if (lex->open_string_pos >= lex->open_string_length)
230 return lex->open_string[lex->open_string_pos++];
235 /* Get or put-back data
236 * The following to functions do NOT understand what kind of data they
238 * The are merely wrapping get/put in order to count line numbers.
240 static void lex_ungetch(lex_file *lex, int ch);
241 static int lex_try_trigraph(lex_file *lex, int old)
246 lex_ungetch(lex, c2);
252 case '=': return '#';
253 case '/': return '\\';
254 case '\'': return '^';
255 case '(': return '[';
256 case ')': return ']';
257 case '!': return '|';
258 case '<': return '{';
259 case '>': return '}';
260 case '-': return '~';
262 lex_ungetch(lex, c3);
263 lex_ungetch(lex, c2);
268 static int lex_try_digraph(lex_file *lex, int ch)
272 if (ch == '<' && c2 == ':')
274 else if (ch == ':' && c2 == '>')
276 else if (ch == '<' && c2 == '%')
278 else if (ch == '%' && c2 == '>')
280 else if (ch == '%' && c2 == ':')
282 lex_ungetch(lex, c2);
286 static int lex_getch(lex_file *lex)
292 if (!lex->push_line && lex->peek[lex->peekpos] == '\n')
294 return lex->peek[lex->peekpos];
298 if (!lex->push_line && ch == '\n')
301 return lex_try_trigraph(lex, ch);
302 else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
303 return lex_try_digraph(lex, ch);
307 static void lex_ungetch(lex_file *lex, int ch)
309 lex->peek[lex->peekpos++] = ch;
310 if (!lex->push_line && ch == '\n')
314 /* classify characters
315 * some additions to the is*() functions of ctype.h
318 /* Idents are alphanumberic, but they start with alpha or _ */
319 static bool isident_start(int ch)
321 return isalpha(ch) || ch == '_';
324 static bool isident(int ch)
326 return isident_start(ch) || isdigit(ch);
329 /* isxdigit_only is used when we already know it's not a digit
330 * and want to see if it's a hex digit anyway.
332 static bool isxdigit_only(int ch)
334 return (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
337 /* Append a character to the token buffer */
338 static void lex_tokench(lex_file *lex, int ch)
340 vec_push(lex->tok.value, ch);
343 /* Append a trailing null-byte */
344 static void lex_endtoken(lex_file *lex)
346 vec_push(lex->tok.value, 0);
347 vec_shrinkby(lex->tok.value, 1);
350 static bool lex_try_pragma(lex_file *lex)
354 char *command = NULL;
358 if (lex->flags.preprocessing)
365 lex_ungetch(lex, ch);
369 for (ch = lex_getch(lex); vec_size(pragma) < 8 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
370 vec_push(pragma, ch);
373 if (ch != ' ' || strcmp(pragma, "pragma")) {
374 lex_ungetch(lex, ch);
378 for (ch = lex_getch(lex); vec_size(command) < 32 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
379 vec_push(command, ch);
380 vec_push(command, 0);
383 lex_ungetch(lex, ch);
387 for (ch = lex_getch(lex); vec_size(param) < 32 && ch != ')' && ch != '\n'; ch = lex_getch(lex))
392 lex_ungetch(lex, ch);
396 if (!strcmp(command, "push")) {
397 if (!strcmp(param, "line")) {
404 else if (!strcmp(command, "pop")) {
405 if (!strcmp(param, "line")) {
413 else if (!strcmp(command, "file")) {
414 lex->name = util_strdup(param);
415 vec_push(lex_filenames, lex->name);
417 else if (!strcmp(command, "line")) {
418 line = strtol(param, NULL, 0)-1;
431 while (vec_size(command)) {
432 lex_ungetch(lex, vec_last(command));
439 while (vec_size(command)) {
440 lex_ungetch(lex, vec_last(command));
447 while (vec_size(pragma)) {
448 lex_ungetch(lex, vec_last(pragma));
453 lex_ungetch(lex, '#');
459 /* Skip whitespace and comments and return the first
460 * non-white character.
461 * As this makes use of the above getch() ungetch() functions,
462 * we don't need to care at all about line numbering anymore.
464 * In theory, this function should only be used at the beginning
465 * of lexing, or when we *know* the next character is part of the token.
466 * Otherwise, if the parser throws an error, the linenumber may not be
467 * the line of the error, but the line of the next token AFTER the error.
469 * This is currently only problematic when using c-like string-continuation,
470 * since comments and whitespaces are allowed between 2 such strings.
474 "A continuation of the previous string"
475 // This line is skipped
478 * In this case, if the parse decides it didn't actually want a string,
479 * and uses lex->line to print an error, it will show the ', foo);' line's
482 * On the other hand, the parser is supposed to remember the line of the next
483 * token's beginning. In this case we would want skipwhite() to be called
484 * AFTER reading a token, so that the parser, before reading the NEXT token,
485 * doesn't store teh *comment's* linenumber, but the actual token's linenumber.
488 * here is to store the line of the first character after skipping
489 * the initial whitespace in lex->sline, this happens in lex_do.
491 static int lex_skipwhite(lex_file *lex)
494 bool haswhite = false;
499 while (ch != EOF && isspace(ch)) {
501 if (lex_try_pragma(lex))
504 if (lex->flags.preprocessing) {
507 /* see if there was whitespace first */
508 if (haswhite) { /* (vec_size(lex->tok.value)) { */
509 lex_ungetch(lex, ch);
513 /* otherwise return EOL */
517 lex_tokench(lex, ch);
526 /* one line comment */
529 if (lex->flags.preprocessing) {
532 lex_tokench(lex, '/');
533 lex_tokench(lex, '/');
535 lex_tokench(lex, ' ');
536 lex_tokench(lex, ' ');
539 while (ch != EOF && ch != '\n') {
540 if (lex->flags.preprocessing)
541 lex_tokench(lex, ' '); /* ch); */
544 if (lex->flags.preprocessing) {
545 lex_ungetch(lex, '\n');
553 /* multiline comment */
554 if (lex->flags.preprocessing) {
557 lex_tokench(lex, '/');
558 lex_tokench(lex, '*');
560 lex_tokench(lex, ' ');
561 lex_tokench(lex, ' ');
570 if (lex->flags.preprocessing) {
572 lex_tokench(lex, '*');
573 lex_tokench(lex, '/');
575 lex_tokench(lex, ' ');
576 lex_tokench(lex, ' ');
581 if (lex->flags.preprocessing) {
582 lex_tokench(lex, ' '); /* ch); */
585 ch = ' '; /* cause TRUE in the isspace check */
588 /* Otherwise roll back to the slash and break out of the loop */
589 lex_ungetch(lex, ch);
593 } while (ch != EOF && isspace(ch));
597 lex_ungetch(lex, ch);
604 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
609 while (ch != EOF && isident(ch))
611 lex_tokench(lex, ch);
615 /* last ch was not an ident ch: */
616 lex_ungetch(lex, ch);
621 /* read one ident for the frame list */
622 static int lex_parse_frame(lex_file *lex)
629 while (ch != EOF && ch != '\n' && isspace(ch))
635 if (!isident_start(ch)) {
636 lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
640 lex_tokench(lex, ch);
641 if (!lex_finish_ident(lex))
647 /* read a list of $frames */
648 static bool lex_finish_frames(lex_file *lex)
655 rc = lex_parse_frame(lex);
656 if (rc > 0) /* end of line */
658 if (rc < 0) /* error */
661 for (i = 0; i < vec_size(lex->frames); ++i) {
662 if (!strcmp(lex->tok.value, lex->frames[i].name)) {
663 lex->frames[i].value = lex->framevalue++;
664 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
669 if (i < vec_size(lex->frames))
672 m.value = lex->framevalue++;
673 m.name = util_strdup(lex->tok.value);
674 vec_shrinkto(lex->tok.value, 0);
675 vec_push(lex->frames, m);
679 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
687 return TOKEN_STRINGCONST;
689 if (lex->flags.preprocessing && ch == '\\') {
690 lex_tokench(lex, ch);
693 lexerror(lex, "unexpected end of file");
694 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
695 return (lex->tok.ttype = TOKEN_ERROR);
697 lex_tokench(lex, ch);
699 else if (ch == '\\') {
702 lexerror(lex, "unexpected end of file");
703 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
704 return (lex->tok.ttype = TOKEN_ERROR);
711 case 'a': ch = '\a'; break;
712 case 'b': ch = '\b'; break;
713 case 'r': ch = '\r'; break;
714 case 'n': ch = '\n'; break;
715 case 't': ch = '\t'; break;
716 case 'f': ch = '\f'; break;
717 case 'v': ch = '\v'; break;
719 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
720 /* so we just add the character plus backslash no matter what it actually is */
721 lex_tokench(lex, '\\');
723 /* add the character finally */
724 lex_tokench(lex, ch);
727 lex_tokench(lex, ch);
729 lexerror(lex, "unexpected end of file within string constant");
730 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
731 return (lex->tok.ttype = TOKEN_ERROR);
734 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
740 /* parse a number... */
741 lex->tok.ttype = TOKEN_INTCONST;
743 lex_tokench(lex, ch);
746 if (ch != '.' && !isdigit(ch))
748 if (lastch != '0' || ch != 'x')
750 /* end of the number or EOF */
751 lex_ungetch(lex, ch);
754 lex->tok.constval.i = lastch - '0';
755 return lex->tok.ttype;
761 /* EOF would have been caught above */
765 lex_tokench(lex, ch);
767 while (isdigit(ch) || (ishex && isxdigit_only(ch)))
769 lex_tokench(lex, ch);
773 /* NOT else, '.' can come from above as well */
774 if (ch == '.' && !ishex)
776 /* Allow floating comma in non-hex mode */
777 lex->tok.ttype = TOKEN_FLOATCONST;
778 lex_tokench(lex, ch);
780 /* continue digits-only */
784 lex_tokench(lex, ch);
788 /* put back the last character */
789 /* but do not put back the trailing 'f' or a float */
790 if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
793 /* generally we don't want words to follow numbers: */
795 lexerror(lex, "unexpected trailing characters after number");
796 return (lex->tok.ttype = TOKEN_ERROR);
798 lex_ungetch(lex, ch);
801 if (lex->tok.ttype == TOKEN_FLOATCONST)
802 lex->tok.constval.f = strtod(lex->tok.value, NULL);
804 lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
805 return lex->tok.ttype;
808 int lex_do(lex_file *lex)
819 ch = lex_skipwhite(lex);
820 if (!lex->flags.mergelines || ch != '\\')
824 lex_ungetch(lex, ch);
828 /* we reached a linemerge */
829 lex_tokench(lex, '\n');
833 lex->sline = lex->line;
834 lex->tok.ctx.line = lex->sline;
835 lex->tok.ctx.file = lex->name;
837 if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
838 return (lex->tok.ttype = ch);
842 return (lex->tok.ttype = TOKEN_FATAL);
846 return (lex->tok.ttype = TOKEN_EOF);
849 /* modelgen / spiritgen commands */
855 if (!isident_start(ch)) {
856 lexerror(lex, "hanging '$' modelgen/spritegen command line");
859 lex_tokench(lex, ch);
860 if (!lex_finish_ident(lex))
861 return (lex->tok.ttype = TOKEN_ERROR);
863 /* skip the known commands */
866 if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
868 /* frame/framesave command works like an enum
869 * similar to fteqcc we handle this in the lexer.
870 * The reason for this is that it is sensitive to newlines,
871 * which the parser is unaware of
873 if (!lex_finish_frames(lex))
874 return (lex->tok.ttype = TOKEN_ERROR);
878 if (!strcmp(v, "framevalue"))
881 while (ch != EOF && isspace(ch) && ch != '\n')
885 lexerror(lex, "$framevalue requires an integer parameter");
890 lex->tok.ttype = lex_finish_digit(lex, ch);
892 if (lex->tok.ttype != TOKEN_INTCONST) {
893 lexerror(lex, "$framevalue requires an integer parameter");
896 lex->framevalue = lex->tok.constval.i;
900 if (!strcmp(v, "framerestore"))
906 rc = lex_parse_frame(lex);
909 lexerror(lex, "$framerestore requires a framename parameter");
913 return (lex->tok.ttype = TOKEN_FATAL);
916 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
917 if (!strcmp(v, lex->frames[frame].name)) {
918 lex->framevalue = lex->frames[frame].value;
922 lexerror(lex, "unknown framename `%s`", v);
926 if (!strcmp(v, "modelname"))
932 rc = lex_parse_frame(lex);
935 lexerror(lex, "$modelname requires a parameter");
939 return (lex->tok.ttype = TOKEN_FATAL);
942 if (lex->modelname) {
944 m.value = lex->framevalue;
945 m.name = lex->modelname;
946 lex->modelname = NULL;
947 vec_push(lex->frames, m);
949 lex->modelname = lex->tok.value;
950 lex->tok.value = NULL;
954 if (!strcmp(v, "flush"))
957 for (frame = 0; frame < vec_size(lex->frames); ++frame)
958 mem_d(lex->frames[frame].name);
959 vec_free(lex->frames);
960 /* skip line (fteqcc does it too) */
962 while (ch != EOF && ch != '\n')
967 if (!strcmp(v, "cd") ||
968 !strcmp(v, "origin") ||
969 !strcmp(v, "base") ||
970 !strcmp(v, "flags") ||
971 !strcmp(v, "scale") ||
976 while (ch != EOF && ch != '\n')
981 for (frame = 0; frame < vec_size(lex->frames); ++frame) {
982 if (!strcmp(v, lex->frames[frame].name)) {
983 lex->tok.constval.i = lex->frames[frame].value;
984 return (lex->tok.ttype = TOKEN_INTCONST);
988 lexerror(lex, "invalid frame macro");
992 /* single-character tokens */
997 lex_tokench(lex, ch);
999 if (lex->flags.noops)
1000 return (lex->tok.ttype = ch);
1002 return (lex->tok.ttype = TOKEN_OPERATOR);
1011 lex_tokench(lex, ch);
1013 return (lex->tok.ttype = ch);
1018 if (lex->flags.noops)
1020 /* Detect characters early which are normally
1021 * operators OR PART of an operator.
1038 lex_tokench(lex, ch);
1040 return (lex->tok.ttype = ch);
1047 lex_tokench(lex, ch);
1048 /* peak ahead once */
1049 nextch = lex_getch(lex);
1050 if (nextch != '.') {
1051 lex_ungetch(lex, nextch);
1053 return (lex->tok.ttype = ch);
1055 /* peak ahead again */
1056 nextch = lex_getch(lex);
1057 if (nextch != '.') {
1058 lex_ungetch(lex, nextch);
1059 lex_ungetch(lex, nextch);
1061 return (lex->tok.ttype = ch);
1063 /* fill the token to be "..." */
1064 lex_tokench(lex, ch);
1065 lex_tokench(lex, ch);
1067 return (lex->tok.ttype = TOKEN_DOTS);
1071 if (ch == ',' || ch == '.') {
1072 lex_tokench(lex, ch);
1074 return (lex->tok.ttype = TOKEN_OPERATOR);
1077 if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */
1078 ch == '>' || ch == '<' || /* <<, >>, <=, >= */
1079 ch == '=' || ch == '!' || /* ==, != */
1080 ch == '&' || ch == '|') /* &&, ||, &=, |= */
1082 lex_tokench(lex, ch);
1084 nextch = lex_getch(lex);
1085 if (nextch == ch || nextch == '=') {
1086 lex_tokench(lex, nextch);
1087 } else if (ch == '-' && nextch == '>') {
1088 lex_tokench(lex, nextch);
1090 lex_ungetch(lex, nextch);
1093 return (lex->tok.ttype = TOKEN_OPERATOR);
1097 if (ch == '^' || ch == '~' || ch == '!')
1099 lex_tokench(lex, ch);
1101 return (lex->tok.ttype = TOKEN_OPERATOR);
1105 if (ch == '*' || ch == '/') /* *=, /= */
1107 lex_tokench(lex, ch);
1109 nextch = lex_getch(lex);
1110 if (nextch == '=') {
1111 lex_tokench(lex, nextch);
1113 lex_ungetch(lex, nextch);
1116 return (lex->tok.ttype = TOKEN_OPERATOR);
1119 if (isident_start(ch))
1123 lex_tokench(lex, ch);
1124 if (!lex_finish_ident(lex)) {
1126 return (lex->tok.ttype = TOKEN_ERROR);
1129 lex->tok.ttype = TOKEN_IDENT;
1132 if (!strcmp(v, "void")) {
1133 lex->tok.ttype = TOKEN_TYPENAME;
1134 lex->tok.constval.t = TYPE_VOID;
1135 } else if (!strcmp(v, "int")) {
1136 lex->tok.ttype = TOKEN_TYPENAME;
1137 lex->tok.constval.t = TYPE_INTEGER;
1138 } else if (!strcmp(v, "float")) {
1139 lex->tok.ttype = TOKEN_TYPENAME;
1140 lex->tok.constval.t = TYPE_FLOAT;
1141 } else if (!strcmp(v, "string")) {
1142 lex->tok.ttype = TOKEN_TYPENAME;
1143 lex->tok.constval.t = TYPE_STRING;
1144 } else if (!strcmp(v, "entity")) {
1145 lex->tok.ttype = TOKEN_TYPENAME;
1146 lex->tok.constval.t = TYPE_ENTITY;
1147 } else if (!strcmp(v, "vector")) {
1148 lex->tok.ttype = TOKEN_TYPENAME;
1149 lex->tok.constval.t = TYPE_VECTOR;
1150 } else if (!strcmp(v, "for") ||
1151 !strcmp(v, "while") ||
1154 !strcmp(v, "else") ||
1155 !strcmp(v, "local") ||
1156 !strcmp(v, "return") ||
1157 !strcmp(v, "not") ||
1158 !strcmp(v, "const"))
1160 lex->tok.ttype = TOKEN_KEYWORD;
1162 else if (opts_standard != COMPILER_QCC)
1164 /* other standards reserve these keywords */
1165 if (!strcmp(v, "switch") ||
1166 !strcmp(v, "struct") ||
1167 !strcmp(v, "union") ||
1168 !strcmp(v, "break") ||
1169 !strcmp(v, "continue") ||
1172 lex->tok.ttype = TOKEN_KEYWORD;
1176 return lex->tok.ttype;
1181 lex->flags.nodigraphs = true;
1182 if (lex->flags.preprocessing)
1183 lex_tokench(lex, ch);
1184 lex->tok.ttype = lex_finish_string(lex, '"');
1185 if (lex->flags.preprocessing)
1186 lex_tokench(lex, ch);
1187 while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
1189 /* Allow c style "string" "continuation" */
1190 ch = lex_skipwhite(lex);
1192 lex_ungetch(lex, ch);
1196 lex->tok.ttype = lex_finish_string(lex, '"');
1198 lex->flags.nodigraphs = false;
1200 return lex->tok.ttype;
1205 /* we parse character constants like string,
1206 * but return TOKEN_CHARCONST, or a vector type if it fits...
1207 * Likewise actual unescaping has to be done by the parser.
1208 * The difference is we don't allow 'char' 'continuation'.
1210 if (lex->flags.preprocessing)
1211 lex_tokench(lex, ch);
1212 lex->tok.ttype = lex_finish_string(lex, '\'');
1213 if (lex->flags.preprocessing)
1214 lex_tokench(lex, ch);
1217 /* It's a vector if we can successfully scan 3 floats */
1219 if (sscanf_s(lex->tok.value, " %f %f %f ",
1220 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1222 if (sscanf(lex->tok.value, " %f %f %f ",
1223 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1227 lex->tok.ttype = TOKEN_VECTORCONST;
1230 return lex->tok.ttype;
1235 lex->tok.ttype = lex_finish_digit(lex, ch);
1237 return lex->tok.ttype;
1240 lexerror(lex, "unknown token");
1241 return (lex->tok.ttype = TOKEN_ERROR);