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

📄 c-exp.tab.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
# line 30 "./c-exp.y"#include <stdio.h>#include <string.h>#include "defs.h"#include "symtab.h"#include "gdbtypes.h"#include "frame.h"#include "expression.h"#include "parser-defs.h"#include "value.h"#include "language.h"#include "bfd.h"#include "symfile.h"#include "objfiles.h"/* These MUST be included in any grammar file!!!! Please choose unique names!   Note that this are a combined list of variables that can be produced   by any one of bison, byacc, or yacc. */#define	yymaxdepth c_maxdepth#define	yyparse	c_parse#define	yylex	c_lex#define	yyerror	c_error#define	yylval	c_lval#define	yychar	c_char#define	yydebug	c_debug#define	yypact	c_pact	#define	yyr1	c_r1			#define	yyr2	c_r2			#define	yydef	c_def		#define	yychk	c_chk		#define	yypgo	c_pgo		#define	yyact	c_act		#define	yyexca	c_exca#define yyerrflag c_errflag#define yynerrs	c_nerrs#define	yyps	c_ps#define	yypv	c_pv#define	yys	c_s#define	yy_yys	c_yys#define	yystate	c_state#define	yytmp	c_tmp#define	yyv	c_v#define	yy_yyv	c_yyv#define	yyval	c_val#define	yylloc	c_lloc#define yyss	c_yyss		/* byacc */#define	yyssp	c_yysp		/* byacc */#define	yyvs	c_yyvs		/* byacc */#define	yyvsp	c_yyvsp		/* byacc */intyyparse PARAMS ((void));intyylex PARAMS ((void));voidyyerror PARAMS ((char *));/* #define	YYDEBUG	1 */# line 97 "./c-exp.y"typedef union   {    LONGEST lval;    unsigned LONGEST ulval;    double dval;    struct symbol *sym;    struct type *tval;    struct stoken sval;    struct ttype tsym;    struct symtoken ssym;    int voidval;    struct block *bval;    enum exp_opcode opcode;    struct internalvar *ivar;    struct type **tvec;    int *ivec;  } YYSTYPE;# line 117 "./c-exp.y"/* YYSTYPE gets defined by %union */static intparse_number PARAMS ((char *, int, int, YYSTYPE *));# define INT 257# define CHAR 258# define UINT 259# define FLOAT 260# define STRING 261# define NAME 262# define TYPENAME 263# define NAME_OR_INT 264# define NAME_OR_UINT 265# define STRUCT 266# define CLASS 267# define UNION 268# define ENUM 269# define SIZEOF 270# define UNSIGNED 271# define COLONCOLON 272# define TEMPLATE 273# define ERROR 274# define SIGNED_KEYWORD 275# define LONG 276# define SHORT 277# define INT_KEYWORD 278# define CONST_KEYWORD 279# define VOLATILE_KEYWORD 280# define LAST 281# define REGNAME 282# define VARIABLE 283# define ASSIGN_MODIFY 284# define THIS 285# define ABOVE_COMMA 286# define OROR 287# define ANDAND 288# define EQUAL 289# define NOTEQUAL 290# define LEQ 291# define GEQ 292# define LSH 293# define RSH 294# define UNARY 295# define INCREMENT 296# define DECREMENT 297# define ARROW 298# define BLOCKNAME 299# line 197 "./c-exp.y"/* Ensure that if the generated parser contains any calls to malloc/realloc,   that they get mapped to xmalloc/xrealloc.  We have to do this here   rather than earlier in the file because this is the first point after   the place where the SVR4 yacc includes <malloc.h>, and if we do it   before that, then the remapped declarations in <malloc.h> will collide   with the ones in "defs.h". */#define malloc	xmalloc#define realloc	xrealloc#define yyclearin yychar = -1#define yyerrok yyerrflag = 0extern int yychar;extern int yyerrflag;#ifndef YYMAXDEPTH#define YYMAXDEPTH 150#endifYYSTYPE yylval, yyval;# define YYERRCODE 256# line 946 "./c-exp.y"/* 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.  *//*** Needs some error checking for the float case ***/static intparse_number (p, len, parsed_float, putithere)     register char *p;     register int len;     int parsed_float;     YYSTYPE *putithere;{  register LONGEST n = 0;  register LONGEST prevn = 0;  register int i;  register int c;  register int base = input_radix;  int unsigned_p = 0;  if (parsed_float)    {      /* It's a float since it contains a point or an exponent.  */      putithere->dval = atof (p);      return FLOAT;    }  /* Handle base-switching prefixes 0x, 0t, 0d, 0 */  if (p[0] == '0')    switch (p[1])      {      case 'x':      case 'X':	if (len >= 3)	  {	    p += 2;	    base = 16;	    len -= 2;	  }	break;      case 't':      case 'T':      case 'd':      case 'D':	if (len >= 3)	  {	    p += 2;	    base = 10;	    len -= 2;	  }	break;      default:	base = 8;	break;      }  while (len-- > 0)    {      c = *p++;      if (c >= 'A' && c <= 'Z')	c += 'a' - 'A';      if (c != 'l' && c != 'u')	n *= base;      if (c >= '0' && c <= '9')	n += i = c - '0';      else	{	  if (base > 10 && c >= 'a' && c <= 'f')	    n += i = c - 'a' + 10;	  else if (len == 0 && c == 'l')	    ;	  else if (len == 0 && c == 'u')	    unsigned_p = 1;	  else	    return ERROR;	/* Char not a digit */	}      if (i >= base)	return ERROR;		/* Invalid digit in this base */      /* Portably test for overflow (only works for nonzero values, so make	 a second check for zero).  */      if((prevn >= n) && n != 0)	 unsigned_p=1;		/* Try something unsigned */      /* If range checking enabled, portably test for unsigned overflow.  */      if(RANGE_CHECK && n!=0)      {		 if((unsigned_p && (unsigned)prevn >= (unsigned)n))	    range_error("Overflow on numeric constant.");	       }      prevn=n;    }  if (unsigned_p)    {      putithere->ulval = n;      return UINT;    }  else    {      putithere->lval = n;      return INT;    }}struct token{  char *operator;  int token;  enum exp_opcode opcode;};const static struct token tokentab3[] =  {    {">>=", ASSIGN_MODIFY, BINOP_RSH},    {"<<=", ASSIGN_MODIFY, BINOP_LSH}  };const static struct token tokentab2[] =  {    {"+=", ASSIGN_MODIFY, BINOP_ADD},    {"-=", ASSIGN_MODIFY, BINOP_SUB},    {"*=", ASSIGN_MODIFY, BINOP_MUL},    {"/=", ASSIGN_MODIFY, BINOP_DIV},    {"%=", ASSIGN_MODIFY, BINOP_REM},    {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},    {"&=", ASSIGN_MODIFY, BINOP_LOGAND},    {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},    {"++", INCREMENT, BINOP_END},    {"--", DECREMENT, BINOP_END},    {"->", ARROW, BINOP_END},    {"&&", ANDAND, BINOP_END},    {"||", OROR, BINOP_END},    {"::", COLONCOLON, BINOP_END},    {"<<", LSH, BINOP_END},    {">>", RSH, BINOP_END},    {"==", EQUAL, BINOP_END},    {"!=", NOTEQUAL, BINOP_END},    {"<=", LEQ, BINOP_END},    {">=", GEQ, BINOP_END}  };/* Read one token, getting characters through lexptr.  */intyylex (){  register int c;  register int namelen;  register unsigned i;  register char *tokstart; retry:  tokstart = lexptr;  /* See if it is a special token of length 3.  */  for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)    if (!strncmp (tokstart, tokentab3[i].operator, 3))      {	lexptr += 3;	yylval.opcode = tokentab3[i].opcode;	return tokentab3[i].token;      }  /* See if it is a special token of length 2.  */  for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)    if (!strncmp (tokstart, tokentab2[i].operator, 2))      {	lexptr += 2;	yylval.opcode = tokentab2[i].opcode;	return tokentab2[i].token;      }  switch (c = *tokstart)    {    case 0:      return 0;    case ' ':    case '\t':    case '\n':      lexptr++;      goto retry;    case '\'':      /* We either have a character constant ('0' or '\177' for example)	 or we have a quoted symbol reference ('foo(int,int)' in C++	 for example). */      lexptr++;      c = *lexptr++;      if (c == '\\')	c = parse_escape (&lexptr);      yylval.lval = c;      c = *lexptr++;      if (c != '\'')	{	  namelen = skip_quoted (tokstart) - tokstart;	  if (namelen > 2)	    {	      lexptr = tokstart + namelen;	      namelen -= 2;	      tokstart++;	      goto tryname;	    }	  error ("Invalid character constant.");	}      return CHAR;    case '(':      paren_depth++;      lexptr++;      return c;    case ')':      if (paren_depth == 0)	return 0;      paren_depth--;      lexptr++;      return c;    case ',':      if (comma_terminates && paren_depth == 0)	return 0;      lexptr++;      return c;    case '.':      /* Might be a floating point number.  */      if (lexptr[1] < '0' || lexptr[1] > '9')	goto symbol;		/* Nope, must be a symbol. */      /* FALL THRU into number case.  */    case '0':    case '1':    case '2':    case '3':    case '4':    case '5':    case '6':    case '7':    case '8':    case '9':      {	/* It's a number.  */	int got_dot = 0, got_e = 0, toktype;	register char *p = tokstart;	int hex = input_radix > 10;	if (c == '0' && (p[1] == 'x' || p[1] == 'X'))	  {	    p += 2;	    hex = 1;	  }	else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))	  {	    p += 2;	    hex = 0;	  }	for (;; ++p)	  {	    if (!hex && !got_e && (*p == 'e' || *p == 'E'))	      got_dot = got_e = 1;	    else if (!hex && !got_dot && *p == '.')	      got_dot = 1;	    else if (got_e && (p[-1] == 'e' || p[-1] == 'E')		     && (*p == '-' || *p == '+'))	      /* This is the sign of the exponent, not the end of the		 number.  */	      continue;	    /* We will take any letters or digits.  parse_number will	       complain if past the radix, or if L or U are not final.  */	    else if ((*p < '0' || *p > '9')		     && ((*p < 'a' || *p > 'z')				  && (*p < 'A' || *p > 'Z')))	      break;	  }	toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);        if (toktype == ERROR)	  {	    char *err_copy = (char *) alloca (p - tokstart + 1);	    memcpy (err_copy, tokstart, p - tokstart);	    err_copy[p - tokstart] = 0;	    error ("Invalid number \"%s\".", err_copy);	  }	lexptr = p;

⌨️ 快捷键说明

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