⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lex.c

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 C
📖 第 1 页 / 共 4 页
字号:
    case 'Z':    case 'a':                                   case 'e':    case 'f':  case 'g':             case 'i':  case 'j':    case 'k':  case 'l':  case 'm':  case 'n':    case 'p':  case 'q':  case 'r':  case 's':  case 't':    case 'u':  case 'v':  case 'w':  case 'x':  case 'y':    case 'z':    case '_':    letter:      return handle_name (read_identifier (ch));    case '\'':      tmp = readstring ('\'', &len);      yylval.ttype = string_or_char (len, tmp);      free (tmp);      return len == 1 ? SINGLECHAR : STRING;    case '\"':      tmp = readstring ('\"', &len);      yylval.ttype = build_chill_string (len, tmp);      free (tmp);      return STRING;    case '.':      nextc = input ();      unput (nextc);      if (ISDIGIT (nextc)) /* || nextc == '_')  we don't start numbers with '_' */	goto number;      return DOT;    case '0': case '1': case '2': case '3': case '4':    case '5': case '6': case '7': case '8': case '9':    number:      yylval.ttype = read_number (ch);      return TREE_CODE (yylval.ttype) == REAL_CST ? FLOATING : NUMBER;    default:      return ch;    }}static voidclose_input_file (fn)  char *fn;{  if (finput == NULL)    abort ();  if (finput != stdin && fclose (finput) == EOF)    {      error ("can't close %s", fn);      abort ();    }  finput = NULL;}/* Return an identifier, starting with FIRST and then reading   more characters using input().  Return an IDENTIFIER_NODE. */static treeread_identifier (first)     int first; /* First letter of identifier */{  tree id;  char *start;  for (;;)    {      obstack_1grow (&temporary_obstack, first);      first = input ();      if (first == EOF)	break;      if (! ISALNUM (first) && first != '_')	{	  unput (first);	  break;	}    }  obstack_1grow (&temporary_obstack, '\0');  start = obstack_finish (&temporary_obstack);  maybe_downcase (start);  id = get_identifier (start);  obstack_free (&temporary_obstack, start);  return id;}/* Given an identifier ID, check to see if it is a reserved name,   and return the appropriate token type. */static inthandle_name (id)     tree id;{  struct resword *tp;  tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));  if (tp != NULL      && special_UC == ISUPPER ((unsigned char) tp->name[0])      && (tp->flags == RESERVED || tp->flags == PREDEF))    {      if (tp->rid != NORID)	yylval.ttype = ridpointers[tp->rid];      else if (tp->token == THIS)	yylval.ttype = lookup_name (get_identifier ("__whoami"));      return tp->token;    }  yylval.ttype = id;  return NAME;}static treeread_number (ch)     int ch; /* Initial character */{  tree num;  char *start;  int is_float = 0;  for (;;)    {      if (ch != '_')	obstack_1grow (&temporary_obstack, ch);      ch = input ();      if (! ISDIGIT (ch) && ch != '_')	break;    }  if (ch == '.')    {      do	{	  if (ch != '_')	    obstack_1grow (&temporary_obstack, ch);	  ch = input ();	} while (ISDIGIT (ch) || ch == '_');      is_float++;    }  if (ch == 'd' || ch == 'D' || ch == 'e' || ch == 'E')    {      /* Convert exponent indication [eEdD] to 'e'. */      obstack_1grow (&temporary_obstack, 'e');      ch = input ();      if (ch == '+' || ch == '-')	{	  obstack_1grow (&temporary_obstack, ch);	  ch = input ();	}      if (ISDIGIT (ch) || ch == '_')	{	  do	    {	      if (ch != '_')		obstack_1grow (&temporary_obstack, ch);	      ch = input ();	    } while (ISDIGIT (ch) || ch == '_');	}      else	{	  error ("malformed exponent part of floating-point literal");	}      is_float++;    }  if (ch != EOF)    unput (ch);  obstack_1grow (&temporary_obstack, '\0');  start = obstack_finish (&temporary_obstack);  if (is_float)    {      REAL_VALUE_TYPE value;      tree  type = double_type_node;      errno = 0;      value = REAL_VALUE_ATOF (start, TYPE_MODE (type));      obstack_free (&temporary_obstack, start);      if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT	  && REAL_VALUE_ISINF (value) && pedantic)	pedwarn ("real number exceeds range of REAL");      num = build_real (type, value);    }  else    num = convert_integer (start);  CH_DERIVED_FLAG (num) = 1;  return num;}/* Skip to the end of a compiler directive. */static voidskip_directive (){  int ch = input ();  for (;;)    {      if (ch == EOF)	{	  error ("end-of-file in '<>' directive");	  break;	}      if (ch == '\n')	break;      if (ch == '<')	{	  ch = input ();	  if (ch == '>')	    break;	}      ch = input ();    }  starting_pass_2 = 0;}/* Read a compiler directive.  ("<>{WS}" have already been read. ) */static voidread_directive (){  struct resword *tp;  tree id;  int ch = skip_whitespace();  if (ISALPHA (ch) || ch == '_')    id = read_identifier (ch);  else if (ch == EOF)    {      error ("end-of-file in '<>' directive");       to_global_binding_level ();       return;    }  else    {      warning ("unrecognized compiler directive");      skip_directive ();      return;    }  tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));  if (tp == NULL || special_UC != ISUPPER ((unsigned char) tp->name[0]))    {      if (pass == 1)	warning ("unrecognized compiler directive `%s'",		 IDENTIFIER_POINTER (id));    }  else    switch (tp->token)      {      case ALL_STATIC_OFF:	all_static_flag = 0;	break;      case ALL_STATIC_ON:	all_static_flag = 1;	break;      case EMPTY_OFF:	empty_checking = 0;	break;      case EMPTY_ON:	empty_checking = 1;	break;      case IGNORED_DIRECTIVE:	break;      case PROCESS_TYPE_TOKEN:	process_type = equal_number ();	break;      case RANGE_OFF:	range_checking = 0;	break;      case RANGE_ON:	range_checking = 1;	break;      case SEND_SIGNAL_DEFAULT_PRIORITY: 	send_signal_prio = equal_number ();	break;      case SEND_BUFFER_DEFAULT_PRIORITY:	send_buffer_prio = equal_number ();	break;      case SIGNAL_CODE:	signal_code = equal_number ();	break;      case USE_SEIZE_FILE:	handle_use_seizefile_directive (0);	break;      case USE_SEIZE_FILE_RESTRICTED:	handle_use_seizefile_directive (1);	break;      default:	if (pass == 1)	  warning ("unrecognized compiler directive `%s'", 		   IDENTIFIER_POINTER (id));	break;      }  skip_directive ();}treebuild_chill_string (len, str)    int   len;    char  *str;{  tree t;  push_obstacks (&permanent_obstack, &permanent_obstack);  t = build_string (len, str);  TREE_TYPE (t) = build_string_type (char_type_node, 				     build_int_2 (len, 0));  CH_DERIVED_FLAG (t) = 1;  pop_obstacks ();  return t;}static treestring_or_char (len, str)     int   len;     char *str;{  tree result;    push_obstacks (&permanent_obstack, &permanent_obstack);  if (len == 1)    {      result = build_int_2 ((unsigned char)str[0], 0);      CH_DERIVED_FLAG (result) = 1;      TREE_TYPE (result) = char_type_node;    }  else    result = build_chill_string (len, str);  pop_obstacks ();  return result;}static voidmaybe_downcase (str)    char        *str;{  if (! ignore_case)    return;  while (*str)    {      if (ISUPPER ((unsigned char) *str))	*str = tolower ((unsigned char)*str);      str++;    }}static intmaybe_number (s)  char	*s;{  char	fc;    /* check for decimal number */  if (*s >= '0' && *s <= '9')    {      while (*s)	{	  if (*s >= '0' && *s <= '9')	    s++;	  else	    return 0;	}      return 1;    }    fc = *s;  if (s[1] != '\'')    return 0;  s += 2;  while (*s)    {      switch (fc)	{	case 'd':	case 'D':	  if (*s < '0' || *s > '9')	    return 0;	  break;	case 'h':	case 'H':	  if (!ISXDIGIT ((unsigned char) *s))	    return 0;	  break;	case 'b':	case 'B':	  if (*s < '0' || *s > '1')	    return 0;	  break;	case 'o':	case 'O':	  if (*s < '0' || *s > '7')	    return 0;	  break;	default:	  return 0;	}      s++;    }  return 1;}static char *readstring (terminator, len)     char terminator;     int *len;{  int      c;  unsigned allocated = 1024;  char    *tmp = xmalloc (allocated);  unsigned i = 0;    for (;;)    {      c = input ();      if (c == terminator)	{	  if ((c = input ()) != terminator)	    {	      unput (c);	      break;	    }	  else	    c = terminator;	}      if (c == '\n' || c == EOF)	  goto unterminated;      if (c == '^')	{	  c = input();	  if (c == EOF || c == '\n')	    goto unterminated;	  if (c == '^')	    goto storeit;	  if (c == '(')	    {	      int cc, count = 0;	      int base = 10;	      int next_apos = 0;	      int check_base = 1;	      c = 0;	      while (1)		{		  cc = input ();		  if (cc == terminator)		    {		      if (!(terminator == '\'' && next_apos))			{			  error ("unterminated control sequence");			  serious_errors++;			  goto done;			}		    }		  if (cc == EOF || cc == '\n')		    {		      c = cc;		      goto unterminated;		    }		  if (next_apos)		    {		      next_apos = 0;		      if (cc != '\'')			{			  error ("invalid integer literal in control sequence");			  serious_errors++;			  goto done;			}		      continue;		    }		  if (cc == ' ' || cc == '\t')		    continue;		  if (cc == ')')		    {		      if ((c < 0 || c > 255) && (pass == 1))			error ("control sequence overflow");		      if (! count && pass == 1)			error ("invalid control sequence");		      break;		    }		  else if (cc == ',')		    {		      if ((c < 0 || c > 255) && (pass == 1))			error ("control sequence overflow");		      if (! count && pass == 1)			error ("invalid control sequence");		      tmp[i++] = c;		      if (i == allocated)			{			  allocated += 1024;			  tmp = xrealloc (tmp, allocated);			}		      c = count = 0;		      base = 10;		      check_base = 1;		      continue;		    }		  else if (cc == '_')		    {		      if (! count && pass == 1)			error ("invalid integer literal in control sequence");		      continue;		    }		  if (check_base)		    {		      if (cc == 'D' || cc == 'd')			{			  base = 10;			  next_apos = 1;			}		      else if (cc == 'H' || cc == 'h')			{			  base = 16;			  next_apos = 1;			}		      else if (cc == 'O' || cc == 'o')			{			  base = 8;			  next_apos = 1;			}		      else if (cc == 'B' || cc == 'b')			{			  base = 2;			  next_apos = 1;			}		      check_base = 0;		      if (next_apos)			continue;		    }		  if (base == 2)		    {		      if (cc < '0' || cc > '1')			cc = -1;		      else			cc -= '0';		    }		  else if (base == 8)		    {		      if (cc < '0' || cc > '8')			cc = -1;		      else			cc -= '0';		    }		  else if (base == 10)		    {		      if (! ISDIGIT (cc))			cc = -1;		      else			cc -= '0';		    }		  else if (base == 16)		    {		      if (!ISXDIGIT (cc))			cc = -1;		      else			{			  if (cc >= 'a')			    cc -= ' ';			  cc -= '0';			  if (cc > 9)			    cc -= 7;			}		    }		  else		    {		      error ("invalid base in read control sequence");		      abort ();		    }		  if (cc == -1)		    {		      /* error in control sequence */		      if (pass == 1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -