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

📄 y.tab.c

📁 一个c语言开发的小型的dbms系统
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifndef lintstatic char const yyrcsid[] = "$FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28 2000/01/17 02:04:06 bde Exp $";#endif#include <stdlib.h>#define YYBYACC 1#define YYMAJOR 1#define YYMINOR 9#define YYLEX yylex()#define YYEMPTY -1#define yyclearin (yychar=(YYEMPTY))#define yyerrok (yyerrflag=0)#define YYRECOVERING() (yyerrflag!=0)static int yygrowstack();#define YYPREFIX "yy"#line 1 "no_help.y"
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "struct.h"
#include "error.h"



char	sql[256];		/*用于读输入行的*/
int	sqlnum=0;		/*用于表示读到了第几个字符*/
char	*error_var;	/*用来接收各个程序返回的错误提示*/
int 	finish_flag;	/*用来控制主程序的循环,当用户输入"QUIT"时,它的值为1,表示应用结束*/

_dic_type		dic;	/*用来存放数据字典*/

_selectedfields_type	*sf_var1,*sf_end;
_selectedtables_type	*st_var1,*st_end;
_createfieldsdef_type	*cfdef_end;
_insertvalues_type		*iv_var1,*iv_end;
_insertfields_type		*if_var1,*if_end;

#line 27 "no_help.y"typedef union			/*定义yylval的格式*/
{	char			char_var;
	char			*yych;
	/*---------------------------------属于select语法树的类型*/
	_selectedfields_type	*sf_var;
	_selectedtables_type	*st_var;
	_selectstruct_type		*ss_var;
	/*---------------------------------属于create语法树的类型*/
	_createfieldsdef_type	*cfdef_var;
	_createstruct_type		*cs_var;
	/*---------------------------------属于insert语法树的类型*/
	_insertfields_type		*if_var;
	_insertvalues_type		*iv_var;
	_insertstruct_type		*is_var;
	/*---------------------------------属于delete语法树的类型*/
	_deletestruct_type		*ds_var;
	_conditions_type		*cons_var;

} YYSTYPE;#line 62 "no_help.c"#define YYERRCODE 256#define SELECT 257#define FROM 258#define WHERE 259#define IDENTIFIER 260#define NUMBER 261#define CREATE 262#define TABLE 263#define CHAR 264#define INT 265#define DATE 266#define INSERT 267#define INTO 268#define VALUES 269#define DELETE 270#define AND 271#define OR 272#define QUIT 273#define SHOW 274#define TABLES 275#define TABLE_DIC 276#define OF 277#define COLS 278const short yylhs[] = {                                        -1,    0,    0,    0,    0,    0,    0,    0,    1,    1,    2,    2,    5,    5,    3,    3,    4,    4,    7,    6,    8,    8,   12,   10,   10,   11,    9,    9,    9,   17,   14,   14,   13,   13,   15,   15,   16,   16,   16,   18,   18,   23,   23,   23,   19,   20,   21,   21,   21,   21,   22,   22,   24,   24,   24,   25,   25,   25,};const short yylen[] = {                                         2,    1,    1,    1,    1,    2,    2,    2,    5,    7,    1,    1,    1,    3,    1,    3,    1,    3,    1,    1,    1,    1,    7,    1,    3,    2,    4,    1,    1,    9,    0,    3,    1,    3,    1,    3,    3,    3,    1,    6,    4,    1,    7,    7,    3,    1,    1,    3,    3,    1,    1,    3,    1,    1,    1,    2,    2,    4,};const short yydefred[] = {                                      0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    1,    0,   50,    2,    3,    4,   41,    0,   45,    0,    0,   11,    0,    0,   14,    0,   16,    0,    0,    0,    6,   55,   56,    0,    0,    0,   52,   53,   54,    0,    5,    7,    0,    0,    0,   19,    0,    0,    0,    0,    0,   18,   51,   49,    0,   44,   46,    0,   12,   15,   17,    0,    0,    0,    0,   40,   57,    0,    0,    0,    0,    0,    8,    0,    0,    0,   23,   32,    0,    0,    0,    0,    0,   47,   48,    0,   13,    0,   27,   28,   25,    0,    0,    0,   31,    0,   39,    0,    0,    9,    0,   24,   22,   33,   38,    0,    0,   34,   42,   43,    0,    0,    0,    0,    0,   26,   36,   37,   35,   29,};const short yydgoto[] = {                                       9,   10,   22,   23,   24,   57,   11,   12,    0,   90,   75,   76,   13,   78,   63,  106,  107,   14,   15,   16,   17,   55,   18,   19,   39,   20,};const short yysindex[] = {                                    -40,  -34,    0, -256, -259, -241,  -13, -263,  -39,    0,    0,    3,    0,    0,    0,    0,    0,  -20,    0,   -9,   -6,    0, -204,   11,    0,   10,    0, -203, -203, -203,    0,    0,    0, -218,   19, -199,    0,    0,    0,  -37,    0,    0, -203, -197, -199,    0,   24,   27,  -55, -203, -247,    0,    0,    0, -233,    0,    0,  -24,    0,    0,    0, -199, -199, -201,  -39,    0,    0,   30,   31,   33,   34,  -39,    0, -203, -221,  -23,    0,    0,  -22,   35,   15,  -39,  -39,    0,    0,   17,    0,   37,    0,    0,    0, -199,   22, -199,    0,  -36,    0,   42,   43,    0, -183,    0,    0,    0,    0, -227,  -18,    0,    0,    0,   44,   47,   48,  -36,   29,    0,    0,    0,    0,    0,};const short yyrindex[] = {                                      0,    0,  -30,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, -169,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, -179,    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,    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,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,};const short yygindex[] = {                                      0,    0,    0,    0,   49,    0,    9,    4,    0,    0,    0,    2,    0,    0,    0,    0,  -19,    0,    0,    0,    0,    0,   52,   -2,    0,    0,};#define YYTABLESIZE 235const short yytable[] = {                                       8,    8,   54,  105,   65,   26,   34,   27,   21,   28,   25,   18,   31,   32,   18,   33,   19,   29,   92,   94,   73,   91,   93,  114,   67,   68,  113,   69,   70,   18,   18,   18,   18,  111,  112,   72,   46,   47,   48,   52,   36,   38,   37,   87,   88,   89,   30,   26,   60,   35,   40,   58,   25,   41,   42,   43,   44,   45,   66,   49,   50,   51,   80,    2,   61,   74,   77,   62,   79,   85,   81,   82,   83,   84,   96,   95,   99,  100,  110,   97,   98,  102,   86,  108,  109,  115,  116,  117,  119,   10,   30,   56,   59,  101,  118,   74,    0,  103,    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,    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,    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,    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,    0,    0,    0,    0,    0,    0,   64,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    1,    0,    0,    2,    2,    3,    2,   53,  104,    2,    4,   18,    0,    5,    0,    0,    6,    7,   71,};const short yycheck[] = {                                      40,   40,   39,   39,   59,    1,    8,  263,   42,  268,    1,   41,  275,  276,   44,  278,   46,  258,   41,   41,   44,   44,   44,   41,  271,  272,   44,  260,  261,   59,   60,   61,   62,  260,  261,   59,   27,   28,   29,   35,   60,   61,   62,  264,  265,  266,   59,   43,   44,   46,   59,   42,   43,   59,  258,   44,   46,  260,   49,  277,   41,  260,   64,  260,   40,   61,   62,   40,  269,   71,   40,   40,   39,   39,   59,   40,   59,   40,  261,   81,   82,   59,   73,   41,   41,   41,   39,   39,   59,  258,  269,   39,   43,   91,  113,   91,   -1,   93,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  259,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,   -1,   -1,  260,  260,  262,  260,  261,  261,  260,  267,  258,   -1,  270,   -1,   -1,  273,  274,  259,};#define YYFINAL 9#ifndef YYDEBUG#define YYDEBUG 0#endif#define YYMAXTOKEN 278#if YYDEBUGconst char * const yyname[] = {"end-of-file",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,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,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,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,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,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,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,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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"SELECT","FROM","WHERE","IDENTIFIER","NUMBER","CREATE","TABLE","CHAR","INT","DATE","INSERT","INTO","VALUES","DELETE","AND","OR","QUIT","SHOW","TABLES","TABLE_DIC","OF","COLS",};const char * const yyrule[] = {"$accept : statement","statement : selectsql","statement : createsql","statement : insertsql","statement : deletesql","statement : conditions ';'","statement : QUIT ';'","statement : show ';'","selectsql : SELECT fields_star FROM tables ';'","selectsql : SELECT fields_star FROM tables WHERE conditions ';'","fields_star : table_fields","fields_star : '*'","tables : table","tables : tables ',' table","table_fields : table_field","table_fields : table_fields ',' table_field","table_field : field","table_field : table '.' field","field : IDENTIFIER","table : IDENTIFIER","express : IDENTIFIER","express : NUMBER","createsql : CREATE TABLE table '(' fieldsdefinition ')' ';'","fieldsdefinition : field_type","fieldsdefinition : fieldsdefinition ',' field_type","field_type : field type","type : CHAR '(' NUMBER ')'","type : INT","type : DATE","insertsql : INSERT INTO table fields_choosed VALUES '(' values ')' ';'","fields_choosed :","fields_choosed : '(' fields ')'","fields : field","fields : fields ',' field","values : avalue","values : values ',' avalue","avalue : '\\'' IDENTIFIER '\\''","avalue : '\\'' NUMBER '\\''","avalue : NUMBER","deletesql : DELETE FROM table WHERE conditions ';'","deletesql : DELETE FROM table ';'","conditions : condition","conditions : '(' conditions ')' AND '(' conditions ')'","conditions : '(' conditions ')' OR '(' conditions ')'","condition : comp_left comp_op comp_right","comp_left : table_field_","comp_right : table_field_","comp_right : '\\'' IDENTIFIER '\\''","comp_right : '\\'' NUMBER '\\''","comp_right : NUMBER","table_field_ : field","table_field_ : table '.' field","comp_op : '<'","comp_op : '>'","comp_op : '='","show : SHOW TABLES","show : SHOW TABLE_DIC","show : SHOW COLS OF table",};#endif#if YYDEBUG#include <stdio.h>#endif#ifdef YYSTACKSIZE#undef YYMAXDEPTH#define YYMAXDEPTH YYSTACKSIZE#else#ifdef YYMAXDEPTH#define YYSTACKSIZE YYMAXDEPTH#else#define YYSTACKSIZE 10000#define YYMAXDEPTH 10000#endif#endif#define YYINITSTACKSIZE 200int yydebug;int yynerrs;int yyerrflag;int yychar;short *yyssp;YYSTYPE *yyvsp;YYSTYPE yyval;YYSTYPE yylval;short *yyss;short *yysslim;YYSTYPE *yyvs;int yystacksize;#line 465 "no_help.y"

