📄 lex.c
字号:
return (unicode_t)0x9; case 'n': return (unicode_t)0xa; case 'f': return (unicode_t)0xc; case 'r': return (unicode_t)0xd; case '"': return (unicode_t)0x22; case '\'': return (unicode_t)0x27; case '\\': return (unicode_t)0x5c; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { int octal_escape[3]; int octal_escape_index = 0; for (; octal_escape_index < 3 && RANGE (c, '0', '9'); c = java_get_unicode ()) octal_escape [octal_escape_index++] = c; java_unget_unicode (); if ((octal_escape_index == 3) && (octal_escape [0] > '3')) { java_lex_error ("Literal octal escape out of range", 0); return JAVA_CHAR_ERROR; } else { int i, shift; for (char_lit=0, i = 0, shift = 3*(octal_escape_index-1); i < octal_escape_index; i++, shift -= 3) char_lit |= (octal_escape [i] - '0') << shift; return (char_lit); } break; } case '\n': return '\n'; /* ULT, caught latter as a specific error */ default: java_lex_error ("Illegal character in escape sequence", 0); return JAVA_CHAR_ERROR; }}int#ifdef JC1_LITEyylex (java_lval)#elsejava_lex (java_lval)#endif YYSTYPE *java_lval;{ unicode_t c, first_unicode; int ascii_index, all_ascii; char *string; /* Translation of the Unicode escape in the raw stream of Unicode characters. Takes care of line terminator. */ step1: /* Skip white spaces: SP, TAB and FF or ULT */ for (c = java_get_unicode (); c == '\n' || JAVA_WHITE_SPACE_P (c); c = java_get_unicode ()) if (c == '\n') { ctxp->elc.line = ctxp->c_line->lineno; ctxp->elc.col = ctxp->c_line->char_col-2; } ctxp->elc.col = (ctxp->elc.col < 0 ? 0 : ctxp->elc.col); if (c == 0x1a) /* CTRL-Z */ { if ((c = java_get_unicode ()) == UEOF) return 0; /* Ok here */ else java_unget_unicode (); /* Caught latter at the end the function */ } /* Handle EOF here */ if (c == UEOF) /* Should probably do something here... */ return 0; /* Take care of eventual comments. */ if (c == '/') { switch (c = java_get_unicode ()) { case '/': for (;;) { c = java_get_unicode (); if (c == UEOF) java_lex_error ("Comment not terminated at end of input", 0); if (c == '\n') /* ULT */ goto step1; } break; case '*': if ((c = java_get_unicode ()) == '*') { if ((c = java_get_unicode ()) == '/') goto step1; /* Empy documentation comment */ else if (java_parse_doc_section (c)) goto step1; } java_parse_end_comment (c); goto step1; break; default: java_unget_unicode (); c = '/'; break; } } ctxp->elc.line = ctxp->c_line->lineno; ctxp->elc.prev_col = ctxp->elc.col; ctxp->elc.col = ctxp->c_line->char_col - JAVA_COLUMN_DELTA (-1); if (ctxp->elc.col < 0) fatal ("ctxp->elc.col < 0 - java_lex"); /* Numeric literals */ if (JAVA_ASCII_DIGIT (c) || (c == '.')) { /* This section of code is borrowed from gcc/c-lex.c */#define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2) int parts[TOTAL_PARTS]; HOST_WIDE_INT high, low; /* End borrowed section */ char literal_token [256]; int literal_index = 0, radix = 10, long_suffix = 0, overflow = 0, bytes; int i;#ifndef JC1_LITE int number_beginning = ctxp->c_line->current;#endif /* We might have a . separator instead of a FP like .[0-9]* */ if (c == '.') { unicode_t peep = java_sneak_unicode (); if (!JAVA_ASCII_DIGIT (peep)) { JAVA_LEX_SEP('.'); BUILD_OPERATOR (DOT_TK); } } for (i = 0; i < TOTAL_PARTS; i++) parts [i] = 0; if (c == '0') { c = java_get_unicode (); if (c == 'x' || c == 'X') { radix = 16; c = java_get_unicode (); } else if (JAVA_ASCII_DIGIT (c)) radix = 8; else if (c == '.') { /* Push the '.' back and prepare for a FP parsing... */ java_unget_unicode (); c = '0'; } else { /* We have a zero literal: 0, 0{f,F}, 0{d,D} */ JAVA_LEX_LIT ("0", 10); switch (c) { case 'L': case 'l': SET_LVAL_NODE (long_zero_node); return (INT_LIT_TK); case 'f': case 'F': SET_LVAL_NODE (float_zero_node); return (FP_LIT_TK); case 'd': case 'D': SET_LVAL_NODE (double_zero_node); return (FP_LIT_TK); default: java_unget_unicode (); SET_LVAL_NODE (integer_zero_node); return (INT_LIT_TK); } } } /* Parse the first part of the literal, until we find something which is not a number. */ while ((radix == 10 && JAVA_ASCII_DIGIT (c)) || (radix == 16 && JAVA_ASCII_HEXDIGIT (c)) || (radix == 8 && JAVA_ASCII_OCTDIGIT (c))) { /* We store in a string (in case it turns out to be a FP) and in PARTS if we have to process a integer literal. */ int numeric = (RANGE (c, '0', '9') ? c-'0' : 10 +(c|0x20)-'a'); int count; literal_token [literal_index++] = c; /* This section of code if borrowed from gcc/c-lex.c */ for (count = 0; count < TOTAL_PARTS; count++) { parts[count] *= radix; if (count) { parts[count] += (parts[count-1] >> HOST_BITS_PER_CHAR); parts[count-1] &= (1 << HOST_BITS_PER_CHAR) - 1; } else parts[0] += numeric; } if (parts [TOTAL_PARTS-1] != 0) overflow = 1; /* End borrowed section. */ c = java_get_unicode (); } /* If we have something from the FP char set but not a digit, parse a FP literal. */ if (JAVA_ASCII_FPCHAR (c) && !JAVA_ASCII_DIGIT (c)) { int stage = 0; int seen_digit = (literal_index ? 1 : 0); int seen_exponent = 0; int fflag = 0; /* 1 for {f,F}, 0 for {d,D}. FP literal are double unless specified. */ if (radix != 10) java_lex_error ("Can't express non-decimal FP literal", 0); for (;;) { if (c == '.') { if (stage < 1) { stage = 1; literal_token [literal_index++ ] = c; c = java_get_unicode (); } else java_lex_error ("Invalid character in FP literal", 0); } if (c == 'e' || c == 'E') { if (stage < 2) { /* {E,e} must have seen at list a digit */ if (!seen_digit) java_lex_error ("Invalid FP literal", 0); seen_digit = 0; seen_exponent = 1; stage = 2; literal_token [literal_index++] = c; c = java_get_unicode (); } else java_lex_error ("Invalid character in FP literal", 0); } if ( c == 'f' || c == 'F' || c == 'd' || c == 'D') { fflag = ((c == 'd') || (c == 'D')) ? 0 : 1; stage = 4; /* So we fall through */ } if ((c=='-' || c =='+') && stage == 2) { stage = 3; literal_token [literal_index++] = c; c = java_get_unicode (); } if ((stage == 0 && JAVA_ASCII_FPCHAR (c)) || (stage == 1 && JAVA_ASCII_FPCHAR (c) && !(c == '.')) || (stage == 2 && (JAVA_ASCII_DIGIT (c) || JAVA_FP_PM (c))) || (stage == 3 && JAVA_ASCII_DIGIT (c))) { if (JAVA_ASCII_DIGIT (c)) seen_digit = 1; literal_token [literal_index++ ] = c; c = java_get_unicode (); } else { jmp_buf handler; REAL_VALUE_TYPE value;#ifndef JC1_LITE tree type = (fflag ? FLOAT_TYPE_NODE : DOUBLE_TYPE_NODE);#endif if (stage != 4) /* Don't push back fF/dD */ java_unget_unicode (); /* An exponent (if any) must have seen a digit. */ if (seen_exponent && !seen_digit) java_lex_error ("Invalid FP literal", 0); literal_token [literal_index] = '\0'; JAVA_LEX_LIT (literal_token, radix); if (setjmp (handler)) { JAVA_FLOAT_RANGE_ERROR ((fflag ? "float" : "double")); value = DCONST0; } else { SET_FLOAT_HANDLER (handler); SET_REAL_VALUE_ATOF (value, REAL_VALUE_ATOF (literal_token, TYPE_MODE (type))); if (REAL_VALUE_ISINF (value)) JAVA_FLOAT_RANGE_ERROR ((fflag ? "float" : "double")); if (REAL_VALUE_ISNAN (value)) JAVA_FLOAT_RANGE_ERROR ((fflag ? "float" : "double")); SET_LVAL_NODE_TYPE (build_real (type, value), type); SET_FLOAT_HANDLER (NULL_PTR); return FP_LIT_TK; } } } } /* JAVA_ASCCI_FPCHAR (c) */ /* Here we get back to converting the integral literal. */ if (c == 'L' || c == 'l') long_suffix = 1; else if (radix == 16 && JAVA_ASCII_LETTER (c)) java_lex_error ("Digit out of range in hexadecimal literal", 0); else if (radix == 8 && JAVA_ASCII_DIGIT (c)) java_lex_error ("Digit out of range in octal literal", 0); else if (radix == 16 && !literal_index) java_lex_error ("No digit specified for hexadecimal literal", 0); else java_unget_unicode ();#ifdef JAVA_LEX_DEBUG literal_token [literal_index] = '\0'; /* So JAVA_LEX_LIT is safe. */ JAVA_LEX_LIT (literal_token, radix);#endif /* This section of code is borrowed from gcc/c-lex.c */ if (!overflow) { bytes = GET_TYPE_PRECISION (long_type_node); for (i = bytes; i < TOTAL_PARTS; i++) if (parts [i]) { overflow = 1; break; } } high = low = 0; for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++) { high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR)] << (i * HOST_BITS_PER_CHAR)); low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR); } /* End borrowed section. */ /* Range checking */ if (long_suffix) { /* 9223372036854775808L is valid if operand of a '-'. Otherwise 9223372036854775807L is the biggest `long' literal that can be expressed using a 10 radix. For other radixes, everything that fits withing 64 bits is OK. */ int hb = (high >> 31); if (overflow || (hb && low && radix == 10) || (hb && high & 0x7fffffff && radix == 10) || (hb && !(high & 0x7fffffff) && !ctxp->minus_seen && radix == 10)) JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `long' literal"); } else { /* 2147483648 is valid if operand of a '-'. Otherwise, 2147483647 is the biggest `int' literal that can be expressed using a 10 radix. For other radixes, everything that fits within 32 bits is OK. As all literals are signed, we sign extend here. */ int hb = (low >> 31) & 0x1; if (overflow || high || (hb && low & 0x7fffffff && radix == 10) || (hb && !(low & 0x7fffffff) && !ctxp->minus_seen && radix == 10)) JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `int' literal"); high = -hb; } ctxp->minus_seen = 0; SET_LVAL_NODE_TYPE (build_int_2 (low, high), (long_suffix ? long_type_node : int_type_node)); return INT_LIT_TK; } ctxp->minus_seen = 0; /* Character literals */ if (c == '\'') { unicode_t char_lit; if ((c = java_get_unicode ()) == '\\') char_lit = java_parse_escape_sequence (); else char_lit = c; c = java_get_unicode (); if ((c == '\n') || (c == UEOF)) java_lex_error ("Character literal not terminated at end of line", 0); if (c != '\'') java_lex_error ("Syntax error in character literal", 0); if (c == JAVA_CHAR_ERROR) char_lit = 0; /* We silently convert it to zero */ JAVA_LEX_CHAR_LIT (char_lit); SET_LVAL_NODE_TYPE (build_int_2 (char_lit, 0), char_type_node); return CHAR_LIT_TK; } /* String literals */ if (c == '"') { int no_error; char *string; for (no_error = 1, c = java_get_unicode (); c != '"' && c != '\n'; c = java_get_unicode ()) { if (c == '\\') c = java_parse_escape_sequence (); no_error &= (c != JAVA_CHAR_ERROR ? 1 : 0); java_unicode_2_utf8 (c); } if (c == '\n' || c == UEOF) /* ULT */ { lineno--; /* Refer to the line the terminator was seen */ java_lex_error ("String not terminated at end of line.", 0); lineno++; } obstack_1grow (&temporary_obstack, '\0'); string = obstack_finish (&temporary_obstack);#ifndef JC1_LITE if (!no_error || (c != '"')) java_lval->node = error_mark_node; /* Requires futher testing FIXME */ else { tree s = make_node (STRING_CST); TREE_STRING_LENGTH (s) = strlen (string); TREE_STRING_POINTER (s) = obstack_alloc (expression_obstack, TREE_STRING_LENGTH (s)+1); strcpy (TREE_STRING_POINTER (s), string); java_lval->node = s; }#endif return STRING_LIT_TK; } /* Separator */ switch (c) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -