]> de.git.xonotic.org Git - xonotic/gmqcc.git/blob - lexer.c
Merge branch 'master' into cooking
[xonotic/gmqcc.git] / lexer.c
1 /*
2  * Copyright (C) 2012, 2013
3  *     Wolfgang Bumiller
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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
21  * SOFTWARE.
22  */
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27
28 #include "gmqcc.h"
29 #include "lexer.h"
30
31 /*
32  * List of Keywords
33  */
34
35 /* original */
36 static const char *keywords_qc[] = {
37     "for", "do", "while",
38     "if", "else",
39     "local",
40     "return",
41     "const"
42 };
43 static size_t num_keywords_qc = sizeof(keywords_qc) / sizeof(keywords_qc[0]);
44
45 /* For fte/gmgqcc */
46 static const char *keywords_fg[] = {
47     "switch", "case", "default",
48     "struct", "union",
49     "break", "continue",
50     "typedef",
51     "goto",
52
53     "__builtin_debug_printtype"
54 };
55 static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]);
56
57 /*
58  * Lexer code
59  */
60
61 static char* *lex_filenames;
62
63 static void lexerror(lex_file *lex, const char *fmt, ...)
64 {
65     va_list ap;
66
67     va_start(ap, fmt);
68     if (lex)
69         con_vprintmsg(LVL_ERROR, lex->name, lex->sline, lex->column, "parse error", fmt, ap);
70     else
71         con_vprintmsg(LVL_ERROR, "", 0, 0, "parse error", fmt, ap);
72     va_end(ap);
73 }
74
75 static bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...)
76 {
77     bool    r;
78     lex_ctx ctx;
79     va_list ap;
80
81     ctx.file = lex->name;
82     ctx.line = lex->sline;
83
84     va_start(ap, fmt);
85     r = vcompile_warning(ctx, warntype, fmt, ap);
86     va_end(ap);
87     return r;
88 }
89
90
91 #if 0
92 token* token_new()
93 {
94     token *tok = (token*)mem_a(sizeof(token));
95     if (!tok)
96         return NULL;
97     memset(tok, 0, sizeof(*tok));
98     return tok;
99 }
100
101 void token_delete(token *self)
102 {
103     if (self->next && self->next->prev == self)
104         self->next->prev = self->prev;
105     if (self->prev && self->prev->next == self)
106         self->prev->next = self->next;
107     MEM_VECTOR_CLEAR(self, value);
108     mem_d(self);
109 }
110
111 token* token_copy(const token *cp)
112 {
113     token* self = token_new();
114     if (!self)
115         return NULL;
116     /* copy the value */
117     self->value_alloc = cp->value_count + 1;
118     self->value_count = cp->value_count;
119     self->value = (char*)mem_a(self->value_alloc);
120     if (!self->value) {
121         mem_d(self);
122         return NULL;
123     }
124     memcpy(self->value, cp->value, cp->value_count);
125     self->value[self->value_alloc-1] = 0;
126
127     /* rest */
128     self->ctx = cp->ctx;
129     self->ttype = cp->ttype;
130     memcpy(&self->constval, &cp->constval, sizeof(self->constval));
131     return self;
132 }
133
134 void token_delete_all(token *t)
135 {
136     token *n;
137
138     do {
139         n = t->next;
140         token_delete(t);
141         t = n;
142     } while(t);
143 }
144
145 token* token_copy_all(const token *cp)
146 {
147     token *cur;
148     token *out;
149
150     out = cur = token_copy(cp);
151     if (!out)
152         return NULL;
153
154     while (cp->next) {
155         cp = cp->next;
156         cur->next = token_copy(cp);
157         if (!cur->next) {
158             token_delete_all(out);
159             return NULL;
160         }
161         cur->next->prev = cur;
162         cur = cur->next;
163     }
164
165     return out;
166 }
167 #else
168 static void lex_token_new(lex_file *lex)
169 {
170 #if 0
171     if (lex->tok)
172         token_delete(lex->tok);
173     lex->tok = token_new();
174 #else
175     if (lex->tok.value)
176         vec_shrinkto(lex->tok.value, 0);
177         
178     lex->tok.constval.t  = 0;
179     lex->tok.ctx.line    = lex->sline;
180     lex->tok.ctx.file    = lex->name;
181     lex->tok.ctx.column  = lex->column;
182 #endif
183 }
184 #endif
185
186 lex_file* lex_open(const char *file)
187 {
188     lex_file *lex;
189     FILE *in = fs_file_open(file, "rb");
190
191     if (!in) {
192         lexerror(NULL, "open failed: '%s'\n", file);
193         return NULL;
194     }
195
196     lex = (lex_file*)mem_a(sizeof(*lex));
197     if (!lex) {
198         fs_file_close(in);
199         lexerror(NULL, "out of memory\n");
200         return NULL;
201     }
202
203     memset(lex, 0, sizeof(*lex));
204
205     lex->file    = in;
206     lex->name    = util_strdup(file);
207     lex->line    = 1; /* we start counting at 1 */
208     lex->column  = 0;
209     lex->peekpos = 0;
210     lex->eof     = false;
211
212     vec_push(lex_filenames, lex->name);
213     return lex;
214 }
215
216 lex_file* lex_open_string(const char *str, size_t len, const char *name)
217 {
218     lex_file *lex;
219
220     lex = (lex_file*)mem_a(sizeof(*lex));
221     if (!lex) {
222         lexerror(NULL, "out of memory\n");
223         return NULL;
224     }
225
226     memset(lex, 0, sizeof(*lex));
227
228     lex->file = NULL;
229     lex->open_string        = str;
230     lex->open_string_length = len;
231     lex->open_string_pos    = 0;
232
233     lex->name    = util_strdup(name ? name : "<string-source>");
234     lex->line    = 1; /* we start counting at 1 */
235     lex->peekpos = 0;
236     lex->eof     = false;
237     lex->column  = 0;
238
239     vec_push(lex_filenames, lex->name);
240
241     return lex;
242 }
243
244 void lex_cleanup(void)
245 {
246     size_t i;
247     for (i = 0; i < vec_size(lex_filenames); ++i)
248         mem_d(lex_filenames[i]);
249     vec_free(lex_filenames);
250 }
251
252 void lex_close(lex_file *lex)
253 {
254     size_t i;
255     for (i = 0; i < vec_size(lex->frames); ++i)
256         mem_d(lex->frames[i].name);
257     vec_free(lex->frames);
258
259     if (lex->modelname)
260         vec_free(lex->modelname);
261
262     if (lex->file)
263         fs_file_close(lex->file);
264 #if 0
265     if (lex->tok)
266         token_delete(lex->tok);
267 #else
268     vec_free(lex->tok.value);
269 #endif
270     /* mem_d(lex->name); collected in lex_filenames */
271     mem_d(lex);
272 }
273
274 static int lex_fgetc(lex_file *lex)
275 {
276     if (lex->file) {
277         lex->column++;
278         return fs_file_getc(lex->file);
279     }
280     if (lex->open_string) {
281         if (lex->open_string_pos >= lex->open_string_length)
282             return EOF;
283         lex->column++;
284         return lex->open_string[lex->open_string_pos++];
285     }
286     return EOF;
287 }
288
289 /* Get or put-back data
290  * The following to functions do NOT understand what kind of data they
291  * are working on.
292  * The are merely wrapping get/put in order to count line numbers.
293  */
294 static void lex_ungetch(lex_file *lex, int ch);
295 static int lex_try_trigraph(lex_file *lex, int old)
296 {
297     int c2, c3;
298     c2 = lex_fgetc(lex);
299     if (!lex->push_line && c2 == '\n') {
300         lex->line++;
301         lex->column = 0;
302     }
303     
304     if (c2 != '?') {
305         lex_ungetch(lex, c2);
306         return old;
307     }
308
309     c3 = lex_fgetc(lex);
310     if (!lex->push_line && c3 == '\n') {
311         lex->line++;
312         lex->column = 0;
313     }
314     
315     switch (c3) {
316         case '=': return '#';
317         case '/': return '\\';
318         case '\'': return '^';
319         case '(': return '[';
320         case ')': return ']';
321         case '!': return '|';
322         case '<': return '{';
323         case '>': return '}';
324         case '-': return '~';
325         default:
326             lex_ungetch(lex, c3);
327             lex_ungetch(lex, c2);
328             return old;
329     }
330 }
331
332 static int lex_try_digraph(lex_file *lex, int ch)
333 {
334     int c2;
335     c2 = lex_fgetc(lex);
336     /* we just used fgetc() so count lines
337      * need to offset a \n the ungetch would recognize
338      */
339     if (!lex->push_line && c2 == '\n')
340         lex->line++;
341     if      (ch == '<' && c2 == ':')
342         return '[';
343     else if (ch == ':' && c2 == '>')
344         return ']';
345     else if (ch == '<' && c2 == '%')
346         return '{';
347     else if (ch == '%' && c2 == '>')
348         return '}';
349     else if (ch == '%' && c2 == ':')
350         return '#';
351     lex_ungetch(lex, c2);
352     return ch;
353 }
354
355 static int lex_getch(lex_file *lex)
356 {
357     int ch;
358
359     if (lex->peekpos) {
360         lex->peekpos--;
361         if (!lex->push_line && lex->peek[lex->peekpos] == '\n')
362             lex->line++;
363         return lex->peek[lex->peekpos];
364     }
365
366     ch = lex_fgetc(lex);
367     if (!lex->push_line && ch == '\n')
368         lex->line++;
369     else if (ch == '?')
370         return lex_try_trigraph(lex, ch);
371     else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
372         return lex_try_digraph(lex, ch);
373     return ch;
374 }
375
376 static void lex_ungetch(lex_file *lex, int ch)
377 {
378     lex->peek[lex->peekpos++] = ch;
379     lex->column--;
380     if (!lex->push_line && ch == '\n') {
381         lex->line--;
382         lex->column = 0;
383     }
384 }
385
386 /* classify characters
387  * some additions to the is*() functions of ctype.h
388  */
389
390 /* Idents are alphanumberic, but they start with alpha or _ */
391 static bool isident_start(int ch)
392 {
393     return isalpha(ch) || ch == '_';
394 }
395
396 static bool isident(int ch)
397 {
398     return isident_start(ch) || isdigit(ch);
399 }
400
401 /* isxdigit_only is used when we already know it's not a digit
402  * and want to see if it's a hex digit anyway.
403  */
404 static bool isxdigit_only(int ch)
405 {
406     return (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
407 }
408
409 /* Append a character to the token buffer */
410 static void lex_tokench(lex_file *lex, int ch)
411 {
412     vec_push(lex->tok.value, ch);
413 }
414
415 /* Append a trailing null-byte */
416 static void lex_endtoken(lex_file *lex)
417 {
418     vec_push(lex->tok.value, 0);
419     vec_shrinkby(lex->tok.value, 1);
420 }
421
422 static bool lex_try_pragma(lex_file *lex)
423 {
424     int ch;
425     char *pragma  = NULL;
426     char *command = NULL;
427     char *param   = NULL;
428     size_t line;
429
430     if (lex->flags.preprocessing)
431         return false;
432
433     line = lex->line;
434
435     ch = lex_getch(lex);
436     if (ch != '#') {
437         lex_ungetch(lex, ch);
438         return false;
439     }
440
441     for (ch = lex_getch(lex); vec_size(pragma) < 8 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
442         vec_push(pragma, ch);
443     vec_push(pragma, 0);
444
445     if (ch != ' ' || strcmp(pragma, "pragma")) {
446         lex_ungetch(lex, ch);
447         goto unroll;
448     }
449
450     for (ch = lex_getch(lex); vec_size(command) < 32 && ch >= 'a' && ch <= 'z'; ch = lex_getch(lex))
451         vec_push(command, ch);
452     vec_push(command, 0);
453
454     if (ch != '(') {
455         lex_ungetch(lex, ch);
456         goto unroll;
457     }
458
459     for (ch = lex_getch(lex); vec_size(param) < 1024 && ch != ')' && ch != '\n'; ch = lex_getch(lex))
460         vec_push(param, ch);
461     vec_push(param, 0);
462
463     if (ch != ')') {
464         lex_ungetch(lex, ch);
465         goto unroll;
466     }
467
468     if (!strcmp(command, "push")) {
469         if (!strcmp(param, "line")) {
470             lex->push_line++;
471             if (lex->push_line == 1)
472                 --line;
473         }
474         else
475             goto unroll;
476     }
477     else if (!strcmp(command, "pop")) {
478         if (!strcmp(param, "line")) {
479             if (lex->push_line)
480                 lex->push_line--;
481             if (lex->push_line == 0)
482                 --line;
483         }
484         else
485             goto unroll;
486     }
487     else if (!strcmp(command, "file")) {
488         lex->name = util_strdup(param);
489         vec_push(lex_filenames, lex->name);
490     }
491     else if (!strcmp(command, "line")) {
492         line = strtol(param, NULL, 0)-1;
493     }
494     else
495         goto unroll;
496
497     lex->line = line;
498     while (ch != '\n' && ch != EOF)
499         ch = lex_getch(lex);
500     vec_free(command);
501     vec_free(param);
502     vec_free(pragma);
503     return true;
504
505 unroll:
506     if (command) {
507         vec_pop(command);
508         while (vec_size(command)) {
509             lex_ungetch(lex, (unsigned char)vec_last(command));
510             vec_pop(command);
511         }
512         vec_free(command);
513         lex_ungetch(lex, ' ');
514     }
515     if (param) {
516         vec_pop(param);
517         while (vec_size(param)) {
518             lex_ungetch(lex, (unsigned char)vec_last(param));
519             vec_pop(param);
520         }
521         vec_free(param);
522         lex_ungetch(lex, ' ');
523     }
524     if (pragma) {
525         vec_pop(pragma);
526         while (vec_size(pragma)) {
527             lex_ungetch(lex, (unsigned char)vec_last(pragma));
528             vec_pop(pragma);
529         }
530         vec_free(pragma);
531     }
532     lex_ungetch(lex, '#');
533
534     lex->line = line;
535     return false;
536 }
537
538 /* Skip whitespace and comments and return the first
539  * non-white character.
540  * As this makes use of the above getch() ungetch() functions,
541  * we don't need to care at all about line numbering anymore.
542  *
543  * In theory, this function should only be used at the beginning
544  * of lexing, or when we *know* the next character is part of the token.
545  * Otherwise, if the parser throws an error, the linenumber may not be
546  * the line of the error, but the line of the next token AFTER the error.
547  *
548  * This is currently only problematic when using c-like string-continuation,
549  * since comments and whitespaces are allowed between 2 such strings.
550  * Example:
551 printf(   "line one\n"
552 // A comment
553           "A continuation of the previous string"
554 // This line is skipped
555       , foo);
556
557  * In this case, if the parse decides it didn't actually want a string,
558  * and uses lex->line to print an error, it will show the ', foo);' line's
559  * linenumber.
560  *
561  * On the other hand, the parser is supposed to remember the line of the next
562  * token's beginning. In this case we would want skipwhite() to be called
563  * AFTER reading a token, so that the parser, before reading the NEXT token,
564  * doesn't store teh *comment's* linenumber, but the actual token's linenumber.
565  *
566  * THIS SOLUTION
567  *    here is to store the line of the first character after skipping
568  *    the initial whitespace in lex->sline, this happens in lex_do.
569  */
570 static int lex_skipwhite(lex_file *lex, bool hadwhite)
571 {
572     int ch = 0;
573     bool haswhite = hadwhite;
574
575     do
576     {
577         ch = lex_getch(lex);
578         while (ch != EOF && isspace(ch)) {
579             if (ch == '\n') {
580                 if (lex_try_pragma(lex))
581                     continue;
582             }
583             if (lex->flags.preprocessing) {
584                 if (ch == '\n') {
585                     /* end-of-line */
586                     /* see if there was whitespace first */
587                     if (haswhite) { /* (vec_size(lex->tok.value)) { */
588                         lex_ungetch(lex, ch);
589                         lex_endtoken(lex);
590                         return TOKEN_WHITE;
591                     }
592                     /* otherwise return EOL */
593                     return TOKEN_EOL;
594                 }
595                 haswhite = true;
596                 lex_tokench(lex, ch);
597             }
598             ch = lex_getch(lex);
599         }
600
601         if (ch == '/') {
602             ch = lex_getch(lex);
603             if (ch == '/')
604             {
605                 /* one line comment */
606                 ch = lex_getch(lex);
607
608                 if (lex->flags.preprocessing) {
609                     haswhite = true;
610                     /*
611                     lex_tokench(lex, '/');
612                     lex_tokench(lex, '/');
613                     */
614                     lex_tokench(lex, ' ');
615                     lex_tokench(lex, ' ');
616                 }
617
618                 while (ch != EOF && ch != '\n') {
619                     if (lex->flags.preprocessing)
620                         lex_tokench(lex, ' '); /* ch); */
621                     ch = lex_getch(lex);
622                 }
623                 if (lex->flags.preprocessing) {
624                     lex_ungetch(lex, '\n');
625                     lex_endtoken(lex);
626                     return TOKEN_WHITE;
627                 }
628                 continue;
629             }
630             if (ch == '*')
631             {
632                 /* multiline comment */
633                 if (lex->flags.preprocessing) {
634                     haswhite = true;
635                     /*
636                     lex_tokench(lex, '/');
637                     lex_tokench(lex, '*');
638                     */
639                     lex_tokench(lex, ' ');
640                     lex_tokench(lex, ' ');
641                 }
642
643                 while (ch != EOF)
644                 {
645                     ch = lex_getch(lex);
646                     if (ch == '*') {
647                         ch = lex_getch(lex);
648                         if (ch == '/') {
649                             if (lex->flags.preprocessing) {
650                                 /*
651                                 lex_tokench(lex, '*');
652                                 lex_tokench(lex, '/');
653                                 */
654                                 lex_tokench(lex, ' ');
655                                 lex_tokench(lex, ' ');
656                             }
657                             break;
658                         }
659                         lex_ungetch(lex, ch);
660                     }
661                     if (lex->flags.preprocessing) {
662                         if (ch == '\n')
663                             lex_tokench(lex, '\n');
664                         else
665                             lex_tokench(lex, ' '); /* ch); */
666                     }
667                 }
668                 ch = ' '; /* cause TRUE in the isspace check */
669                 continue;
670             }
671             /* Otherwise roll back to the slash and break out of the loop */
672             lex_ungetch(lex, ch);
673             ch = '/';
674             break;
675         }
676     } while (ch != EOF && isspace(ch));
677
678     if (haswhite) {
679         lex_endtoken(lex);
680         lex_ungetch(lex, ch);
681         return TOKEN_WHITE;
682     }
683     return ch;
684 }
685
686 /* Get a token */
687 static bool GMQCC_WARN lex_finish_ident(lex_file *lex)
688 {
689     int ch;
690
691     ch = lex_getch(lex);
692     while (ch != EOF && isident(ch))
693     {
694         lex_tokench(lex, ch);
695         ch = lex_getch(lex);
696     }
697
698     /* last ch was not an ident ch: */
699     lex_ungetch(lex, ch);
700
701     return true;
702 }
703
704 /* read one ident for the frame list */
705 static int lex_parse_frame(lex_file *lex)
706 {
707     int ch;
708
709     lex_token_new(lex);
710
711     ch = lex_getch(lex);
712     while (ch != EOF && ch != '\n' && isspace(ch))
713         ch = lex_getch(lex);
714
715     if (ch == '\n')
716         return 1;
717
718     if (!isident_start(ch)) {
719         lexerror(lex, "invalid framename, must start with one of a-z or _, got %c", ch);
720         return -1;
721     }
722
723     lex_tokench(lex, ch);
724     if (!lex_finish_ident(lex))
725         return -1;
726     lex_endtoken(lex);
727     return 0;
728 }
729
730 /* read a list of $frames */
731 static bool lex_finish_frames(lex_file *lex)
732 {
733     do {
734         size_t i;
735         int    rc;
736         frame_macro m;
737
738         rc = lex_parse_frame(lex);
739         if (rc > 0) /* end of line */
740             return true;
741         if (rc < 0) /* error */
742             return false;
743
744         for (i = 0; i < vec_size(lex->frames); ++i) {
745             if (!strcmp(lex->tok.value, lex->frames[i].name)) {
746                 lex->frames[i].value = lex->framevalue++;
747                 if (lexwarn(lex, WARN_FRAME_MACROS, "duplicate frame macro defined: `%s`", lex->tok.value))
748                     return false;
749                 break;
750             }
751         }
752         if (i < vec_size(lex->frames))
753             continue;
754
755         m.value = lex->framevalue++;
756         m.name = util_strdup(lex->tok.value);
757         vec_shrinkto(lex->tok.value, 0);
758         vec_push(lex->frames, m);
759     } while (true);
760
761     return false;
762 }
763
764 static int GMQCC_WARN lex_finish_string(lex_file *lex, int quote)
765 {
766     uchar_t chr;
767     int ch = 0;
768     int nextch;
769     bool hex;
770     char u8buf[8]; /* way more than enough */
771     int  u8len, uc;
772
773     while (ch != EOF)
774     {
775         ch = lex_getch(lex);
776         if (ch == quote)
777             return TOKEN_STRINGCONST;
778
779         if (lex->flags.preprocessing && ch == '\\') {
780             lex_tokench(lex, ch);
781             ch = lex_getch(lex);
782             if (ch == EOF) {
783                 lexerror(lex, "unexpected end of file");
784                 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
785                 return (lex->tok.ttype = TOKEN_ERROR);
786             }
787             lex_tokench(lex, ch);
788         }
789         else if (ch == '\\') {
790             ch = lex_getch(lex);
791             if (ch == EOF) {
792                 lexerror(lex, "unexpected end of file");
793                 lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
794                 return (lex->tok.ttype = TOKEN_ERROR);
795             }
796
797             switch (ch) {
798             case '\\': break;
799             case '\'': break;
800             case '"':  break;
801             case 'a':  ch = '\a'; break;
802             case 'b':  ch = '\b'; break;
803             case 'r':  ch = '\r'; break;
804             case 'n':  ch = '\n'; break;
805             case 't':  ch = '\t'; break;
806             case 'f':  ch = '\f'; break;
807             case 'v':  ch = '\v'; break;
808             case 'x':
809             case 'X':
810                 /* same procedure as in fteqcc */
811                 ch = 0;
812                 nextch = lex_getch(lex);
813                 if      (nextch >= '0' && nextch <= '9')
814                     ch += nextch - '0';
815                 else if (nextch >= 'a' && nextch <= 'f')
816                     ch += nextch - 'a' + 10;
817                 else if (nextch >= 'A' && nextch <= 'F')
818                     ch += nextch - 'A' + 10;
819                 else {
820                     lexerror(lex, "bad character code");
821                     lex_ungetch(lex, nextch);
822                     return (lex->tok.ttype = TOKEN_ERROR);
823                 }
824
825                 ch *= 0x10;
826                 nextch = lex_getch(lex);
827                 if      (nextch >= '0' && nextch <= '9')
828                     ch += nextch - '0';
829                 else if (nextch >= 'a' && nextch <= 'f')
830                     ch += nextch - 'a' + 10;
831                 else if (nextch >= 'A' && nextch <= 'F')
832                     ch += nextch - 'A' + 10;
833                 else {
834                     lexerror(lex, "bad character code");
835                     lex_ungetch(lex, nextch);
836                     return (lex->tok.ttype = TOKEN_ERROR);
837                 }
838                 break;
839
840             /* fteqcc support */
841             case '0': case '1': case '2': case '3':
842             case '4': case '5': case '6': case '7':
843             case '8': case '9':
844                 ch = 18 + ch - '0';
845                 break;
846             case '<':  ch = 29; break;
847             case '-':  ch = 30; break;
848             case '>':  ch = 31; break;
849             case '[':  ch = 16; break;
850             case ']':  ch = 17; break;
851             case '{':
852                 chr = 0;
853                 nextch = lex_getch(lex);
854                 hex = (nextch == 'x');
855                 if (!hex)
856                     lex_ungetch(lex, nextch);
857                 for (nextch = lex_getch(lex); nextch != '}'; nextch = lex_getch(lex)) {
858                     if (!hex) {
859                         if (nextch >= '0' && nextch <= '9')
860                             chr = chr * 10 + nextch - '0';
861                         else {
862                             lexerror(lex, "bad character code");
863                             return (lex->tok.ttype = TOKEN_ERROR);
864                         }
865                     } else {
866                         if (nextch >= '0' && nextch <= '9')
867                             chr = chr * 0x10 + nextch - '0';
868                         else if (nextch >= 'a' && nextch <= 'f')
869                             chr = chr * 0x10 + nextch - 'a' + 10;
870                         else if (nextch >= 'A' && nextch <= 'F')
871                             chr = chr * 0x10 + nextch - 'A' + 10;
872                         else {
873                             lexerror(lex, "bad character code");
874                             return (lex->tok.ttype = TOKEN_ERROR);
875                         }
876                     }
877                     if (chr > 0x10FFFF || (!OPTS_FLAG(UTF8) && chr > 255))
878                     {
879                         lexerror(lex, "character code out of range");
880                         return (lex->tok.ttype = TOKEN_ERROR);
881                     }
882                 }
883                 if (OPTS_FLAG(UTF8) && chr >= 128) {
884                     u8len = u8_fromchar(chr, u8buf, sizeof(u8buf));
885                     if (!u8len)
886                         ch = 0;
887                     else {
888                         --u8len;
889                         lex->column += u8len;
890                         for (uc = 0; uc < u8len; ++uc)
891                             lex_tokench(lex, u8buf[uc]);
892                         /* the last character will be inserted with the tokench() call
893                          * below the switch
894                          */
895                         ch = u8buf[uc];
896                     }
897                 }
898                 else
899                     ch = chr;
900                 break;
901             case '\n':  ch = '\n'; break;
902
903             default:
904                 lexwarn(lex, WARN_UNKNOWN_CONTROL_SEQUENCE, "unrecognized control sequence: \\%c", ch);
905                 /* so we just add the character plus backslash no matter what it actually is */
906                 lex_tokench(lex, '\\');
907             }
908             /* add the character finally */
909             lex_tokench(lex, ch);
910         }
911         else
912             lex_tokench(lex, ch);
913     }
914     lexerror(lex, "unexpected end of file within string constant");
915     lex_ungetch(lex, EOF); /* next token to be TOKEN_EOF */
916     return (lex->tok.ttype = TOKEN_ERROR);
917 }
918
919 static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
920 {
921     bool ishex = false;
922
923     int  ch = lastch;
924
925     /* parse a number... */
926     if (ch == '.')
927         lex->tok.ttype = TOKEN_FLOATCONST;
928     else
929         lex->tok.ttype = TOKEN_INTCONST;
930
931     lex_tokench(lex, ch);
932
933     ch = lex_getch(lex);
934     if (ch != '.' && !isdigit(ch))
935     {
936         if (lastch != '0' || ch != 'x')
937         {
938             /* end of the number or EOF */
939             lex_ungetch(lex, ch);
940             lex_endtoken(lex);
941
942             lex->tok.constval.i = lastch - '0';
943             return lex->tok.ttype;
944         }
945
946         ishex = true;
947     }
948
949     /* EOF would have been caught above */
950
951     if (ch != '.')
952     {
953         lex_tokench(lex, ch);
954         ch = lex_getch(lex);
955         while (isdigit(ch) || (ishex && isxdigit_only(ch)))
956         {
957             lex_tokench(lex, ch);
958             ch = lex_getch(lex);
959         }
960     }
961     /* NOT else, '.' can come from above as well */
962     if (lex->tok.ttype != TOKEN_FLOATCONST && ch == '.' && !ishex)
963     {
964         /* Allow floating comma in non-hex mode */
965         lex->tok.ttype = TOKEN_FLOATCONST;
966         lex_tokench(lex, ch);
967
968         /* continue digits-only */
969         ch = lex_getch(lex);
970         while (isdigit(ch))
971         {
972             lex_tokench(lex, ch);
973             ch = lex_getch(lex);
974         }
975     }
976     /* put back the last character */
977     /* but do not put back the trailing 'f' or a float */
978     if (lex->tok.ttype == TOKEN_FLOATCONST && ch == 'f')
979         ch = lex_getch(lex);
980
981     /* generally we don't want words to follow numbers: */
982     if (isident(ch)) {
983         lexerror(lex, "unexpected trailing characters after number");
984         return (lex->tok.ttype = TOKEN_ERROR);
985     }
986     lex_ungetch(lex, ch);
987
988     lex_endtoken(lex);
989     if (lex->tok.ttype == TOKEN_FLOATCONST)
990         lex->tok.constval.f = strtod(lex->tok.value, NULL);
991     else
992         lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
993     return lex->tok.ttype;
994 }
995
996 int lex_do(lex_file *lex)
997 {
998     int ch, nextch, thirdch;
999     bool hadwhite = false;
1000
1001     lex_token_new(lex);
1002 #if 0
1003     if (!lex->tok)
1004         return TOKEN_FATAL;
1005 #endif
1006
1007     while (true) {
1008         ch = lex_skipwhite(lex, hadwhite);
1009         hadwhite = true;
1010         if (!lex->flags.mergelines || ch != '\\')
1011             break;
1012         ch = lex_getch(lex);
1013         if (ch == '\r')
1014             ch = lex_getch(lex);
1015         if (ch != '\n') {
1016             lex_ungetch(lex, ch);
1017             ch = '\\';
1018             break;
1019         }
1020         /* we reached a linemerge */
1021         lex_tokench(lex, '\n');
1022         continue;
1023     }
1024
1025     if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
1026         return (lex->tok.ttype = ch);
1027     }
1028
1029     lex->sline = lex->line;
1030     lex->tok.ctx.line = lex->sline;
1031     lex->tok.ctx.file = lex->name;
1032
1033     if (lex->eof)
1034         return (lex->tok.ttype = TOKEN_FATAL);
1035
1036     if (ch == EOF) {
1037         lex->eof = true;
1038         return (lex->tok.ttype = TOKEN_EOF);
1039     }
1040
1041     /* modelgen / spiritgen commands */
1042     if (ch == '$' && !lex->flags.preprocessing) {
1043         const char *v;
1044         size_t frame;
1045
1046         ch = lex_getch(lex);
1047         if (!isident_start(ch)) {
1048             lexerror(lex, "hanging '$' modelgen/spritegen command line");
1049             return lex_do(lex);
1050         }
1051         lex_tokench(lex, ch);
1052         if (!lex_finish_ident(lex))
1053             return (lex->tok.ttype = TOKEN_ERROR);
1054         lex_endtoken(lex);
1055         /* skip the known commands */
1056         v = lex->tok.value;
1057
1058         if (!strcmp(v, "frame") || !strcmp(v, "framesave"))
1059         {
1060             /* frame/framesave command works like an enum
1061              * similar to fteqcc we handle this in the lexer.
1062              * The reason for this is that it is sensitive to newlines,
1063              * which the parser is unaware of
1064              */
1065             if (!lex_finish_frames(lex))
1066                  return (lex->tok.ttype = TOKEN_ERROR);
1067             return lex_do(lex);
1068         }
1069
1070         if (!strcmp(v, "framevalue"))
1071         {
1072             ch = lex_getch(lex);
1073             while (ch != EOF && isspace(ch) && ch != '\n')
1074                 ch = lex_getch(lex);
1075
1076             if (!isdigit(ch)) {
1077                 lexerror(lex, "$framevalue requires an integer parameter");
1078                 return lex_do(lex);
1079             }
1080
1081             lex_token_new(lex);
1082             lex->tok.ttype = lex_finish_digit(lex, ch);
1083             lex_endtoken(lex);
1084             if (lex->tok.ttype != TOKEN_INTCONST) {
1085                 lexerror(lex, "$framevalue requires an integer parameter");
1086                 return lex_do(lex);
1087             }
1088             lex->framevalue = lex->tok.constval.i;
1089             return lex_do(lex);
1090         }
1091
1092         if (!strcmp(v, "framerestore"))
1093         {
1094             int rc;
1095
1096             lex_token_new(lex);
1097
1098             rc = lex_parse_frame(lex);
1099
1100             if (rc > 0) {
1101                 lexerror(lex, "$framerestore requires a framename parameter");
1102                 return lex_do(lex);
1103             }
1104             if (rc < 0)
1105                 return (lex->tok.ttype = TOKEN_FATAL);
1106
1107             v = lex->tok.value;
1108             for (frame = 0; frame < vec_size(lex->frames); ++frame) {
1109                 if (!strcmp(v, lex->frames[frame].name)) {
1110                     lex->framevalue = lex->frames[frame].value;
1111                     return lex_do(lex);
1112                 }
1113             }
1114             lexerror(lex, "unknown framename `%s`", v);
1115             return lex_do(lex);
1116         }
1117
1118         if (!strcmp(v, "modelname"))
1119         {
1120             int rc;
1121
1122             lex_token_new(lex);
1123
1124             rc = lex_parse_frame(lex);
1125
1126             if (rc > 0) {
1127                 lexerror(lex, "$modelname requires a parameter");
1128                 return lex_do(lex);
1129             }
1130             if (rc < 0)
1131                 return (lex->tok.ttype = TOKEN_FATAL);
1132
1133             if (lex->modelname) {
1134                 frame_macro m;
1135                 m.value = lex->framevalue;
1136                 m.name = lex->modelname;
1137                 lex->modelname = NULL;
1138                 vec_push(lex->frames, m);
1139             }
1140             lex->modelname = lex->tok.value;
1141             lex->tok.value = NULL;
1142             return lex_do(lex);
1143         }
1144
1145         if (!strcmp(v, "flush"))
1146         {
1147             size_t fi;
1148             for (fi = 0; fi < vec_size(lex->frames); ++fi)
1149                 mem_d(lex->frames[fi].name);
1150             vec_free(lex->frames);
1151             /* skip line (fteqcc does it too) */
1152             ch = lex_getch(lex);
1153             while (ch != EOF && ch != '\n')
1154                 ch = lex_getch(lex);
1155             return lex_do(lex);
1156         }
1157
1158         if (!strcmp(v, "cd") ||
1159             !strcmp(v, "origin") ||
1160             !strcmp(v, "base") ||
1161             !strcmp(v, "flags") ||
1162             !strcmp(v, "scale") ||
1163             !strcmp(v, "skin"))
1164         {
1165             /* skip line */
1166             ch = lex_getch(lex);
1167             while (ch != EOF && ch != '\n')
1168                 ch = lex_getch(lex);
1169             return lex_do(lex);
1170         }
1171
1172         for (frame = 0; frame < vec_size(lex->frames); ++frame) {
1173             if (!strcmp(v, lex->frames[frame].name)) {
1174                 lex->tok.constval.i = lex->frames[frame].value;
1175                 return (lex->tok.ttype = TOKEN_INTCONST);
1176             }
1177         }
1178
1179         lexerror(lex, "invalid frame macro");
1180         return lex_do(lex);
1181     }
1182
1183     /* single-character tokens */
1184     switch (ch)
1185     {
1186         case '[':
1187             nextch = lex_getch(lex);
1188             if (nextch == '[') {
1189                 lex_tokench(lex, ch);
1190                 lex_tokench(lex, nextch);
1191                 lex_endtoken(lex);
1192                 return (lex->tok.ttype = TOKEN_ATTRIBUTE_OPEN);
1193             }
1194             lex_ungetch(lex, nextch);
1195             /* FALL THROUGH */
1196         case '(':
1197         case ':':
1198         case '?':
1199             lex_tokench(lex, ch);
1200             lex_endtoken(lex);
1201             if (lex->flags.noops)
1202                 return (lex->tok.ttype = ch);
1203             else
1204                 return (lex->tok.ttype = TOKEN_OPERATOR);
1205
1206         case ']':
1207             if (lex->flags.noops) {
1208                 nextch = lex_getch(lex);
1209                 if (nextch == ']') {
1210                     lex_tokench(lex, ch);
1211                     lex_tokench(lex, nextch);
1212                     lex_endtoken(lex);
1213                     return (lex->tok.ttype = TOKEN_ATTRIBUTE_CLOSE);
1214                 }
1215                 lex_ungetch(lex, nextch);
1216             }
1217             /* FALL THROUGH */
1218         case ')':
1219         case ';':
1220         case '{':
1221         case '}':
1222
1223         case '#':
1224             lex_tokench(lex, ch);
1225             lex_endtoken(lex);
1226             return (lex->tok.ttype = ch);
1227         default:
1228             break;
1229     }
1230
1231     if (ch == '.') {
1232         nextch = lex_getch(lex);
1233         /* digits starting with a dot */
1234         if (isdigit(nextch)) {
1235             lex_ungetch(lex, nextch);
1236             lex->tok.ttype = lex_finish_digit(lex, ch);
1237             lex_endtoken(lex);
1238             return lex->tok.ttype;
1239         }
1240         lex_ungetch(lex, nextch);
1241     }
1242
1243     if (lex->flags.noops)
1244     {
1245         /* Detect characters early which are normally
1246          * operators OR PART of an operator.
1247          */
1248         switch (ch)
1249         {
1250             /*
1251             case '+':
1252             case '-':
1253             */
1254             case '*':
1255             case '/':
1256             case '<':
1257             case '>':
1258             case '=':
1259             case '&':
1260             case '|':
1261             case '^':
1262             case '~':
1263             case ',':
1264             case '!':
1265                 lex_tokench(lex, ch);
1266                 lex_endtoken(lex);
1267                 return (lex->tok.ttype = ch);
1268             default:
1269                 break;
1270         }
1271     }
1272
1273     if (ch == '.')
1274     {
1275         lex_tokench(lex, ch);
1276         /* peak ahead once */
1277         nextch = lex_getch(lex);
1278         if (nextch != '.') {
1279             lex_ungetch(lex, nextch);
1280             lex_endtoken(lex);
1281             if (lex->flags.noops)
1282                 return (lex->tok.ttype = ch);
1283             else
1284                 return (lex->tok.ttype = TOKEN_OPERATOR);
1285         }
1286         /* peak ahead again */
1287         nextch = lex_getch(lex);
1288         if (nextch != '.') {
1289             lex_ungetch(lex, nextch);
1290             lex_ungetch(lex, '.');
1291             lex_endtoken(lex);
1292             if (lex->flags.noops)
1293                 return (lex->tok.ttype = ch);
1294             else
1295                 return (lex->tok.ttype = TOKEN_OPERATOR);
1296         }
1297         /* fill the token to be "..." */
1298         lex_tokench(lex, ch);
1299         lex_tokench(lex, ch);
1300         lex_endtoken(lex);
1301         return (lex->tok.ttype = TOKEN_DOTS);
1302     }
1303
1304     if (ch == ',' || ch == '.') {
1305         lex_tokench(lex, ch);
1306         lex_endtoken(lex);
1307         return (lex->tok.ttype = TOKEN_OPERATOR);
1308     }
1309
1310     if (ch == '+' || ch == '-' || /* ++, --, +=, -=  and -> as well! */
1311         ch == '>' || ch == '<' || /* <<, >>, <=, >=                  */
1312         ch == '=' || ch == '!' || /* <=>, ==, !=                     */
1313         ch == '&' || ch == '|' || /* &&, ||, &=, |=                  */
1314         ch == '~'                 /* ~=, ~                           */
1315     )  {
1316         lex_tokench(lex, ch);
1317
1318         nextch = lex_getch(lex);
1319         if ((nextch == '=' && ch != '<') || (nextch == ch && ch != '!')) {
1320             lex_tokench(lex, nextch);
1321         } else if (ch == '<' && nextch == '=') {
1322             lex_tokench(lex, nextch);
1323             if ((thirdch = lex_getch(lex)) == '>')
1324                 lex_tokench(lex, thirdch);
1325             else
1326                 lex_ungetch(lex, thirdch);
1327
1328         } else if (ch == '-' && nextch == '>') {
1329             lex_tokench(lex, nextch);
1330         } else if (ch == '&' && nextch == '~') {
1331             thirdch = lex_getch(lex);
1332             if (thirdch != '=') {
1333                 lex_ungetch(lex, thirdch);
1334                 lex_ungetch(lex, nextch);
1335             }
1336             else {
1337                 lex_tokench(lex, nextch);
1338                 lex_tokench(lex, thirdch);
1339             }
1340         }
1341         else if (lex->flags.preprocessing &&
1342                  ch == '-' && isdigit(nextch))
1343         {
1344             lex->tok.ttype = lex_finish_digit(lex, nextch);
1345             if (lex->tok.ttype == TOKEN_INTCONST)
1346                 lex->tok.constval.i = -lex->tok.constval.i;
1347             else
1348                 lex->tok.constval.f = -lex->tok.constval.f;
1349             lex_endtoken(lex);
1350             return lex->tok.ttype;
1351         } else {
1352             lex_ungetch(lex, nextch);
1353         }
1354
1355         lex_endtoken(lex);
1356         return (lex->tok.ttype = TOKEN_OPERATOR);
1357     }
1358
1359     /*
1360     if (ch == '^' || ch == '~' || ch == '!')
1361     {
1362         lex_tokench(lex, ch);
1363         lex_endtoken(lex);
1364         return (lex->tok.ttype = TOKEN_OPERATOR);
1365     }
1366     */
1367
1368     if (ch == '*' || ch == '/') /* *=, /= */
1369     {
1370         lex_tokench(lex, ch);
1371
1372         nextch = lex_getch(lex);
1373         if (nextch == '=' || nextch == '*') {
1374             lex_tokench(lex, nextch);
1375         } else
1376             lex_ungetch(lex, nextch);
1377
1378         lex_endtoken(lex);
1379         return (lex->tok.ttype = TOKEN_OPERATOR);
1380     }
1381
1382     if (ch == '%') {
1383         lex_tokench(lex, ch);
1384         lex_endtoken(lex);
1385         return (lex->tok.ttype = TOKEN_OPERATOR);
1386     }
1387
1388     if (isident_start(ch))
1389     {
1390         const char *v;
1391
1392         lex_tokench(lex, ch);
1393         if (!lex_finish_ident(lex)) {
1394             /* error? */
1395             return (lex->tok.ttype = TOKEN_ERROR);
1396         }
1397         lex_endtoken(lex);
1398         lex->tok.ttype = TOKEN_IDENT;
1399
1400         v = lex->tok.value;
1401         if (!strcmp(v, "void")) {
1402             lex->tok.ttype = TOKEN_TYPENAME;
1403             lex->tok.constval.t = TYPE_VOID;
1404         } else if (!strcmp(v, "int")) {
1405             lex->tok.ttype = TOKEN_TYPENAME;
1406             lex->tok.constval.t = TYPE_INTEGER;
1407         } else if (!strcmp(v, "float")) {
1408             lex->tok.ttype = TOKEN_TYPENAME;
1409             lex->tok.constval.t = TYPE_FLOAT;
1410         } else if (!strcmp(v, "string")) {
1411             lex->tok.ttype = TOKEN_TYPENAME;
1412             lex->tok.constval.t = TYPE_STRING;
1413         } else if (!strcmp(v, "entity")) {
1414             lex->tok.ttype = TOKEN_TYPENAME;
1415             lex->tok.constval.t = TYPE_ENTITY;
1416         } else if (!strcmp(v, "vector")) {
1417             lex->tok.ttype = TOKEN_TYPENAME;
1418             lex->tok.constval.t = TYPE_VECTOR;
1419         } else {
1420             size_t kw;
1421             for (kw = 0; kw < num_keywords_qc; ++kw) {
1422                 if (!strcmp(v, keywords_qc[kw]))
1423                     return (lex->tok.ttype = TOKEN_KEYWORD);
1424             }
1425             if (OPTS_OPTION_U32(OPTION_STANDARD) != COMPILER_QCC) {
1426                 for (kw = 0; kw < num_keywords_fg; ++kw) {
1427                     if (!strcmp(v, keywords_fg[kw]))
1428                         return (lex->tok.ttype = TOKEN_KEYWORD);
1429                 }
1430             }
1431         }
1432
1433         return lex->tok.ttype;
1434     }
1435
1436     if (ch == '"')
1437     {
1438         lex->flags.nodigraphs = true;
1439         if (lex->flags.preprocessing)
1440             lex_tokench(lex, ch);
1441         lex->tok.ttype = lex_finish_string(lex, '"');
1442         if (lex->flags.preprocessing)
1443             lex_tokench(lex, ch);
1444         while (!lex->flags.preprocessing && lex->tok.ttype == TOKEN_STRINGCONST)
1445         {
1446             /* Allow c style "string" "continuation" */
1447             ch = lex_skipwhite(lex, false);
1448             if (ch != '"') {
1449                 lex_ungetch(lex, ch);
1450                 break;
1451             }
1452
1453             lex->tok.ttype = lex_finish_string(lex, '"');
1454         }
1455         lex->flags.nodigraphs = false;
1456         lex_endtoken(lex);
1457         return lex->tok.ttype;
1458     }
1459
1460     if (ch == '\'')
1461     {
1462         /* we parse character constants like string,
1463          * but return TOKEN_CHARCONST, or a vector type if it fits...
1464          * Likewise actual unescaping has to be done by the parser.
1465          * The difference is we don't allow 'char' 'continuation'.
1466          */
1467         if (lex->flags.preprocessing)
1468             lex_tokench(lex, ch);
1469         lex->tok.ttype = lex_finish_string(lex, '\'');
1470         if (lex->flags.preprocessing)
1471             lex_tokench(lex, ch);
1472         lex_endtoken(lex);
1473
1474         lex->tok.ttype = TOKEN_CHARCONST;
1475          /* It's a vector if we can successfully scan 3 floats */
1476 #ifdef _MSC_VER
1477         if (sscanf_s(lex->tok.value, " %f %f %f ",
1478                    &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1479 #else
1480         if (sscanf(lex->tok.value, " %f %f %f ",
1481                    &lex->tok.constval.v.x, &lex->tok.constval.v.y, &lex->tok.constval.v.z) == 3)
1482 #endif
1483
1484         {
1485              lex->tok.ttype = TOKEN_VECTORCONST;
1486         }
1487         else
1488         {
1489             if (!lex->flags.preprocessing && strlen(lex->tok.value) > 1) {
1490                 uchar_t u8char;
1491                 /* check for a valid utf8 character */
1492                 if (!OPTS_FLAG(UTF8) || !u8_analyze(lex->tok.value, NULL, NULL, &u8char, 8)) {
1493                     if (lexwarn(lex, WARN_MULTIBYTE_CHARACTER,
1494                                 ( OPTS_FLAG(UTF8) ? "invalid multibyte character sequence `%s`"
1495                                                   : "multibyte character: `%s`" ),
1496                                 lex->tok.value))
1497                         return (lex->tok.ttype = TOKEN_ERROR);
1498                 }
1499                 else
1500                     lex->tok.constval.i = u8char;
1501             }
1502             else
1503                 lex->tok.constval.i = lex->tok.value[0];
1504         }
1505
1506         return lex->tok.ttype;
1507     }
1508
1509     if (isdigit(ch))
1510     {
1511         lex->tok.ttype = lex_finish_digit(lex, ch);
1512         lex_endtoken(lex);
1513         return lex->tok.ttype;
1514     }
1515
1516     if (lex->flags.preprocessing) {
1517         lex_tokench(lex, ch);
1518         lex_endtoken(lex);
1519         return (lex->tok.ttype = ch);
1520     }
1521
1522     lexerror(lex, "unknown token: `%s`", lex->tok.value);
1523     return (lex->tok.ttype = TOKEN_ERROR);
1524 }