9 MEM_VEC_FUNCTIONS(token, char, value)
10 MEM_VEC_FUNCTIONS(lex_file, frame_macro, frames)
12 VECTOR_MAKE(char*, lex_filenames);
14 void lexerror(lex_file *lex, const char *fmt, ...)
19 vprintmsg(LVL_ERROR, lex->name, lex->sline, "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 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();
126 lex->tok.value_count = 0;
127 lex->tok.constval.t = 0;
128 lex->tok.ctx.line = lex->sline;
129 lex->tok.ctx.file = lex->name;
134 lex_file* lex_open(const char *file)
137 FILE *in = util_fopen(file, "rb");
140 lexerror(NULL, "open failed: '%s'\n", file);
144 lex = (lex_file*)mem_a(sizeof(*lex));
147 lexerror(NULL, "out of memory\n");
151 memset(lex, 0, sizeof(*lex));
154 lex->name = util_strdup(file);
155 lex->line = 1; /* we start counting at 1 */
160 lex_filenames_add(lex->name);
165 void lex_cleanup(void)
168 for (i = 0; i < lex_filenames_elements; ++i)
169 mem_d(lex_filenames_data[i]);
170 mem_d(lex_filenames_data);
173 void lex_close(lex_file *lex)
176 for (i = 0; i < lex->frames_count; ++i)
177 mem_d(lex->frames[i].name);
178 MEM_VECTOR_CLEAR(lex, frames);
181 mem_d(lex->modelname);
187 token_delete(lex->tok);
189 MEM_VECTOR_CLEAR(&(lex->tok), value);
191 /* mem_d(lex->name); collected in lex_filenames */
195 /* Get or put-back data
196 * The following to functions do NOT understand what kind of data they
198 * The are merely wrapping get/put in order to count line numbers.
200 static void lex_ungetch(lex_file *lex, int ch);
201 static int lex_try_trigraph(lex_file *lex, int old)
204 c2 = fgetc(lex->file);
206 lex_ungetch(lex, c2);
210 c3 = fgetc(lex->file);
212 case '=': return '#';
213 case '/': return '\\';
214 case '\'': return '^';
215 case '(': return '[';
216 case ')': return ']';
217 case '!': return '|';
218 case '<': return '{';
219 case '>': return '}';
220 case '-': return '~';
222 lex_ungetch(lex, c3);
223 lex_ungetch(lex, c2);
228 static int lex_try_digraph(lex_file *lex, int ch)
231 c2 = fgetc(lex->file);
232 if (ch == '<' && c2 == ':')
234 else if (ch == ':' && c2 == '>')
236 else if (ch == '<' && c2 == '%')
238 else if (ch == '%' && c2 == '>')
240 else if (ch == '%' && c2 == ':')
242 lex_ungetch(lex, c2);
246 static int lex_getch(lex_file *lex)
252 if (lex->peek[lex->peekpos] == '\n')
254 return lex->peek[lex->peekpos];
257 ch = fgetc(lex->file);
261 return lex_try_trigraph(lex, ch);
262 else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
263 return lex_try_digraph(lex, ch);
267 static void lex_ungetch(lex_file *lex, int ch)
269 lex->peek[lex->peekpos++] = ch;
274 /* classify characters
275 * some additions to the is*() functions of ctype.h
278 /* Idents are alphanumberic, but they start with alpha or _ */
279 static bool isident_start(int ch)
281 return isalpha(ch) || ch == '_';
284 static bool isident(int ch)
286 return isident_start(ch) || isdigit(ch);
289 /* isxdigit_only is used when we already know it's not a digit
290 * and want to see if it's a hex digit anyway.
292 static bool isxdigit_only(int ch)
294 return (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
297 /* Append a character to the token buffer */
298 static bool GMQCC_WARN lex_tokench(lex_file *lex, int ch)
300 if (!token_value_add(&lex->tok, ch)) {
301 lexerror(lex, "out of memory");
307 /* Append a trailing null-byte */
308 static bool GMQCC_WARN lex_endtoken(lex_file *lex)
310 if (!token_value_add(&lex->tok, 0)) {
311 lexerror(lex, "out of memory");
314 lex->tok.value_count--;
318 /* Skip whitespace and comments and return the first
319 * non-white character.
320 * As this makes use of the above getch() ungetch() functions,
321 * we don't need to care at all about line numbering anymore.
323 * In theory, this function should only be used at the beginning
324 * of lexing, or when we *know* the next character is part of the token.
325 * Otherwise, if the parser throws an error, the linenumber may not be
326 * the line of the error, but the line of the next token AFTER the error.
328 * This is currently only problematic when using c-like string-continuation,
329 * since comments and whitespaces are allowed between 2 such strings.
333 "A continuation of the previous string"
334 // This line is skipped
337 * In this case, if the parse decides it didn't actually want a string,
338 * and uses lex->line to print an error, it will show the ', foo);' line's
341 * On the other hand, the parser is supposed to remember the line of the next
342 * token's beginning. In this case we would want skipwhite() to be called
343 * AFTER reading a token, so that the parser, before reading the NEXT token,
344 * doesn't store teh *comment's* linenumber, but the actual token's linenumber.
347 * here is to store the line of the first character after skipping
348 * the initial whitespace in lex->sline, this happens in lex_do.
350 static int lex_skipwhite(lex_file *lex)
357 while (ch != EOF && isspace(ch)) {
358 if (lex->flags.preprocessing) {
361 /* see if there was whitespace first */
362 if (lex->tok.value_count) {
363 lex_ungetch(lex, ch);
364 if (!lex_endtoken(lex))
368 /* otherwise return EOL */
371 if (!lex_tokench(lex, ch))
376 if (lex->flags.preprocessing && !lex_tokench(lex, ch))
383 /* one line comment */
386 if (lex->flags.preprocessing) {
387 if (!lex_tokench(lex, ' ') ||
388 !lex_tokench(lex, ' '))
394 while (ch != EOF && ch != '\n') {
396 if (lex->flags.preprocessing && !lex_tokench(lex, ' '))
399 if (lex->flags.preprocessing) {
400 lex_ungetch(lex, '\n');
401 if (!lex_endtoken(lex))
409 /* multiline comment */
410 if (lex->flags.preprocessing) {
411 if (!lex_tokench(lex, ' ') ||
412 !lex_tokench(lex, ' '))
424 if (lex->flags.preprocessing) {
425 if (!lex_tokench(lex, ' ') ||
426 !lex_tokench(lex, ' '))
434 if (lex->flags.preprocessing) {
437 if (!lex_tokench(lex, ch))
441 ch = ' '; /* cause TRUE in the isspace check */
444 /* Otherwise roll back to the slash and break out of the loop */
445 lex_ungetch(lex, ch);
449 } while (ch != EOF && isspace(ch));
455 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
460 while (ch != EOF && isident(ch))
462 if (!lex_tokench(lex, ch))
463 return (lex->tok.ttype = TOKEN_FATAL);
467 /* last ch was not an ident ch: */
468 lex_ungetch(lex, ch);
473 /* read one ident for the frame list */
474 static int lex_parse_frame(lex_file *lex)
481 while (ch != EOF && ch != '\n' && isspace(ch))
487 if (!isident_start(ch)) {
488 lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
492 if (!lex_tokench(lex, ch))
494 if (!lex_finish_ident(lex))
496 if (!lex_endtoken(lex))
501 /* read a list of $frames */
502 static bool lex_finish_frames(lex_file *lex)
509 rc = lex_parse_frame(lex);
510 if (rc > 0) /* end of line */
512 if (rc < 0) /* error */
515 for (i = 0; i < lex->frames_count; ++i) {
516 if (!strcmp(lex->tok.value, lex->frames[i].name)) {
517 lex->frames[i].value = lex->framevalue++;
518 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
523 if (i < lex->frames_count)
526 m.value = lex->framevalue++;
527 m.name = lex->tok.value;
528 lex->tok.value = NULL;
529 lex->tok.value_alloc = lex->tok.value_count = 0;
530 if (!lex_file_frames_add(lex, m)) {
531 lexerror(lex, "out of memory");
537 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
545 return TOKEN_STRINGCONST;
550 lexerror(lex, "unexpected end of file");
551 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
552 return (lex->tok.ttype = TOKEN_ERROR);
557 case 'a': ch = '\a'; break;
558 case 'b': ch = '\b'; break;
559 case 'r': ch = '\r'; break;
560 case 'n': ch = '\n'; break;
561 case 't': ch = '\t'; break;
562 case 'f': ch = '\f'; break;
563 case 'v': ch = '\v'; break;
565 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
566 /* so we just add the character plus backslash no matter what it actually is */
567 if (!lex_tokench(lex, '\\'))
568 return (lex->tok.ttype = TOKEN_FATAL);
570 /* add the character finally */
571 if (!lex_tokench(lex, ch))
572 return (lex->tok.ttype = TOKEN_FATAL);
574 else if (!lex_tokench(lex, ch))
575 return (lex->tok.ttype = TOKEN_FATAL);
577 lexerror(lex, "unexpected end of file within string constant");
578 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
579 return (lex->tok.ttype = TOKEN_ERROR);
582 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
588 /* parse a number... */
589 lex->tok.ttype = TOKEN_INTCONST;
591 if (!lex_tokench(lex, ch))
592 return (lex->tok.ttype = TOKEN_FATAL);
595 if (ch != '.' && !isdigit(ch))
597 if (lastch != '0' || ch != 'x')
599 /* end of the number or EOF */
600 lex_ungetch(lex, ch);
601 if (!lex_endtoken(lex))
602 return (lex->tok.ttype = TOKEN_FATAL);
604 lex->tok.constval.i = lastch - '0';
605 return lex->tok.ttype;
611 /* EOF would have been caught above */
615 if (!lex_tokench(lex, ch))
616 return (lex->tok.ttype = TOKEN_FATAL);
618 while (isdigit(ch) || (ishex && isxdigit_only(ch)))
620 if (!lex_tokench(lex, ch))
621 return (lex->tok.ttype = TOKEN_FATAL);
625 /* NOT else, '.' can come from above as well */
626 if (ch == '.' && !ishex)
628 /* Allow floating comma in non-hex mode */
629 lex->tok.ttype = TOKEN_FLOATCONST;
630 if (!lex_tokench(lex, ch))
631 return (lex->tok.ttype = TOKEN_FATAL);
633 /* continue digits-only */
637 if (!lex_tokench(lex, ch))
638 return (lex->tok.ttype = TOKEN_FATAL);
642 /* put back the last character */
643 /* but do not put back the trailing 'f' or a float */
644 if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
647 /* generally we don't want words to follow numbers: */
649 lexerror(lex, "unexpected trailing characters after number");
650 return (lex->tok.ttype = TOKEN_ERROR);
652 lex_ungetch(lex, ch);
654 if (!lex_endtoken(lex))
655 return (lex->tok.ttype = TOKEN_FATAL);
656 if (lex->tok.ttype == TOKEN_FLOATCONST)
657 lex->tok.constval.f = strtod(lex->tok.value, NULL);
659 lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
660 return lex->tok.ttype;
663 int lex_do(lex_file *lex)
673 ch = lex_skipwhite(lex);
674 lex->sline = lex->line;
675 lex->tok.ctx.line = lex->sline;
676 lex->tok.ctx.file = lex->name;
678 if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || TOKEN_FATAL)) {
679 return (lex->tok.ttype = ch);
683 return (lex->tok.ttype = TOKEN_FATAL);
687 return (lex->tok.ttype = TOKEN_EOF);
690 /* modelgen / spiritgen commands */
696 if (!isident_start(ch)) {
697 lexerror(lex, "hanging '$' modelgen/spritegen command line");
700 if (!lex_tokench(lex, ch))
701 return (lex->tok.ttype = TOKEN_FATAL);
702 if (!lex_finish_ident(lex))
703 return (lex->tok.ttype = TOKEN_ERROR);
704 if (!lex_endtoken(lex))
705 return (lex->tok.ttype = TOKEN_FATAL);
706 /* skip the known commands */
709 if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
711 /* frame/framesave command works like an enum
712 * similar to fteqcc we handle this in the lexer.
713 * The reason for this is that it is sensitive to newlines,
714 * which the parser is unaware of
716 if (!lex_finish_frames(lex))
717 return (lex->tok.ttype = TOKEN_ERROR);
721 if (!strcmp(v, "framevalue"))
724 while (ch != EOF && isspace(ch) && ch != '\n')
728 lexerror(lex, "$framevalue requires an integer parameter");
733 lex->tok.ttype = lex_finish_digit(lex, ch);
734 if (!lex_endtoken(lex))
735 return (lex->tok.ttype = TOKEN_FATAL);
736 if (lex->tok.ttype != TOKEN_INTCONST) {
737 lexerror(lex, "$framevalue requires an integer parameter");
740 lex->framevalue = lex->tok.constval.i;
744 if (!strcmp(v, "framerestore"))
750 rc = lex_parse_frame(lex);
753 lexerror(lex, "$framerestore requires a framename parameter");
757 return (lex->tok.ttype = TOKEN_FATAL);
760 for (frame = 0; frame < lex->frames_count; ++frame) {
761 if (!strcmp(v, lex->frames[frame].name)) {
762 lex->framevalue = lex->frames[frame].value;
766 lexerror(lex, "unknown framename `%s`", v);
770 if (!strcmp(v, "modelname"))
776 rc = lex_parse_frame(lex);
779 lexerror(lex, "$framerestore requires a framename parameter");
783 return (lex->tok.ttype = TOKEN_FATAL);
786 if (lex->modelname) {
788 m.value = lex->framevalue;
789 m.name = lex->modelname;
790 lex->modelname = NULL;
791 if (!lex_file_frames_add(lex, m)) {
792 lexerror(lex, "out of memory");
793 return (lex->tok.ttype = TOKEN_FATAL);
796 lex->modelname = lex->tok.value;
797 lex->tok.value = NULL;
798 lex->tok.value_alloc = lex->tok.value_count = 0;
799 for (frame = 0; frame < lex->frames_count; ++frame) {
800 if (!strcmp(v, lex->frames[frame].name)) {
801 lex->framevalue = lex->frames[frame].value;
808 if (!strcmp(v, "flush"))
811 for (frame = 0; frame < lex->frames_count; ++frame)
812 mem_d(lex->frames[frame].name);
813 MEM_VECTOR_CLEAR(lex, frames);
814 /* skip line (fteqcc does it too) */
816 while (ch != EOF && ch != '\n')
821 if (!strcmp(v, "cd") ||
822 !strcmp(v, "origin") ||
823 !strcmp(v, "base") ||
824 !strcmp(v, "flags") ||
825 !strcmp(v, "scale") ||
830 while (ch != EOF && ch != '\n')
835 for (frame = 0; frame < lex->frames_count; ++frame) {
836 if (!strcmp(v, lex->frames[frame].name)) {
837 lex->tok.constval.i = lex->frames[frame].value;
838 return (lex->tok.ttype = TOKEN_INTCONST);
842 lexerror(lex, "invalid frame macro");
846 /* single-character tokens */
850 if (!lex_tokench(lex, ch) ||
853 return (lex->tok.ttype = TOKEN_FATAL);
855 if (lex->flags.noops)
856 return (lex->tok.ttype = ch);
858 return (lex->tok.ttype = TOKEN_OPERATOR);
867 if (!lex_tokench(lex, ch) ||
870 return (lex->tok.ttype = TOKEN_FATAL);
872 return (lex->tok.ttype = ch);
877 if (lex->flags.noops)
879 /* Detect characters early which are normally
880 * operators OR PART of an operator.
897 if (!lex_tokench(lex, ch) ||
900 return (lex->tok.ttype = TOKEN_FATAL);
902 return (lex->tok.ttype = ch);
909 if (!lex_tokench(lex, ch))
910 return (lex->tok.ttype = TOKEN_FATAL);
911 /* peak ahead once */
912 nextch = lex_getch(lex);
914 lex_ungetch(lex, nextch);
915 if (!lex_endtoken(lex))
916 return (lex->tok.ttype = TOKEN_FATAL);
917 return (lex->tok.ttype = ch);
919 /* peak ahead again */
920 nextch = lex_getch(lex);
922 lex_ungetch(lex, nextch);
923 lex_ungetch(lex, nextch);
924 if (!lex_endtoken(lex))
925 return (lex->tok.ttype = TOKEN_FATAL);
926 return (lex->tok.ttype = ch);
928 /* fill the token to be "..." */
929 if (!lex_tokench(lex, ch) ||
930 !lex_tokench(lex, ch) ||
933 return (lex->tok.ttype = TOKEN_FATAL);
935 return (lex->tok.ttype = TOKEN_DOTS);
939 if (ch == ',' || ch == '.') {
940 if (!lex_tokench(lex, ch) ||
943 return (lex->tok.ttype = TOKEN_FATAL);
945 return (lex->tok.ttype = TOKEN_OPERATOR);
948 if (ch == '+' || ch == '-' || /* ++, --, +=, -= and -> as well! */
949 ch == '>' || ch == '<' || /* <<, >>, <=, >= */
950 ch == '=' || ch == '!' || /* ==, != */
951 ch == '&' || ch == '|') /* &&, ||, &=, |= */
953 if (!lex_tokench(lex, ch))
954 return (lex->tok.ttype = TOKEN_FATAL);
956 nextch = lex_getch(lex);
957 if (nextch == ch || nextch == '=') {
958 if (!lex_tokench(lex, nextch))
959 return (lex->tok.ttype = TOKEN_FATAL);
960 } else if (ch == '-' && nextch == '>') {
961 if (!lex_tokench(lex, nextch))
962 return (lex->tok.ttype = TOKEN_FATAL);
964 lex_ungetch(lex, nextch);
966 if (!lex_endtoken(lex))
967 return (lex->tok.ttype = TOKEN_FATAL);
968 return (lex->tok.ttype = TOKEN_OPERATOR);
972 if (ch == '^' || ch == '~' || ch == '!')
974 if (!lex_tokench(lex, ch) ||
977 return (lex->tok.ttype = TOKEN_FATAL);
979 return (lex->tok.ttype = TOKEN_OPERATOR);
983 if (ch == '*' || ch == '/') /* *=, /= */
985 if (!lex_tokench(lex, ch))
986 return (lex->tok.ttype = TOKEN_FATAL);
988 nextch = lex_getch(lex);
990 if (!lex_tokench(lex, nextch))
991 return (lex->tok.ttype = TOKEN_FATAL);
993 lex_ungetch(lex, nextch);
995 if (!lex_endtoken(lex))
996 return (lex->tok.ttype = TOKEN_FATAL);
997 return (lex->tok.ttype = TOKEN_OPERATOR);
1000 if (isident_start(ch))
1004 if (!lex_tokench(lex, ch))
1005 return (lex->tok.ttype = TOKEN_FATAL);
1006 if (!lex_finish_ident(lex)) {
1008 return (lex->tok.ttype = TOKEN_ERROR);
1010 if (!lex_endtoken(lex))
1011 return (lex->tok.ttype = TOKEN_FATAL);
1012 lex->tok.ttype = TOKEN_IDENT;
1015 if (!strcmp(v, "void")) {
1016 lex->tok.ttype = TOKEN_TYPENAME;
1017 lex->tok.constval.t = TYPE_VOID;
1018 } else if (!strcmp(v, "int")) {
1019 lex->tok.ttype = TOKEN_TYPENAME;
1020 lex->tok.constval.t = TYPE_INTEGER;
1021 } else if (!strcmp(v, "float")) {
1022 lex->tok.ttype = TOKEN_TYPENAME;
1023 lex->tok.constval.t = TYPE_FLOAT;
1024 } else if (!strcmp(v, "string")) {
1025 lex->tok.ttype = TOKEN_TYPENAME;
1026 lex->tok.constval.t = TYPE_STRING;
1027 } else if (!strcmp(v, "entity")) {
1028 lex->tok.ttype = TOKEN_TYPENAME;
1029 lex->tok.constval.t = TYPE_ENTITY;
1030 } else if (!strcmp(v, "vector")) {
1031 lex->tok.ttype = TOKEN_TYPENAME;
1032 lex->tok.constval.t = TYPE_VECTOR;
1033 } else if (!strcmp(v, "for") ||
1034 !strcmp(v, "while") ||
1037 !strcmp(v, "else") ||
1038 !strcmp(v, "local") ||
1039 !strcmp(v, "return") ||
1040 !strcmp(v, "const"))
1042 lex->tok.ttype = TOKEN_KEYWORD;
1044 else if (opts_standard != COMPILER_QCC)
1046 /* other standards reserve these keywords */
1047 if (!strcmp(v, "switch") ||
1048 !strcmp(v, "struct") ||
1049 !strcmp(v, "union") ||
1050 !strcmp(v, "break") ||
1051 !strcmp(v, "continue"))
1053 lex->tok.ttype = TOKEN_KEYWORD;
1057 return lex->tok.ttype;
1062 lex->flags.nodigraphs = true;
1063 lex->tok.ttype = lex_finish_string(lex, '"');
1064 while (lex->tok.ttype == TOKEN_STRINGCONST)
1066 /* Allow c style "string" "continuation" */
1067 ch = lex_skipwhite(lex);
1069 lex_ungetch(lex, ch);
1073 lex->tok.ttype = lex_finish_string(lex, '"');
1075 lex->flags.nodigraphs = false;
1076 if (!lex_endtoken(lex))
1077 return (lex->tok.ttype = TOKEN_FATAL);
1078 return lex->tok.ttype;
1083 /* we parse character constants like string,
1084 * but return TOKEN_CHARCONST, or a vector type if it fits...
1085 * Likewise actual unescaping has to be done by the parser.
1086 * The difference is we don't allow 'char' 'continuation'.
1088 lex->tok.ttype = lex_finish_string(lex, '\'');
1089 if (!lex_endtoken(lex))
1090 return (lex->tok.ttype = TOKEN_FATAL);
1092 /* It's a vector if we can successfully scan 3 floats */
1094 if (sscanf_s(lex->tok.value, " %f %f %f ",
1095 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1097 if (sscanf(lex->tok.value, " %f %f %f ",
1098 &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1101 lex->tok.ttype = TOKEN_VECTORCONST;
1104 return lex->tok.ttype;
1109 lex->tok.ttype = lex_finish_digit(lex, ch);
1110 if (!lex_endtoken(lex))
1111 return (lex->tok.ttype = TOKEN_FATAL);
1112 return lex->tok.ttype;
1115 lexerror(lex, "unknown token");
1116 return (lex->tok.ttype = TOKEN_ERROR);