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

📄 vy.tab.c

📁 編譯器的虛擬yacc工具
💻 C
📖 第 1 页 / 共 3 页
字号:
# line 2 "./ny.temp.y"typedef enum {ny_empty,ny_terminal,ny_nonTerminal} ny_TokenType;#include <stdio.h>#include "nytags.h"char *union_found();char *output_default_types();char *special();char *output_spec();char *attr_type;char *dump_attrs(), *new_info();char *check_name();char *new_lhs();char *visual(), *extended(), *init_count(), *re_init_count(), *process();/* tag meanings:  FIND_UNION -- detects whether there is a user-defined union present                sets a flag approprately  DEFAULT -- transforms a yacc specification that has no union.     Here we have 2 cases; either there is no attribute use, or      there is a default integer attribute.  In this case, we define     a union with a single integer attribute.  All tokens and types     get this default type.  EXTEND -- this deals with the more interesting case where there is     a union defined and this union needs to be extended appropriatelyE. White*/# define UNION_T 257# define TOKEN_T 258# define LEFT_T 259# define RIGHT_T 260# define TYPE_T 261# define NONASSOC_T 262# define PREC_T 263# define NAME 264# define DIVIDER 265# define CHAR 266# define STRING 267# define START_C 268# define STOP_C 269# define LHS 270# define RHS 271# define BRACKET_KEYWORD 272# define POUND_KEYWORD 273# define KEYWORD 274# define SPECIAL_KEYWORD 275#ifdef __STDC__#include <stdlib.h>#include <string.h>#else#include <malloc.h>#include <memory.h>#endif#include <values.h>#ifdef __cplusplus#ifndef yyerror	void yyerror(const char *);#endif#ifndef yylex#ifdef __EXTERN_C__	extern "C" { int yylex(void); }#else	int yylex(void);#endif#endif	int yyparse(void);#endif#define yyclearin yychar = -1#define yyerrok yyerrflag = 0extern int yychar;extern int yylineno; extern int yyerrflag;#ifndef YYSTYPE#define YYSTYPE int#endifYYSTYPE yylval;YYSTYPE yyval;typedef int yytabelem;#ifndef YYMAXDEPTH#define YYMAXDEPTH 150#endif#if YYMAXDEPTH > 0int yy_yys[YYMAXDEPTH], *yys = yy_yys;YYSTYPE yy_yyv[YYMAXDEPTH], *yyv = yy_yyv;#else	/* user does initial allocation */int *yys;YYSTYPE *yyv;#endifstatic int yymaxdepth = YYMAXDEPTH;# define YYERRCODE 256# line 240 "./ny.temp.y"char *myprint(s)char *s;{  if(s != 0) fputs(s,stdout);  return NULL;}yyerror(){  fprintf(stderr, "syntax error on line %d\n",yylineno);  fflush(stderr);  exit(1);}typedef struct {  char *name;  char *attr_name;  int special;} attr_info;attr_info attributes[256];int num_attrs = 0;char *special_names[100];int rule_elem[100];int specialct = 0;int count;char *init_count() {count = 0; return NULL;}char *re_init_count() {count = 1; return NULL;}char *process(int argc,char**argv) {  int ct;  rule_elem[count] = -1;    for (ct=0;ct<num_attrs;ct++)     if (strcmp(argv[0],attributes[ct].name) == 0)       rule_elem[count] = ct;    count++;  return NULL;}char *visual() {  if (rule_elem[0] != -1)     if (attributes[rule_elem[0]].special >= 0) {      printf("$$.x[%d] =  $$.%s;\n",attributes[rule_elem[0]].special,         attributes[rule_elem[0]].attr_name);     }  return NULL;}char *extended(int argc, char**argv) {  if (strcmp(argv[0],"$$") ==0) {    printf(".%s",attributes[rule_elem[0]].attr_name);  } else {   (argv[0])++;    printf(".%s",attributes[rule_elem[atoi(argv[0])]].attr_name);     }  return NULL;}char *special(int argc, char**argv) {  int i;  special_names[specialct] = (char*)malloc(strlen(argv[0])+1);  strcpy(special_names[specialct], argv[0]);   for (i = 0;i<num_attrs;i++) {     if (strcmp(attributes[i].attr_name,argv[0]) == 0)       attributes[i].special = specialct;  }  specialct++; return NULL;}char *output_spec(){if (specialct) printf("int x[%d];\n",specialct);   else printf("int x[1];\n"); return NULL;}int union_f ;char*union_found() {union_f = 1; return NULL;}char *output_default_types() {  printf("%%union {\n  struct {\n     int x[1];  \n} vyacc_attrs;\n}\n");  return NULL;}char* dump_attrs() {  int ct;  printf("/*\n");  for (ct=0;ct<num_attrs;ct++) {    printf("%d: %s has type %s (%d)\n",ct,attributes[ct].name,attributes[ct].attr_name,        attributes[ct].special);  }  printf("*/\n");  return NULL;}char *check_name(int argc,char**argv) {  int i;  if (argc == 1) {    for (i=0;i<num_attrs;i++)      if (strcmp(argv[0],attributes[i].name) == 0)          if (strcmp(attributes[i].attr_name,"vy_none") != 0)             printf("%s ",argv[0]);  }  return NULL;}char *new_info(int argc,char**argv) {  int len;  if (argc == 2) {     if (strcmp(argv[0],"") == 0) ;     else {       attributes[num_attrs].name = (char*)malloc(strlen(argv[1])+1);       strcpy(attributes[num_attrs].name, argv[1]);       attributes[num_attrs].attr_name = (char*)malloc(strlen(argv[0]));       len =strlen(argv[0]);       argv[0][len-1] = '\0';       (argv[0])++;       strcpy(attributes[num_attrs].attr_name,argv[0]);       attributes[num_attrs].special = -1;       num_attrs++;     }  }  return NULL;}main(){  if (yyparse() != 0) {fprintf(stderr,"exiting"); exit(1); }  union_f = 0;  nyprint(myprint,FIND_UNION,NY_SELECT,NY_NORMAL);  if (union_f)  {    nyprint(myprint,EXTEND,NY_OPEN,NY_NORMAL);  }  else /* fix default case */ {    nyprint(myprint,DEFAULT,NY_OPEN,NY_NORMAL);  }}static const yytabelem yyexca[] ={-1, 1,	0, -1,	-2, 0,	};# define YYNPROD 64# define YYLAST 370static const yytabelem yyact[]={    23,    46,    25,    85,    55,    28,    57,    34,    35,    31,    29,    22,    30,    44,    32,    45,    41,    65,    44,    66,    45,    42,    39,    40,    54,    71,    33,    26,    24,    27,    23,    54,    25,    81,    51,    28,    80,    34,    35,    31,    29,    22,    30,    15,    32,    79,    61,    72,    53,    83,     3,    84,    59,    14,    78,    18,    33,    26,    24,    27,    23,    16,    25,     4,    69,    28,    52,    34,    35,    31,    29,    22,    30,     2,    32,     1,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,    33,    26,    24,    27,    38,    60,    94,    62,    63,     0,     0,    23,    82,    25,    58,    70,    28,     0,    34,    35,    31,    29,    22,    30,     0,    32,     0,    68,     0,    77,    74,    75,     0,     0,    38,     0,    92,    33,    26,    24,    27,    23,    90,    25,     0,    17,    28,    89,    34,    35,    31,    29,    22,    30,    93,    32,     0,    88,    86,     0,    87,    91,    56,     0,    38,     0,    76,    33,    26,    24,    27,    12,     6,     8,     9,     7,    10,    11,     0,    13,     0,    43,     5,    12,     6,     8,     9,     7,    10,    11,    47,    48,    49,    50,     5,     0,     0,     0,     0,     0,     0,    38,     0,    73,    56,     0,     0,     0,     0,     0,     0,     0,     0,     0,    56,     0,     0,     0,     0,     0,     0,     0,     0,     0,    64,     0,     0,     0,    67,     0,     0,    38,     0,     0,     0,     0,     0,    56,     0,     0,     0,     0,     0,     0,     0,    41,     0,    36,    37,     0,     0,    39,    40,     0,    19,    20,    21,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,    41,     0,    36,    37,     0,     0,    39,    40,     0,    19,    20,    21,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,    41,     0,    36,    37,     0,     0,    39,    40,     0,    19,    20,    21,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,    41,     0,    36,    37,     0,     0,    39,    40,     0,    19,    20,    21,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,    41,     0,    36,    37,     0,     0,    39,    40,     0,    19,    20,    21 };static const yytabelem yypact[]={   -88,-10000000,  -100,-10000000,-10000000,    94,  -251,  -271,  -246,  -246,  -246,  -246,   -89,  -233,-10000000,  -265,    94,-10000000,-10000000,-10000000,-10000000,  -258,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,    94,     0,     0,     0,  -246,  -247,-10000000,-10000000,  -246,  -247,  -247,  -247,  -247,    94,  -240,-10000000,   -11,-10000000,-10000000,-10000000,    64,-10000000,  -248,  -248,-10000000,-10000000,  -247,-10000000,-10000000,  -247,    27,-10000000,-10000000,    94,-10000000,-10000000,   -57,-10000000,-10000000,-10000000,   -26,  -120,     0,-10000000,-10000000,-10000000,-10000000,    -3,-10000000,-10000000,-10000000,-10000000,  -120,   -33,-10000000,-10000000,-10000000 };static const yytabelem yypgo[]={     0,    75,    73,    66,    64,    50,    63,    43,   167,    61,   131,    55,    52,    48,    54,    45,    49,    51 };static const yytabelem yyr1[]={     0,     1,     2,     2,     5,     5,     6,     6,     6,     6,     6,     6,     6,     6,     8,     8,     8,     8,     4,     4,     7,     7,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,    10,     9,     9,    11,    11,    11,    12,    12,    12,     3,     3,    13,    14,    14,    16,    16,    16,    15,    15,    17,    17,    17 };static const yytabelem yyr2[]={     0,     9,     5,     3,     3,     7,     7,     5,     7,     5,     5,     5,     5,     9,     5,     5,     3,     3,     1,     5,     3,     1,     3,     3,     3,     5,     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,     7,     5,     3,     5,     5,     5,     9,     5,     1,     5,     3,     9,     9,     5,     1,     7,     5,     5,     1,     3,     3,     3 };static const yytabelem yychk[]={-10000000,    -1,    -2,    -5,    -6,   268,   258,   261,   259,   260,   262,   263,   257,   265,    -5,    -7,    -9,   -10,   -11,   273,   274,   275,    44,    33,    61,    35,    60,    62,    38,    43,    45,    42,    47,    59,    40,    41,   266,   267,   123,   270,   271,   264,   272,    -8,   264,   266,   272,    -8,    -8,    -8,    -8,   123,    -3,   -13,   264,   269,   -10,   264,    -9,   -12,    91,    46,   -12,   -12,    -8,   264,   266,    -8,    -9,    -4,   -13,   265,    58,   125,   -11,   -11,   125,    -7,   -14,   -15,    93,    59,   124,   -16,   -17,   123,   264,   266,   263,   -12,   -15,    -9,   125,   -16,   125 };static const yytabelem yydef[]={     0,    -2,     0,     3,     4,    21,     0,     0,     0,     0,     0,     0,     0,     0,     2,     0,    20,    44,    22,    23,    24,     0,    26,    27,    28,    29,    30,    31,    32,    33,    34,    35,    36,    37,    38,    39,    40,    41,     0,    50,    50,    50,     0,     7,    16,    17,     0,     9,    10,    11,    12,     0,    18,    52,     0,     5,    43,    25,     0,    45,     0,     0,    46,    47,     6,    14,    15,     8,     0,     1,    51,    21,    60,    42,     0,    49,    13,    19,     0,    56,    50,    53,    60,    55,    59,     0,    61,    62,    63,    48,    56,     0,    58,    54,    57 };typedef struct#ifdef __cplusplus	yytoktype#endif{ char *t_name; int t_val; } yytoktype;#ifndef YYDEBUG#	define YYDEBUG	0	/* don't allow debugging */#endif#if YYDEBUGyytoktype yytoks[] ={	"UNION_T",	257,	"TOKEN_T",	258,	"LEFT_T",	259,	"RIGHT_T",	260,	"TYPE_T",	261,	"NONASSOC_T",	262,	"PREC_T",	263,	"NAME",	264,	"DIVIDER",	265,	"CHAR",	266,	"STRING",	267,	"START_C",	268,	"STOP_C",	269,	"LHS",	270,	"RHS",	271,	"BRACKET_KEYWORD",	272,	"POUND_KEYWORD",	273,	"KEYWORD",	274,	"SPECIAL_KEYWORD",	275,	"-unknown-",	-1	/* ends search */};char * yyreds[] ={	"-no such reduction-",	"yacc_spec : beginning DIVIDER rule_list ending",	"beginning : beginning beginning_elem",	"beginning : beginning_elem",	"beginning_elem : yacc_info",	"beginning_elem : START_C opt_yacc_rest STOP_C",	"yacc_info : TOKEN_T BRACKET_KEYWORD token_list",	"yacc_info : TOKEN_T token_list",	"yacc_info : TYPE_T BRACKET_KEYWORD token_list",	"yacc_info : LEFT_T token_list",	"yacc_info : RIGHT_T token_list",	"yacc_info : NONASSOC_T token_list",	"yacc_info : PREC_T token_list",	"yacc_info : UNION_T '{' yacc_rest '}'",	"token_list : token_list NAME",	"token_list : token_list CHAR",	"token_list : NAME",	"token_list : CHAR",	"ending : /* empty */",	"ending : DIVIDER opt_yacc_rest",	"opt_yacc_rest : yacc_rest",	"opt_yacc_rest : /* empty */",	"yacc_elem : yacc_variable_name",	"yacc_elem : POUND_KEYWORD",	"yacc_elem : KEYWORD",	"yacc_elem : SPECIAL_KEYWORD NAME",	"yacc_elem : ','",	"yacc_elem : '!'",	"yacc_elem : '='",	"yacc_elem : '#'",	"yacc_elem : '<'",	"yacc_elem : '>'",	"yacc_elem : '&'",	"yacc_elem : '+'",	"yacc_elem : '-'",	"yacc_elem : '*'",	"yacc_elem : '/'",	"yacc_elem : ';'",	"yacc_elem : '('",	"yacc_elem : ')'",	"yacc_elem : CHAR",	"yacc_elem : STRING",	"yacc_elem : '{' yacc_rest '}'",	"yacc_rest : yacc_rest yacc_elem",	"yacc_rest : yacc_elem",

⌨️ 快捷键说明

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