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

📄 m2-exp.tab.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
# line 32 "./m2-exp.y"#include <stdio.h>#include <string.h>#include "defs.h"#include "symtab.h"#include "gdbtypes.h"#include "frame.h"#include "expression.h"#include "language.h"#include "value.h"#include "parser-defs.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 m2_maxdepth#define	yyparse	m2_parse#define	yylex	m2_lex#define	yyerror	m2_error#define	yylval	m2_lval#define	yychar	m2_char#define	yydebug	m2_debug#define	yypact	m2_pact#define	yyr1	m2_r1#define	yyr2	m2_r2#define	yydef	m2_def#define	yychk	m2_chk#define	yypgo	m2_pgo#define	yyact	m2_act#define	yyexca	m2_exca#define yyerrflag m2_errflag#define yynerrs	m2_nerrs#define	yyps	m2_ps#define	yypv	m2_pv#define	yys	m2_s#define	yy_yys	m2_yys#define	yystate	m2_state#define	yytmp	m2_tmp#define	yyv	m2_v#define	yy_yyv	m2_yyv#define	yyval	m2_val#define	yylloc	m2_lloc#define yyss	m2_yyss		/* byacc */#define	yyssp	m2_yysp		/* byacc */#define	yyvs	m2_yyvs		/* byacc */#define	yyvsp	m2_yyvsp	/* byacc */#if 0static char *make_qualname PARAMS ((char *, char *));#endifstatic intparse_number PARAMS ((int));static intyylex PARAMS ((void));static voidyyerror PARAMS ((char *));intyyparse PARAMS ((void));/* The sign of the number being parsed. */int number_sign = 1;/* The block that the module specified by the qualifer on an identifer is   contained in, */struct block *modblock=0;/* #define	YYDEBUG	1 */# line 112 "./m2-exp.y"typedef union   {    LONGEST lval;    unsigned LONGEST ulval;    double dval;    struct symbol *sym;    struct type *tval;    struct stoken sval;    int voidval;    struct block *bval;    enum exp_opcode opcode;    struct internalvar *ivar;    struct type **tvec;    int *ivec;  } YYSTYPE;# define INT 257# define HEX 258# define ERROR 259# define UINT 260# define M2_TRUE 261# define M2_FALSE 262# define CHAR 263# define FLOAT 264# define STRING 265# define NAME 266# define BLOCKNAME 267# define IDENT 268# define VARNAME 269# define TYPENAME 270# define SIZE 271# define CAP 272# define ORD 273# define HIGH 274# define ABS 275# define MIN_FUNC 276# define MAX_FUNC 277# define FLOAT_FUNC 278# define VAL 279# define CHR 280# define ODD 281# define TRUNC 282# define INC 283# define DEC 284# define INCL 285# define EXCL 286# define COLONCOLON 287# define LAST 288# define REGNAME 289# define INTERNAL_VAR 290# define ABOVE_COMMA 291# define ASSIGN 292# define LEQ 293# define GEQ 294# define NOTEQUAL 295# define IN 296# define OROR 297# define ANDAND 298# define DIV 299# define MOD 300# define UNARY 301# define DOT 302# define NOT 303# define QID 304# line 181 "./m2-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 673 "./m2-exp.y"#if 0  /* FIXME! */intoverflow(a,b)   long a,b;{   return (MAX_OF_TYPE(builtin_type_m2_int) - b) < a;}intuoverflow(a,b)   unsigned long a,b;{   return (MAX_OF_TYPE(builtin_type_m2_card) - b) < a;}#endif /* FIXME *//* 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 (olen)     int olen;{  register char *p = lexptr;  register LONGEST n = 0;  register LONGEST prevn = 0;  register int c,i,ischar=0;  register int base = input_radix;  register int len = olen;  int unsigned_p = number_sign == 1 ? 1 : 0;  if(p[len-1] == 'H')  {     base = 16;     len--;  }  else if(p[len-1] == 'C' || p[len-1] == 'B')  {     base = 8;     ischar = p[len-1] == 'C';     len--;  }  /* Scan the number */  for (c = 0; c < len; c++)  {    if (p[c] == '.' && base == 10)      {	/* It's a float since it contains a point.  */	yylval.dval = atof (p);	lexptr += len;	return FLOAT;      }    if (p[c] == '.' && base != 10)       error("Floating point numbers must be base 10.");    if (base == 10 && (p[c] < '0' || p[c] > '9'))       error("Invalid digit \'%c\' in number.",p[c]); }  while (len-- > 0)    {      c = *p++;      n *= base;      if( base == 8 && (c == '8' || c == '9'))	 error("Invalid digit \'%c\' in octal number.",c);      if (c >= '0' && c <= '9')	i = c - '0';      else	{	  if (base == 16 && c >= 'A' && c <= 'F')	    i = c - 'A' + 10;	  else	     return ERROR;	}      n+=i;      if(i >= base)	 return ERROR;      if(!unsigned_p && number_sign == 1 && (prevn >= n))	 unsigned_p=1;		/* Try something unsigned */      /* Don't do the range check if n==i and i==0, since that special	 case will give an overflow error. */      if(RANGE_CHECK && n!=i && i)      {	 if((unsigned_p && (unsigned)prevn >= (unsigned)n) ||	    ((!unsigned_p && number_sign==-1) && -prevn <= -n))	    range_error("Overflow on numeric constant.");      }	 prevn=n;    }  lexptr = p;  if(*p == 'B' || *p == 'C' || *p == 'H')     lexptr++;			/* Advance past B,C or H */  if (ischar)  {     yylval.ulval = n;     return CHAR;  }  else if ( unsigned_p && number_sign == 1)  {     yylval.ulval = n;     return UINT;  }  else if((unsigned_p && (n<0))) {     range_error("Overflow on numeric constant -- number too large.");     /* But, this can return if range_check == range_warn.  */  }  yylval.lval = n;  return INT;}/* Some tokens */static struct{   char name[4];   int token;} tokentab2[] ={    { {'<', '>'},    NOTEQUAL 	},    { {':', '='},    ASSIGN	},    { {'<', '='},    LEQ	},    { {'>', '='},    GEQ	},    { {':', ':'},    COLONCOLON },};/* Some specific keywords */struct keyword {   char keyw[10];   int token;};static struct keyword keytab[] ={    {"OR" ,   OROR	 },    {"IN",    IN         },/* Note space after IN */    {"AND",   ANDAND     },    {"ABS",   ABS	 },    {"CHR",   CHR	 },    {"DEC",   DEC	 },    {"NOT",   NOT	 },    {"DIV",   DIV    	 },    {"INC",   INC	 },    {"MAX",   MAX_FUNC	 },    {"MIN",   MIN_FUNC	 },    {"MOD",   MOD	 },    {"ODD",   ODD	 },    {"CAP",   CAP	 },    {"ORD",   ORD	 },    {"VAL",   VAL	 },    {"EXCL",  EXCL	 },    {"HIGH",  HIGH       },    {"INCL",  INCL	 },    {"SIZE",  SIZE       },    {"FLOAT", FLOAT_FUNC },    {"TRUNC", TRUNC	 },};/* Read one token, getting characters through lexptr.  *//* This is where we will check to make sure that the language and the operators used are   compatible  */static intyylex (){  register int c;  register int namelen;  register int i;  register char *tokstart;  register char quote; retry:  tokstart = lexptr;  /* See if it is a special token of length 2 */  for( i = 0 ; i < sizeof tokentab2 / sizeof tokentab2[0] ; i++)     if(!strncmp(tokentab2[i].name, tokstart, 2))     {	lexptr += 2;	return tokentab2[i].token;     }  switch (c = *tokstart)    {    case 0:      return 0;    case ' ':    case '\t':    case '\n':      lexptr++;      goto retry;    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')	break;			/* Falls into number code.  */      else      {	 lexptr++;	 return DOT;      }/* These are character tokens that appear as-is in the YACC grammar */    case '+':    case '-':    case '*':    case '/':    case '^':    case '<':    case '>':    case '[':    case ']':    case '=':    case '{':    case '}':    case '#':    case '@':    case '~':    case '&':      lexptr++;      return c;    case '\'' :    case '"':      quote = c;      for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++)	if (c == '\\')	  {	    c = tokstart[++namelen];	    if (c >= '0' && c <= '9')	      {		c = tokstart[++namelen];		if (c >= '0' && c <= '9')		  c = tokstart[++namelen];	      }	  }      if(c != quote)	 error("Unterminated string or character constant.");      yylval.sval.ptr = tokstart + 1;      yylval.sval.length = namelen - 1;      lexptr += namelen + 1;      if(namelen == 2)  	/* Single character */      {	   yylval.ulval = tokstart[1];	   return CHAR;      }      else	 return STRING;    }  /* Is it a number?  */  /* Note:  We have already dealt with the case of the token '.'.     See case '.' above.  */  if ((c >= '0' && c <= '9'))    {      /* It's a number.  */      int got_dot = 0, got_e = 0;      register char *p = tokstart;      int toktype;      for (++p ;; ++p)	{	  if (!got_e && (*p == 'e' || *p == 'E'))	    got_dot = got_e = 1;	  else if (!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;	  else if ((*p < '0' || *p > '9') &&		   (*p < 'A' || *p > 'F') &&		   (*p != 'H'))  /* Modula-2 hexadecimal number */	    break;	}	toktype = parse_number (p - tokstart);        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;	return toktype;    }  if (!(c == '_' || c == '$'	|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))    /* We must have come across a bad character (e.g. ';').  */    error ("Invalid character '%c' in expression.", c);  /* It's a name.  See how long it is.  */  namelen = 0;  for (c = tokstart[namelen];       (c == '_' || c == '$' || (c >= '0' && c <= '9')	|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));       c = tokstart[++namelen])    ;

⌨️ 快捷键说明

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