typedef	struct	tokentype{
	char 	*name; 
	int 	value; 
	}tokentype;

tokentype tokens[] =	/*这里只列出了没有定义类型的终结符*/
{	"SELECT",		SELECT,
	"FROM",		FROM,
	"WHERE",		WHERE,
	"CREATE",		CREATE,
	"TABLE",		TABLE,
	"CHAR",		CHAR,
	"INT",		INT,
	"DATE",		DATE,
	"INSERT",		INSERT,
	"INTO",		INTO,
	"VALUES",		VALUES,
	"DELETE",		DELETE,
	"AND",		AND,
	"OR",		OR,
	"QUIT",		QUIT,
	"SHOW",		SHOW,
	"TABLES",		TABLES,
	"TABLE_DIC",	TABLE_DIC,
	"COLS",		COLS,
	"OF",		OF,
	"\0",		'\0'	
};

int is_number(char *s)	/*用来判断一个字符串是不是数字*/
{
	char *ss;
	ss=s;
	while (*ss!='\0')
	{	if (*ss<'0' || *ss>'9')  
			return(0);
		ss++;
	}
	return(1);
}

void low_to_up(char *s)	/*把一个字符串变为大写的*/
{	unsigned	int i;
	for(i=0;i<strlen(s);i++)
	{	s[i]=toupper(s[i]);
	}
}
int is_token(char *s)	/*用来判断一个字符串是不是一个无类型定义的token*/
{
	char *str;
	int	i=0;
	str=strdup(s);
	low_to_up(str);
	while(1)
	{
		if (strlen(tokens[i].name)==0)	break;	
		if (strcmp(tokens[i].name,str)==0)
		{	free(str);
			return(tokens[i].value);	/*是token,返回对应的值*/
		}
		i++;
	}
	free(str);
	return(0);		/*不是,则返回0*/
}

int is_legal(char s)	/*用来判断一个字符是不是字符串中的合法字符*/
{	int flag=0;
	if(s>='a' && s<='z')	flag=1;
	if(s>='A' && s<='Z')  	flag=1;
	if(s=='_') 	    	flag=1;
	if(s>='0' && s<='9')  	flag=1;
	if(flag==0)  return(0);	/*不是*/
	return(1);		/*是*/
}
		
int is_identifier(char *s)	/*用来判断一个字符串是不是合格的标识符*/
{
	char *ss;
	ss=s;
	while(*ss!='\0')
	{	if(is_legal(*ss)==0)  return(0);
		ss++;
	}
	return(1);
}

void readaword(char *aword)	/*将下一个词读入aword中*/
{
	char ss;
	int  awordnum=0;
	ss=sql[sqlnum];
	while( is_legal(ss))
	{	aword[awordnum]=ss;
		awordnum++;

⌨️ 快捷键说明

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