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

📄 cexp.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
			  yyval.integer.unsignedp = 0; ;    break;}case 29:#line 292 "cexp.y"{ yyval.integer.value = (yyvsp[-2].integer.value || yyvsp[0].integer.value);			  yyval.integer.unsignedp = 0; ;    break;}case 30:#line 295 "cexp.y"{ yyval.integer.value = yyvsp[-4].integer.value ? yyvsp[-2].integer.value : yyvsp[0].integer.value;			  yyval.integer.unsignedp = yyvsp[-2].integer.unsignedp || yyvsp[0].integer.unsignedp; ;    break;}case 31:#line 298 "cexp.y"{ yyval.integer = yylval.integer; ;    break;}case 32:#line 300 "cexp.y"{ yyval.integer = yylval.integer; ;    break;}case 33:#line 302 "cexp.y"{ yyval.integer.value = 0;			  yyval.integer.unsignedp = 0; ;    break;}case 34:#line 307 "cexp.y"{ yyval.keywords = 0; ;    break;}case 35:#line 309 "cexp.y"{ struct arglist *temp;			  yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));			  yyval.keywords->next = yyvsp[-2].keywords;			  yyval.keywords->name = (U_CHAR *) "(";			  yyval.keywords->length = 1;			  temp = yyval.keywords;			  while (temp != 0 && temp->next != 0)			    temp = temp->next;			  temp->next = (struct arglist *) xmalloc (sizeof (struct arglist));			  temp->next->next = yyvsp[0].keywords;			  temp->next->name = (U_CHAR *) ")";			  temp->next->length = 1; ;    break;}case 36:#line 322 "cexp.y"{ yyval.keywords = (struct arglist *) xmalloc (sizeof (struct arglist));			  yyval.keywords->name = yyvsp[-1].name.address;			  yyval.keywords->length = yyvsp[-1].name.length;			  yyval.keywords->next = yyvsp[0].keywords; ;    break;}}   /* the action file gets copied in in place of this dollarsign */#line 440 "bison.simple"  yyvsp -= yylen;  yyssp -= yylen;#ifdef YYLSP_NEEDED  yylsp -= yylen;#endif#if YYDEBUG != 0  if (yydebug)    {      short *ssp1 = yyss - 1;      fprintf (stderr, "state stack now");      while (ssp1 != yyssp)	fprintf (stderr, " %d", *++ssp1);      fprintf (stderr, "\n");    }#endif  *++yyvsp = yyval;#ifdef YYLSP_NEEDED  yylsp++;  if (yylen == 0)    {      yylsp->first_line = yylloc.first_line;      yylsp->first_column = yylloc.first_column;      yylsp->last_line = (yylsp-1)->last_line;      yylsp->last_column = (yylsp-1)->last_column;      yylsp->text = 0;    }  else    {      yylsp->last_line = (yylsp+yylen-1)->last_line;      yylsp->last_column = (yylsp+yylen-1)->last_column;    }#endif  /* Now "shift" the result of the reduction.     Determine what state that goes to,     based on the state we popped back to     and the rule number reduced by.  */  yyn = yyr1[yyn];  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)    yystate = yytable[yystate];  else    yystate = yydefgoto[yyn - YYNTBASE];  goto yynewstate;yyerrlab:   /* here on detecting error */  if (! yyerrstatus)    /* If not already recovering from an error, report this error.  */    {      ++yynerrs;#ifdef YYERROR_VERBOSE      yyn = yypact[yystate];      if (yyn > YYFLAG && yyn < YYLAST)	{	  int size = 0;	  char *msg;	  int x, count;	  count = 0;	  for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)	    if (yycheck[x + yyn] == x)	      size += strlen(yytname[x]) + 15, count++;	  msg = (char *) malloc(size + 15);	  if (msg != 0)	    {	      strcpy(msg, "parse error");	      if (count < 5)		{		  count = 0;		  for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)		    if (yycheck[x + yyn] == x)		      {			strcat(msg, count == 0 ? ", expecting `" : " or `");			strcat(msg, yytname[x]);			strcat(msg, "'");			count++;		      }		}	      yyerror(msg);	      free(msg);	    }	  else	    yyerror ("parse error; also virtual memory exceeded");	}      else#endif /* YYERROR_VERBOSE */	yyerror("parse error");    }yyerrlab1:   /* here on error raised explicitly by an action */  if (yyerrstatus == 3)    {      /* if just tried and failed to reuse lookahead token after an error, discard it.  */      /* return failure if at end of input */      if (yychar == YYEOF)	YYABORT;#if YYDEBUG != 0      if (yydebug)	fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);#endif      yychar = YYEMPTY;    }  /* Else will try to reuse lookahead token     after shifting the error token.  */  yyerrstatus = 3;		/* Each real token shifted decrements this */  goto yyerrhandle;yyerrdefault:  /* current state does not do anything special for the error token. */#if 0  /* This is wrong; only states that explicitly want error tokens     should shift them.  */  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/  if (yyn) goto yydefault;#endifyyerrpop:   /* pop the current state because it cannot handle the error token */  if (yyssp == yyss) YYABORT;  yyvsp--;  yystate = *--yyssp;#ifdef YYLSP_NEEDED  yylsp--;#endif#if YYDEBUG != 0  if (yydebug)    {      short *ssp1 = yyss - 1;      fprintf (stderr, "Error: state stack now");      while (ssp1 != yyssp)	fprintf (stderr, " %d", *++ssp1);      fprintf (stderr, "\n");    }#endifyyerrhandle:  yyn = yypact[yystate];  if (yyn == YYFLAG)    goto yyerrdefault;  yyn += YYTERROR;  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)    goto yyerrdefault;  yyn = yytable[yyn];  if (yyn < 0)    {      if (yyn == YYFLAG)	goto yyerrpop;      yyn = -yyn;      goto yyreduce;    }  else if (yyn == 0)    goto yyerrpop;  if (yyn == YYFINAL)    YYACCEPT;#if YYDEBUG != 0  if (yydebug)    fprintf(stderr, "Shifting error token, ");#endif  *++yyvsp = yylval;#ifdef YYLSP_NEEDED  *++yylsp = yylloc;#endif  yystate = yyn;  goto yynewstate;}#line 327 "cexp.y"/* During parsing of a C expression, the pointer to the next character   is in this variable.  */static char *lexptr;/* Take care of parsing a number (anything that starts with a digit).   Set yylval and return the token type; update lexptr.   LEN is the number of characters in it.  *//* maybe needs to actually deal with floating point numbers */intparse_number (olen)     int olen;{  register char *p = lexptr;  register int c;  register unsigned long n = 0, nd, ULONG_MAX_over_base;  register int base = 10;  register int len = olen;  register int overflow = 0;  register int digit, largest_digit = 0;  int spec_long = 0;  for (c = 0; c < len; c++)    if (p[c] == '.') {      /* It's a float since it contains a point.  */      yyerror ("floating point numbers not allowed in #if expressions");      return ERROR;    }  yylval.integer.unsignedp = 0;  if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2))) {    p += 2;    base = 16;    len -= 2;  }  else if (*p == '0')    base = 8;  ULONG_MAX_over_base = (unsigned long) -1 / base;  for (; len > 0; len--) {    c = *p++;    if (c >= '0' && c <= '9')      digit = c - '0';    else if (base == 16 && c >= 'a' && c <= 'f')      digit = c - 'a' + 10;    else if (base == 16 && c >= 'A' && c <= 'F')      digit = c - 'A' + 10;    else {      /* `l' means long, and `u' means unsigned.  */      while (1) {	if (c == 'l' || c == 'L')	  {	    if (spec_long)	      yyerror ("two `l's in integer constant");	    spec_long = 1;	  }	else if (c == 'u' || c == 'U')	  {	    if (yylval.integer.unsignedp)	      yyerror ("two `u's in integer constant");	    yylval.integer.unsignedp = 1;	  }	else	  break;	if (--len == 0)	  break;	c = *p++;      }      /* Don't look for any more digits after the suffixes.  */      break;    }    if (largest_digit < digit)      largest_digit = digit;    nd = n * base + digit;    overflow |= ULONG_MAX_over_base < n | nd < n;    n = nd;  }  if (len != 0) {    yyerror ("Invalid number in #if expression");    return ERROR;  }  if (base <= largest_digit)    warning ("integer constant contains digits beyond the radix");  if (overflow)    warning ("integer constant out of range");  /* If too big to be signed, consider it unsigned.  */  if ((long) n < 0 && ! yylval.integer.unsignedp)    {      if (base == 10)	warning ("integer constant is so large that it is unsigned");      yylval.integer.unsignedp = 1;    }  lexptr = p;  yylval.integer.value = n;  return INT;}struct token {  char *operator;  int token;};static struct token tokentab2[] = {  {"&&", AND},  {"||", OR},  {"<<", LSH},  {">>", RSH},  {"==", EQUAL},  {"!=", NOTEQUAL},  {"<=", LEQ},  {">=", GEQ},  {"++", ERROR},  {"--", ERROR},  {NULL, ERROR}};/* Read one token, getting characters through lexptr.  */intyylex (){  register int c;  register int namelen;  register char *tokstart;  register struct token *toktab;  int wide_flag; retry:  tokstart = lexptr;  c = *tokstart;  /* See if it is a special token of length 2.  */  if (! keyword_parsing)    for (toktab = tokentab2; toktab->operator != NULL; toktab++)      if (c == *toktab->operator && tokstart[1] == toktab->operator[1]) {	lexptr += 2;	if (toktab->token == ERROR)	  {	    char *buf = (char *) alloca (40);	    sprintf (buf, "`%s' not allowed in operand of `#if'", toktab->operator);	    yyerror (buf);	  }	return toktab->token;      }  switch (c) {  case 0:    return 0;      case ' ':  case '\t':  case '\r':  case '\n':    lexptr++;    goto retry;      case 'L':    /* Capital L may start a wide-string or wide-character constant.  */    if (lexptr[1] == '\'')      {	lexptr++;	wide_flag = 1;	goto char_constant;      }    if (lexptr[1] == '"')      {	lexptr++;	wide_flag = 1;	goto string_constant;      }    break;  case '\'':    wide_flag = 0;  char_constant:    lexptr++;    if (keyword_parsing) {      char *start_ptr = lexptr - 1;      while (1) {	c = *lexptr++;	if (c == '\\')	  c = parse_escape (&lexptr);	else if (c == '\'')	  break;      }      yylval.name.address = (U_CHAR *) tokstart;      yylval.name.length = lexptr - start_ptr;      return NAME;    }    /* This code for reading a character constant       handles multicharacter constants and wide characters.       It is mostly copied from c-lex.c.  */    {      register int result = 0;      register num_chars = 0;      unsigned width = CHAR_TYPE_SIZE;      int max_chars;      char *token_buffer;      if (wide_flag)	{	  width = WCHAR_TYPE_SIZE;#ifdef MULTIBYTE_CHARS	  max_chars = MB_CUR_MAX;#else	  max_chars = 1;#endif

⌨️ 快捷键说明

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