2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include "diagnostic.h"
26 #include "symbol_table_t.h"
27 #include "adt/error.h"
28 #include "adt/strset.h"
32 #include "target_architecture.h"
35 #include "lang_features.h"
47 /* No strtold on windows and no replacement yet */
48 #define strtold(s, e) strtod(s, e)
55 static char buf[1024 + MAX_PUTBACK];
56 static const char *bufend;
57 static const char *bufpos;
58 static strset_t stringset;
59 bool allow_dollar_in_symbol = true;
62 * Prints a parse error message at the current token.
64 * @param msg the error message
66 static void parse_error(const char *msg)
68 errorf(&lexer_token.source_position, "%s", msg);
72 * Prints an internal error message at the current token.
74 * @param msg the error message
76 static NORETURN internal_error(const char *msg)
78 internal_errorf(&lexer_token.source_position, "%s", msg);
81 static inline void next_real_char(void)
83 assert(bufpos <= bufend);
84 if (bufpos >= bufend) {
90 size_t s = fread(buf + MAX_PUTBACK, 1, sizeof(buf) - MAX_PUTBACK,
96 bufpos = buf + MAX_PUTBACK;
97 bufend = buf + MAX_PUTBACK + s;
103 * Put a character back into the buffer.
105 * @param pc the character to put back
107 static inline void put_back(int pc)
109 assert(bufpos > buf);
110 *(--bufpos - buf + buf) = (char) pc;
113 printf("putback '%c'\n", pc);
117 static inline void next_char(void);
119 #define MATCH_NEWLINE(code) \
125 lexer_token.source_position.linenr++; \
129 lexer_token.source_position.linenr++; \
132 #define eat(c_type) do { assert(c == c_type); next_char(); } while(0)
134 static void maybe_concat_lines(void)
139 MATCH_NEWLINE(return;)
150 * Set c to the next input character, ie.
151 * after expanding trigraphs.
153 static inline void next_char(void)
157 /* filter trigraphs */
158 if(UNLIKELY(c == '\\')) {
159 maybe_concat_lines();
160 goto end_of_next_char;
164 goto end_of_next_char;
167 if(LIKELY(c != '?')) {
170 goto end_of_next_char;
175 case '=': c = '#'; break;
176 case '(': c = '['; break;
177 case '/': c = '\\'; maybe_concat_lines(); break;
178 case ')': c = ']'; break;
179 case '\'': c = '^'; break;
180 case '<': c = '{'; break;
181 case '!': c = '|'; break;
182 case '>': c = '}'; break;
183 case '-': c = '~'; break;
193 printf("nchar '%c'\n", c);
197 #define SYMBOL_CHARS \
198 case '$': if (!allow_dollar_in_symbol) goto dollar_sign; \
266 * Read a symbol from the input and build
269 static void parse_symbol(void)
274 obstack_1grow(&symbol_obstack, (char) c);
281 obstack_1grow(&symbol_obstack, (char) c);
292 obstack_1grow(&symbol_obstack, '\0');
294 string = obstack_finish(&symbol_obstack);
295 symbol = symbol_table_insert(string);
297 lexer_token.type = symbol->ID;
298 lexer_token.v.symbol = symbol;
300 if(symbol->string != string) {
301 obstack_free(&symbol_obstack, string);
305 static void parse_integer_suffix(bool is_oct_hex)
307 bool is_unsigned = false;
308 bool min_long = false;
309 bool min_longlong = false;
311 if(c == 'U' || c == 'u') {
314 if(c == 'L' || c == 'l') {
317 if(c == 'L' || c == 'l') {
322 } else if(c == 'l' || c == 'L') {
325 if(c == 'l' || c == 'L') {
328 if(c == 'u' || c == 'U') {
332 } else if(c == 'u' || c == 'U') {
335 lexer_token.datatype = type_unsigned_long;
340 long long v = lexer_token.v.intvalue;
342 if(v >= TARGET_INT_MIN && v <= TARGET_INT_MAX) {
343 lexer_token.datatype = type_int;
345 } else if(is_oct_hex && v >= 0 && v <= TARGET_UINT_MAX) {
346 lexer_token.datatype = type_unsigned_int;
351 if(v >= TARGET_LONG_MIN && v <= TARGET_LONG_MAX) {
352 lexer_token.datatype = type_long;
354 } else if(is_oct_hex && v >= 0 && (unsigned long long)v <= (unsigned long long)TARGET_ULONG_MAX) {
355 lexer_token.datatype = type_unsigned_long;
359 unsigned long long uv = (unsigned long long) v;
360 if(is_oct_hex && uv > (unsigned long long) TARGET_LONGLONG_MAX) {
361 lexer_token.datatype = type_unsigned_long_long;
365 lexer_token.datatype = type_long_long;
367 unsigned long long v = (unsigned long long) lexer_token.v.intvalue;
368 if(!min_long && v <= TARGET_UINT_MAX) {
369 lexer_token.datatype = type_unsigned_int;
372 if(!min_longlong && v <= TARGET_ULONG_MAX) {
373 lexer_token.datatype = type_unsigned_long;
376 lexer_token.datatype = type_unsigned_long_long;
380 static void parse_floating_suffix(void)
383 /* TODO: do something useful with the suffixes... */
387 lexer_token.datatype = type_float;
392 lexer_token.datatype = type_long_double;
395 lexer_token.datatype = type_double;
401 * A replacement for strtoull. Only those parts needed for
402 * our parser are implemented.
404 static unsigned long long parse_int_string(const char *s, const char **endptr, int base) {
405 unsigned long long v = 0;
410 /* check for overrun */
411 if (v >= 0x1000000000000000ULL)
413 switch (tolower(*s)) {
414 case '0': v <<= 4; break;
415 case '1': v <<= 4; v |= 0x1; break;
416 case '2': v <<= 4; v |= 0x2; break;
417 case '3': v <<= 4; v |= 0x3; break;
418 case '4': v <<= 4; v |= 0x4; break;
419 case '5': v <<= 4; v |= 0x5; break;
420 case '6': v <<= 4; v |= 0x6; break;
421 case '7': v <<= 4; v |= 0x7; break;
422 case '8': v <<= 4; v |= 0x8; break;
423 case '9': v <<= 4; v |= 0x9; break;
424 case 'a': v <<= 4; v |= 0xa; break;
425 case 'b': v <<= 4; v |= 0xb; break;
426 case 'c': v <<= 4; v |= 0xc; break;
427 case 'd': v <<= 4; v |= 0xd; break;
428 case 'e': v <<= 4; v |= 0xe; break;
429 case 'f': v <<= 4; v |= 0xf; break;
437 /* check for overrun */
438 if (v >= 0x2000000000000000ULL)
440 switch (tolower(*s)) {
441 case '0': v <<= 3; break;
442 case '1': v <<= 3; v |= 1; break;
443 case '2': v <<= 3; v |= 2; break;
444 case '3': v <<= 3; v |= 3; break;
445 case '4': v <<= 3; v |= 4; break;
446 case '5': v <<= 3; v |= 5; break;
447 case '6': v <<= 3; v |= 6; break;
448 case '7': v <<= 3; v |= 7; break;
456 /* check for overrun */
457 if (v > 0x1999999999999999ULL)
459 switch (tolower(*s)) {
460 case '0': v *= 10; break;
461 case '1': v *= 10; v += 1; break;
462 case '2': v *= 10; v += 2; break;
463 case '3': v *= 10; v += 3; break;
464 case '4': v *= 10; v += 4; break;
465 case '5': v *= 10; v += 5; break;
466 case '6': v *= 10; v += 6; break;
467 case '7': v *= 10; v += 7; break;
468 case '8': v *= 10; v += 8; break;
469 case '9': v *= 10; v += 9; break;
485 * Parses a hex number including hex floats and set the
488 static void parse_number_hex(void)
490 assert(c == 'x' || c == 'X');
494 obstack_1grow(&symbol_obstack, (char) c);
497 obstack_1grow(&symbol_obstack, '\0');
498 char *string = obstack_finish(&symbol_obstack);
500 if(c == '.' || c == 'p' || c == 'P') {
502 internal_error("Hex floating point numbers not implemented yet");
504 if(*string == '\0') {
505 parse_error("invalid hex number");
506 lexer_token.type = T_ERROR;
510 lexer_token.type = T_INTEGER;
511 lexer_token.v.intvalue = parse_int_string(string, &endptr, 16);
512 if(*endptr != '\0') {
513 parse_error("hex number literal too long");
516 obstack_free(&symbol_obstack, string);
517 parse_integer_suffix(true);
521 * Returns true if the given char is a octal digit.
523 * @param char the character to check
525 static inline bool is_octal_digit(int chr)
543 * Parses a octal number and set the lexer_token.
545 static void parse_number_oct(void)
547 while(is_octal_digit(c)) {
548 obstack_1grow(&symbol_obstack, (char) c);
551 obstack_1grow(&symbol_obstack, '\0');
552 char *string = obstack_finish(&symbol_obstack);
555 lexer_token.type = T_INTEGER;
556 lexer_token.v.intvalue = parse_int_string(string, &endptr, 8);
557 if(*endptr != '\0') {
558 parse_error("octal number literal too long");
561 obstack_free(&symbol_obstack, string);
562 parse_integer_suffix(true);
566 * Parses a decimal including float number and set the
569 static void parse_number_dec(void)
571 bool is_float = false;
573 obstack_1grow(&symbol_obstack, (char) c);
578 obstack_1grow(&symbol_obstack, '.');
582 obstack_1grow(&symbol_obstack, (char) c);
587 if(c == 'e' || c == 'E') {
588 obstack_1grow(&symbol_obstack, 'e');
591 if(c == '-' || c == '+') {
592 obstack_1grow(&symbol_obstack, (char) c);
597 obstack_1grow(&symbol_obstack, (char) c);
603 obstack_1grow(&symbol_obstack, '\0');
604 char *string = obstack_finish(&symbol_obstack);
608 lexer_token.type = T_FLOATINGPOINT;
609 lexer_token.v.floatvalue = strtold(string, &endptr);
611 if(*endptr != '\0') {
612 parse_error("invalid number literal");
615 parse_floating_suffix();
618 lexer_token.type = T_INTEGER;
619 lexer_token.v.intvalue = parse_int_string(string, &endptr, 10);
621 if(*endptr != '\0') {
622 parse_error("invalid number literal");
625 parse_integer_suffix(false);
627 obstack_free(&symbol_obstack, string);
631 * Parses a number and sets the lexer_token.
633 static void parse_number(void)
655 parse_error("invalid octal number");
656 lexer_token.type = T_ERROR;
662 obstack_1grow(&symbol_obstack, '0');
672 * Returns the value of a digit.
673 * The only portable way to do it ...
675 static int digit_value(int digit) {
700 internal_error("wrong character given");
705 * Parses an octal character sequence.
707 * @param first_digit the already read first digit
709 static int parse_octal_sequence(const int first_digit)
711 assert(is_octal_digit(first_digit));
712 int value = digit_value(first_digit);
713 if (!is_octal_digit(c)) return value;
714 value = 8 * value + digit_value(c);
716 if (!is_octal_digit(c)) return value;
717 value = 8 * value + digit_value(c);
721 return (signed char) value;
723 return (unsigned char) value;
728 * Parses a hex character sequence.
730 static int parse_hex_sequence(void)
734 value = 16 * value + digit_value(c);
739 return (signed char) value;
741 return (unsigned char) value;
746 * Parse an escape sequence.
748 static int parse_escape_sequence(void)
756 case '"': return '"';
757 case '\'': return '\'';
758 case '\\': return '\\';
759 case '?': return '\?';
760 case 'a': return '\a';
761 case 'b': return '\b';
762 case 'f': return '\f';
763 case 'n': return '\n';
764 case 'r': return '\r';
765 case 't': return '\t';
766 case 'v': return '\v';
768 return parse_hex_sequence();
777 return parse_octal_sequence(ec);
779 parse_error("reached end of file while parsing escape sequence");
782 parse_error("unknown escape sequence");
788 * Concatenate two strings.
790 string_t concat_strings(const string_t *const s1, const string_t *const s2)
792 const size_t len1 = s1->size - 1;
793 const size_t len2 = s2->size - 1;
795 char *const concat = obstack_alloc(&symbol_obstack, len1 + len2 + 1);
796 memcpy(concat, s1->begin, len1);
797 memcpy(concat + len1, s2->begin, len2 + 1);
799 #if 0 /* TODO hash */
800 const char *result = strset_insert(&stringset, concat);
801 if(result != concat) {
802 obstack_free(&symbol_obstack, concat);
807 return (string_t){ concat, len1 + len2 + 1 };
812 * Concatenate a string and a wide string.
814 wide_string_t concat_string_wide_string(const string_t *const s1, const wide_string_t *const s2)
816 const size_t len1 = s1->size - 1;
817 const size_t len2 = s2->size - 1;
819 wchar_rep_t *const concat = obstack_alloc(&symbol_obstack, (len1 + len2 + 1) * sizeof(*concat));
820 const char *const src = s1->begin;
821 for (size_t i = 0; i != len1; ++i) {
824 memcpy(concat + len1, s2->begin, (len2 + 1) * sizeof(*concat));
826 return (wide_string_t){ concat, len1 + len2 + 1 };
830 * Concatenate two wide strings.
832 wide_string_t concat_wide_strings(const wide_string_t *const s1, const wide_string_t *const s2)
834 const size_t len1 = s1->size - 1;
835 const size_t len2 = s2->size - 1;
837 wchar_rep_t *const concat = obstack_alloc(&symbol_obstack, (len1 + len2 + 1) * sizeof(*concat));
838 memcpy(concat, s1->begin, len1 * sizeof(*concat));
839 memcpy(concat + len1, s2->begin, (len2 + 1) * sizeof(*concat));
841 return (wide_string_t){ concat, len1 + len2 + 1 };
845 * Concatenate a wide string and a string.
847 wide_string_t concat_wide_string_string(const wide_string_t *const s1, const string_t *const s2)
849 const size_t len1 = s1->size - 1;
850 const size_t len2 = s2->size - 1;
852 wchar_rep_t *const concat = obstack_alloc(&symbol_obstack, (len1 + len2 + 1) * sizeof(*concat));
853 memcpy(concat, s1->begin, len1 * sizeof(*concat));
854 const char *const src = s2->begin;
855 for (size_t i = 0; i != len2 + 1; ++i) {
859 return (wide_string_t){ concat, len1 + len2 + 1 };
863 * Parse a string literal and set lexer_token.
865 static void parse_string_literal(void)
867 const unsigned start_linenr = lexer_token.source_position.linenr;
875 tc = parse_escape_sequence();
876 obstack_1grow(&symbol_obstack, (char) tc);
880 source_position_t source_position;
881 source_position.input_name = lexer_token.source_position.input_name;
882 source_position.linenr = start_linenr;
883 errorf(&source_position, "string has no end");
884 lexer_token.type = T_ERROR;
893 obstack_1grow(&symbol_obstack, (char) c);
901 /* TODO: concatenate multiple strings separated by whitespace... */
903 /* add finishing 0 to the string */
904 obstack_1grow(&symbol_obstack, '\0');
905 const size_t size = (size_t)obstack_object_size(&symbol_obstack);
906 const char *const string = obstack_finish(&symbol_obstack);
908 #if 0 /* TODO hash */
909 /* check if there is already a copy of the string */
910 result = strset_insert(&stringset, string);
911 if(result != string) {
912 obstack_free(&symbol_obstack, string);
915 const char *const result = string;
918 lexer_token.type = T_STRING_LITERAL;
919 lexer_token.v.string.begin = result;
920 lexer_token.v.string.size = size;
924 * Parse a wide character constant and set lexer_token.
926 static void parse_wide_character_constant(void)
928 const unsigned start_linenr = lexer_token.source_position.linenr;
935 wchar_rep_t tc = parse_escape_sequence();
936 obstack_grow(&symbol_obstack, &tc, sizeof(tc));
941 parse_error("newline while parsing character constant");
947 goto end_of_wide_char_constant;
950 source_position_t source_position = lexer_token.source_position;
951 source_position.linenr = start_linenr;
952 errorf(&source_position, "EOF while parsing character constant");
953 lexer_token.type = T_ERROR;
958 wchar_rep_t tc = (wchar_rep_t) c;
959 obstack_grow(&symbol_obstack, &tc, sizeof(tc));
966 end_of_wide_char_constant:;
967 size_t size = (size_t) obstack_object_size(&symbol_obstack);
968 assert(size % sizeof(wchar_rep_t) == 0);
969 size /= sizeof(wchar_rep_t);
971 const wchar_rep_t *string = obstack_finish(&symbol_obstack);
973 lexer_token.type = T_WIDE_CHARACTER_CONSTANT;
974 lexer_token.v.wide_string.begin = string;
975 lexer_token.v.wide_string.size = size;
976 lexer_token.datatype = type_wchar_t;
980 * Parse a wide string literal and set lexer_token.
982 static void parse_wide_string_literal(void)
984 const unsigned start_linenr = lexer_token.source_position.linenr;
992 wchar_rep_t tc = parse_escape_sequence();
993 obstack_grow(&symbol_obstack, &tc, sizeof(tc));
998 source_position_t source_position;
999 source_position.input_name = lexer_token.source_position.input_name;
1000 source_position.linenr = start_linenr;
1001 errorf(&source_position, "string has no end");
1002 lexer_token.type = T_ERROR;
1012 obstack_grow(&symbol_obstack, &tc, sizeof(tc));
1021 /* TODO: concatenate multiple strings separated by whitespace... */
1023 /* add finishing 0 to the string */
1024 wchar_rep_t nul = L'\0';
1025 obstack_grow(&symbol_obstack, &nul, sizeof(nul));
1026 const size_t size = (size_t)obstack_object_size(&symbol_obstack) / sizeof(wchar_rep_t);
1027 const wchar_rep_t *const string = obstack_finish(&symbol_obstack);
1029 #if 0 /* TODO hash */
1030 /* check if there is already a copy of the string */
1031 const wchar_rep_t *const result = strset_insert(&stringset, string);
1032 if(result != string) {
1033 obstack_free(&symbol_obstack, string);
1036 const wchar_rep_t *const result = string;
1039 lexer_token.type = T_WIDE_STRING_LITERAL;
1040 lexer_token.v.wide_string.begin = result;
1041 lexer_token.v.wide_string.size = size;
1045 * Parse a character constant and set lexer_token.
1047 static void parse_character_constant(void)
1049 const unsigned start_linenr = lexer_token.source_position.linenr;
1056 int tc = parse_escape_sequence();
1057 obstack_1grow(&symbol_obstack, (char) tc);
1062 parse_error("newline while parsing character constant");
1068 goto end_of_char_constant;
1071 source_position_t source_position;
1072 source_position.input_name = lexer_token.source_position.input_name;
1073 source_position.linenr = start_linenr;
1074 errorf(&source_position, "EOF while parsing character constant");
1075 lexer_token.type = T_ERROR;
1080 obstack_1grow(&symbol_obstack, (char) c);
1087 end_of_char_constant:;
1088 const size_t size = (size_t)obstack_object_size(&symbol_obstack);
1089 const char *const string = obstack_finish(&symbol_obstack);
1091 lexer_token.type = T_CHARACTER_CONSTANT;
1092 lexer_token.v.string.begin = string;
1093 lexer_token.v.string.size = size;
1094 lexer_token.datatype = type_int;
1098 * Skip a multiline comment.
1100 static void skip_multiline_comment(void)
1102 unsigned start_linenr = lexer_token.source_position.linenr;
1109 /* TODO: nested comment, warn here */
1120 MATCH_NEWLINE(break;)
1123 source_position_t source_position;
1124 source_position.input_name = lexer_token.source_position.input_name;
1125 source_position.linenr = start_linenr;
1126 errorf(&source_position, "at end of file while looking for comment end");
1138 * Skip a single line comment.
1140 static void skip_line_comment(void)
1158 /** The current preprocessor token. */
1159 static token_t pp_token;
1162 * Read the next preprocessor token.
1164 static inline void next_pp_token(void)
1166 lexer_next_preprocessing_token();
1167 pp_token = lexer_token;
1171 * Eat all preprocessor tokens until newline.
1173 static void eat_until_newline(void)
1175 while(pp_token.type != '\n' && pp_token.type != T_EOF) {
1181 * Handle the define directive.
1183 static void define_directive(void)
1185 lexer_next_preprocessing_token();
1186 if(lexer_token.type != T_IDENTIFIER) {
1187 parse_error("expected identifier after #define\n");
1188 eat_until_newline();
1193 * Handle the ifdef directive.
1195 static void ifdef_directive(int is_ifndef)
1198 lexer_next_preprocessing_token();
1199 //expect_identifier();
1204 * Handle the endif directive.
1206 static void endif_directive(void)
1212 * Parse the line directive.
1214 static void parse_line_directive(void)
1216 if(pp_token.type != T_INTEGER) {
1217 parse_error("expected integer");
1219 lexer_token.source_position.linenr = (unsigned int)(pp_token.v.intvalue - 1);
1222 if(pp_token.type == T_STRING_LITERAL) {
1223 lexer_token.source_position.input_name = pp_token.v.string.begin;
1227 eat_until_newline();
1233 typedef enum stdc_pragma_kind_t {
1237 STDC_CX_LIMITED_RANGE
1238 } stdc_pragma_kind_t;
1241 * STDC pragma values.
1243 typedef enum stdc_pragma_value_kind_t {
1248 } stdc_pragma_value_kind_t;
1251 * Parse a pragma directive.
1253 static void parse_pragma(void) {
1254 bool unknown_pragma = true;
1257 if (pp_token.v.symbol->pp_ID == TP_STDC) {
1258 stdc_pragma_kind_t kind = STDC_UNKNOWN;
1260 if (c_mode & _C99) {
1263 switch (pp_token.v.symbol->pp_ID) {
1264 case TP_FP_CONTRACT:
1265 kind = STDC_FP_CONTRACT;
1267 case TP_FENV_ACCESS:
1268 kind = STDC_FENV_ACCESS;
1270 case TP_CX_LIMITED_RANGE:
1271 kind = STDC_CX_LIMITED_RANGE;
1276 if (kind != STDC_UNKNOWN) {
1277 stdc_pragma_value_kind_t value = STDC_VALUE_UNKNOWN;
1279 switch (pp_token.v.symbol->pp_ID) {
1281 value = STDC_VALUE_ON;
1284 value = STDC_VALUE_OFF;
1287 value = STDC_VALUE_DEFAULT;
1292 if (value != STDC_VALUE_UNKNOWN) {
1293 unknown_pragma = false;
1295 errorf(&pp_token.source_position, "bad STDC pragma argument");
1300 unknown_pragma = true;
1302 eat_until_newline();
1303 if (unknown_pragma && warning.unknown_pragmas) {
1304 warningf(&pp_token.source_position, "encountered unknown #pragma");
1309 * Parse a preprocessor non-null directive.
1311 static void parse_preprocessor_identifier(void)
1313 assert(pp_token.type == T_IDENTIFIER);
1314 symbol_t *symbol = pp_token.v.symbol;
1316 switch(symbol->pp_ID) {
1318 printf("include - enable header name parsing!\n");
1334 parse_line_directive();
1341 /* TODO; output the rest of the line */
1342 parse_error("#error directive: ");
1351 * Parse a preprocessor directive.
1353 static void parse_preprocessor_directive(void)
1357 switch(pp_token.type) {
1359 parse_preprocessor_identifier();
1362 parse_line_directive();
1365 /* NULL directive, see § 6.10.7 */
1368 parse_error("invalid preprocessor directive");
1369 eat_until_newline();
1374 #define MAYBE_PROLOG \
1379 #define MAYBE(ch, set_type) \
1382 lexer_token.type = set_type; \
1385 #define ELSE_CODE(code) \
1389 } /* end of while(1) */ \
1392 #define ELSE(set_type) \
1394 lexer_token.type = set_type; \
1398 void lexer_next_preprocessing_token(void)
1408 lexer_token.type = '\n';
1414 /* might be a wide string ( L"string" ) */
1415 if(lexer_token.type == T_IDENTIFIER &&
1416 lexer_token.v.symbol == symbol_L) {
1418 parse_wide_string_literal();
1419 } else if(c == '\'') {
1420 parse_wide_character_constant();
1430 parse_string_literal();
1434 parse_character_constant();
1447 MAYBE('.', T_DOTDOTDOT)
1451 lexer_token.type = '.';
1457 MAYBE('&', T_ANDAND)
1458 MAYBE('=', T_ANDEQUAL)
1462 MAYBE('=', T_ASTERISKEQUAL)
1466 MAYBE('+', T_PLUSPLUS)
1467 MAYBE('=', T_PLUSEQUAL)
1471 MAYBE('>', T_MINUSGREATER)
1472 MAYBE('-', T_MINUSMINUS)
1473 MAYBE('=', T_MINUSEQUAL)
1477 MAYBE('=', T_EXCLAMATIONMARKEQUAL)
1481 MAYBE('=', T_SLASHEQUAL)
1484 skip_multiline_comment();
1485 lexer_next_preprocessing_token();
1489 skip_line_comment();
1490 lexer_next_preprocessing_token();
1496 MAYBE('=', T_PERCENTEQUAL)
1501 MAYBE(':', T_HASHHASH)
1505 lexer_token.type = '#';
1514 MAYBE('=', T_LESSEQUAL)
1517 MAYBE('=', T_LESSLESSEQUAL)
1522 MAYBE('=', T_GREATEREQUAL)
1525 MAYBE('=', T_GREATERGREATEREQUAL)
1526 ELSE(T_GREATERGREATER)
1530 MAYBE('=', T_CARETEQUAL)
1534 MAYBE('=', T_PIPEEQUAL)
1535 MAYBE('|', T_PIPEPIPE)
1543 MAYBE('=', T_EQUALEQUAL)
1547 MAYBE('#', T_HASHHASH)
1561 lexer_token.type = c;
1566 lexer_token.type = T_EOF;
1571 errorf(&lexer_token.source_position, "unknown character '%c' found", c);
1573 lexer_token.type = T_ERROR;
1579 void lexer_next_token(void)
1581 lexer_next_preprocessing_token();
1583 while (lexer_token.type == '\n') {
1585 lexer_next_preprocessing_token();
1588 if (lexer_token.type == '#') {
1589 parse_preprocessor_directive();
1594 void init_lexer(void)
1596 strset_init(&stringset);
1597 symbol_L = symbol_table_insert("L");
1600 void lexer_open_stream(FILE *stream, const char *input_name)
1603 lexer_token.source_position.linenr = 0;
1604 lexer_token.source_position.input_name = input_name;
1609 /* place a virtual \n at the beginning so the lexer knows that we're
1610 * at the beginning of a line */
1614 void lexer_open_buffer(const char *buffer, size_t len, const char *input_name)
1617 lexer_token.source_position.linenr = 0;
1618 lexer_token.source_position.input_name = input_name;
1621 bufend = buffer + len;
1623 /* place a virtual \n at the beginning so the lexer knows that we're
1624 * at the beginning of a line */
1628 void exit_lexer(void)
1630 strset_destroy(&stringset);
1633 static __attribute__((unused))
1634 void dbg_pos(const source_position_t source_position)
1636 fprintf(stdout, "%s:%u\n", source_position.input_name,
1637 source_position.linenr);