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

📄 sql语法.c

📁 语言的语法,格式严紧,对于处理yacc,lex有帮助!
💻 C
📖 第 1 页 / 共 4 页
字号:
发信人: InfoMagic (好好学习 天天向上), 信区: PUE 

标  题: sql 语法 

发信站: 武汉白云黄鹤站 (2001年05月23日22:58:17 星期三), 站内信件 

  

#! /bin/sh 

# This is a shell archive.  Remove anything before this line, then unpack 

# it by saving it into a file and typing "sh file".  To overwrite existing 

# files, type "sh file -c".  You can also feed this as standard input via 

# unshar, or by typing "sh <file", e.g..  If this archive is complete, you 

# will see the following message at the end: 

#  "End of shell archive." 

# Contents:  Cain.SQL Makefile README ddf.h dsl.l dsl.y ed0 ed1 ed2 

#   gtok.h parser.c phm.c rwsearch.c testpar tf.l tmprws.h tpar.c 

#   vtest2 

# Wrapped by meyerweg@ndbs on Tue Oct 31 11:42:22 1989 

PATH=/bin:/usr/bin:/usr/ucb ; export PATH 

if test -f Cain.SQL -a "${1}" != "-c" ; then 

  echo shar: Will not over-write existing file \"Cain.SQL\" 

else 

echo shar: Extracting \"Cain.SQL\" \(1880 characters\) 

sed "s/^X//" >Cain.SQL <<'END_OF_Cain.SQL' 

XPath: incas!unido!mcsun!uunet!cuc1!lcain 

XFrom: lcain@cuc1.UUCP (Leroy Cain) 

XNewsgroups: comp.databases 

XSubject: ISO/ANSI SQL Parser in LEX/YACC 

XKeywords: ISO ANSI SQL LEX YACC 

XMessage-ID: <2137@cuc1.UUCP> 

XDate: 15 Sep 89 21:50:08 GMT 

XOrganization: Columbia Union College; Takoma Park, MD 20912 

XLines: 42 

XPosted: Fri Sep 15 22:50:08 1989 

X 

X 

XHi Guys 

X 

XThe LEX/YACC parser for ANSI SQL is almost done.  What I am look for 

Xnow is several of you that are familiar the ANSI specification to 

Xreview my work before I release it, so that it will be as error free 

Xas possible. 

X 

XFor the rest of you here are some highlights of this package. 

X 

XThis is an parser for ISO/ANSI SQL written useing LEX, YACC, and C 

Xit provide syntax check and a frame for building a completed 

Xquery processor. 

XSee ANSI X3.135-1986 and ANSI X3.135.1-198x Addendum 1 

X ISO 9075-1987(E) Addendum 1 

X 

XUnlike the previous SQL parser I posted, this one can be process with 

Xa normal YACC so everyone should be able to use it. 

X 

XThere are three parts: 

X 1. Module -- This processes the module specification and 

X   produces function calls to which ever language 

X   is specificied. 

X 2. Embedded -- This processes the embedded SQL specification and 

X   produces function calls to which ever language 

X   is specificied. 

X 3. Internal -- This processes SQL command passed to the function 

X   interface. 

X 

XNotes: 

X In Module and Embedded you add the code to produce the function 

X calls. 

X Language specificied for use with Module and Embedded are C, COBOL, 

X FORTRAN, Pascal, PL/1. 

X C as a possible langauge for Module and Embedded is not specificied 

X in the ANSI specs.  This is the only place I deveated. 

X 

X 

XMS-DOS Just say NO!!!!!         OS/2 Why???? 

XLeroy Cain;      Columbia Union College;      Mathematical Sciences 

Department 

X7600 Flower Ave. WH406;                 Takoma Park, Md 20912 

X(301) 891-4172          uunet!cucstud!lcain 

X 

END_OF_Cain.SQL 

if test 1880 -ne `wc -c <Cain.SQL`; then 

    echo shar: \"Cain.SQL\" unpacked with wrong size! 

fi 

# end of overwriting check 

fi 

if test -f Makefile -a "${1}" != "-c" ; then 

  echo shar: Will not over-write existing file \"Makefile\" 

else 

echo shar: Extracting \"Makefile\" \(510 characters\) 

sed "s/^X//" >Makefile <<'END_OF_Makefile' 

X# Makefile for Data sublanguages 

X# written 1985 by Leroy Cain 

X# modified 1989 by Klaus Meyer-Wegener 

X 

XALL: tpar 

X 

Xtpar : tpar.c parser.c y.tab.o 

X cc -o tpar tpar.c parser.c y.tab.o -ll 

X 

Xy.tab.o: y.tab.c lex.yy.c parser.h gtok.h 

X cc -c y.tab.c 

X 

Xy.tab.c: dsl.y 

X yacc -vd dsl.y 

X 

Xlex.yy.c: dsl.l 

X lex dsl.l 

X ./ed0 

X 

Xparser.h: y.tab.h tmprws.h phm 

X ./ed1 

X sort +2 -3 y.h | ./phm 

X ./ed2 `wc y.h` 

X 

Xphm: phm.c 

X cc -o phm phm.c 

X 

Xtf: tf.l 

X lex -t tf.l > tf.yy.c 

X cc -o tf tf.yy.c 

X 

Xtest: tf vtest2 tpar 

X tf < vtest2 | tpar 

END_OF_Makefile 

if test 510 -ne `wc -c <Makefile`; then 

    echo shar: \"Makefile\" unpacked with wrong size! 

fi 

# end of overwriting check 

fi 

if test -f README -a "${1}" != "-c" ; then 

  echo shar: Will not over-write existing file \"README\" 

else 

echo shar: Extracting \"README\" \(1879 characters\) 

sed "s/^X//" >README <<'END_OF_README' 

XThis directory contains the parser for DDF.  The components are as follows 

X 

XMakefile 

XREADME 

X 

XPROGRAM FILES 

Xdsl.l           Lex for parser 

Xdsl.y           Yacc for parser 

Xparser.c        Main parser function 

Xrwsearch.c      Reserved word table search functions 

Xtpar.c  Main for testing parser 

X 

XINCLUDE FILES 

Xtmprws.h template for parser.h; filled with data generated from 

X  y.tab.h (output of yacc) 

Xddf.h  definition of type DDFRUN 

Xgtok.h  Parser tree token definitions 

X 

XAUXILIARY SHELL SCRIPTS AND PROGRAMS 

Xed0  edit script for lex; executed after generating lex.yy.c 

X  from dsl.l; removes the definitions of makros input(), 

X  output(c), and unput(c) - they are redefined in parser.c 

Xed0.out  stdout protocol of ed0 actions 

Xed1  edit script for yacc; modifies the output y.tab.h of 

X  yacc to produce y.h; y.h is sorted and piped through phm 

X  to produce rnums and rwords 

Xed1.out  stdout protocol of ed1 actions 

Xed2  edit script for yacc; generates file nt containing 'wc y.h'; 

X  opens tmprws.h, inserts nt, rnums, and rwords in 

X  appropriate places, and writes parser.h 

Xed2.out  stdout protocol of ed2 actions 

Xphm.c  reads y.h to generate rnums and rwords 

Xphm  result of cc -o phm phm.c 

X 

XTEMPFILES 

Xlex.yy.c lex output generated from dsl.l 

Xy.tab.c  yacc program ( yyparse() ) generated from dsl.y 

Xy.tab.h  include with token definitions generated by yacc 

Xy.output states and transitions documented by yacc 

Xrnums 

Xrwords 

Xnt 

Xparser.h        parser related tables, defines and variables; 

X  generated by ed2 

Xy.tab.o  object module yyparse 

Xparser.o object module parse 

X 

XTEST 

Xvtest2  list of sql statements 

Xtf.l  lex definition to eliminate numbers from vtest2 

Xtf.yy.c  lex output generated from tf.l 

Xtf  result of cc -0 tf tf.yy.c -ll 

Xtpar  main test program; reads stdin and writes pt_file 

Xtestpar  shell script to execute tpar: tf < vtest2 | tpar 

Xpt_file  parse tree test output file 

END_OF_README 

if test 1879 -ne `wc -c <README`; then 

    echo shar: \"README\" unpacked with wrong size! 

fi 

# end of overwriting check 

fi 

if test -f ddf.h -a "${1}" != "-c" ; then 

  echo shar: Will not over-write existing file \"ddf.h\" 

else 

echo shar: Extracting \"ddf.h\" \(94 characters\) 

sed "s/^X//" >ddf.h <<'END_OF_ddf.h' 

Xtypedef struct sql_run 

X{ 

X        unsigned char   *par_buf; 

X        int     buf_len; 

X} DDFRUN; 

END_OF_ddf.h 

if test 94 -ne `wc -c <ddf.h`; then 

    echo shar: \"ddf.h\" unpacked with wrong size! 

fi 

# end of overwriting check 

fi 

if test -f dsl.l -a "${1}" != "-c" ; then 

  echo shar: Will not over-write existing file \"dsl.l\" 

else 

echo shar: Extracting \"dsl.l\" \(1806 characters\) 

sed "s/^X//" >dsl.l <<'END_OF_dsl.l' 

X/* 

XDistributed data base Facilitator 

XParser 

XVersion 1.0 

XCopyright 1986 Columbia Union College 

XBy Leroy G. Cain 

X*/ 

X%{ 

X#include "string.h" 

X#include "parser.h" 

X#include "rwsearch.c" 

X%} 

XD       [0-9] 

XE       [Ee][-+]?{D}+ 

X%% 

X[a-zA-Z]+ 

X{ 

Xint     rw; 

X 

X        if((rw= rwsearch(yytext)) == IDENTIFIER ) 

X        { 

X                yylval.nsbuf = strcpy(scratch,yytext); 

X        } 

X                return rw; 

X} 

X 

X"$"[a-zA-Z_][a-zA-Z0-9_#@]* return( PARM ); 

X 

X[a-zA-Z_][a-zA-Z0-9_#@]* { 

X yylval.nsbuf = strcpy (scratch, yytext);   /* KMW */ 

X return IDENTIFIER ; 

X} 

X 

X\"[^\"]*        | 

X\'[^\']* 

X{ 

X        if(yytext[yyleng-1] ==  '\\') 

X                yymore(); 

X        else 

X        { 

X                yytext[yyleng++] = input(); 

X                yytext[yyleng] = '\0'; 

X                return( STRING ); 

X        } 

X} 

X 

X{D}+    return ( INTEGER ); 

X 

X{D}+"."{D}*({E})?       | 

X{D}+"."{D}+({E})?       | 

X{D}+{E} return ( REAL ); 

X 

X":"     return ':' ; 

X";"     return ';' ; 

X".*"    return ALLFIELDS ; 

X"."     return '.' ; 

X","     return ',' ; 

X"!"     return NOT ; 

X"!="    return NE ; 

X"<="    return LE ; 

X">="    return GE ; 

X"<"     return LT ; 

X"!<"    return NLT ; 

X">"     return GT ; 

X"!>"    return NGT ; 

X"("     return '(' ; 

X")"     return ')' ; 

X">>"    return RIGHTSHIFT ; 

X"<<"    return LEFTSHIFT ; 

X"|"     return '|' ; /* Bit or */ 

X"||"    return E_OR ; /* or */ 

X"^"     return '^' ; /* Bit ex-or */ 

X"&"     return '&' ; /* Bit and */ 

X"&&"    return E_AND ; /* and */ 

X"~"     return '~' ; /* Ones compliment */ 

X"`"     return '`' ; /* Sematic control */ 

X"]"     return ']' ; 

X"["     return '[' ; 

X"="     return EQ ; 

X"+"     return '+' ; 

X"-"     return '-' ; 

X"*"     return '*' ; 

X"**"    return PWR ; 

X"/"     return '/' ; 

X"%"     return '%' ; /* Modulus */ 

X"?"     return '?' ; 

X[/] return( ILLEGAL ); 

X[ \n\t\r] ; 

X%% 

END_OF_dsl.l 

if test 1806 -ne `wc -c <dsl.l`; then 

    echo shar: \"dsl.l\" unpacked with wrong size! 

fi 

# end of overwriting check 

fi 

if test -f dsl.y -a "${1}" != "-c" ; then 

  echo shar: Will not over-write existing file \"dsl.y\" 

else 

echo shar: Extracting \"dsl.y\" \(17429 characters\) 

sed "s/^X//" >dsl.y <<'END_OF_dsl.y' 

X/* 

XDistributed Database Facilitator Parcer 

XVersion 1.0 

XBy Leroy G. Cain 

X1985 Columbia Union College 

X*/ 

X%union 

X{ 

X        int     stype; 

X        char    *nsbuf; 

X} 

X%token ADD 

X%token ALL 

X%token ALLOWED 

X%token AFTER 

X%token ALTER 

X%token AND 

X%token ANY 

X%token AS 

X%token ASC 

X%token AT 

X%token AUDIT 

X%token BEFORE 

X%token BBEGIN 

X%token BETWEEN 

X%token BY 

X%token CHECK 

X%token CLOSE 

X%token COMMENT 

X%token COMMIT 

X%token COMPOSITE 

X%token CONSTRAINT 

X%token CREATE 

X%token DATABASE 

X%token DEFAULT 

X%token DELETE 

X%token DESC 

X%token DISTINCT 

X%token DIVIDEBY 

X%token DOMAIN 

X%token DROP 

X%token DUMP 

X%token END 

X%token ELSE 

X%token EXISTS 

X%token FOR 

X%token FOREIGN 

X%token FRAGMENT 

X%token FROM 

X%token GRANT 

X%token GROUP 

X%token HAVING 

X%token IDENTIFIES 

X%token IF 

X%token IN 

X%token INDEX 

X%token INFO 

X%token INSERT 

X%token INTO 

X%token INTERSECT 

X%token IS 

X%token LIKE 

X%token LOCK 

X%token MINUS 

X%token MODE 

X%token MODIFY 

X%token NOT 

X%token NULLN 

X%token NULLS 

X%token OF 

X%token ON 

X%token OPEN 

X%token OPTION 

X%token OR 

X%token ORDER 

X%token OUTER 

X%token PRIMARY 

X%token PROGRAM 

X%token RANGE 

X%token REPAIR 

X%token RESTORE 

X%token REVOKE 

X%token ROLLBACK 

X%token ROLLFORWARD 

X%token SELECT 

X%token SET 

X%token SHOW 

X%token SNAPSHOT 

X%token START 

X%token STORE 

X%token SYNC 

X%token SYNONYM 

X%token TABLE 

X%token THEN 

X%token TO 

X%token TYPE 

X%token VALUES 

X%token VIEW 

X%token UNION 

X%token UNIQUE 

X%token UPDATE 

X%token WHERE 

X%token WORK 

X%token WITH 

X/* 

X*/ 

X%token ALLFIELDS 

X%token <nsbuf> IDENTIFIER 

X%token INTEGER 

X%token ILLEGAL 

X%token REAL 

X%token STRING 

X%token PARM 

X%left ';' 

X%left WHERE 

X%left OR 

X%left AND 

X%left ',' 

X%right ASSIGN 

X%right TCOL 

X%left '?' 

X%left E_OR 

X%left E_AND 

X%left '|' 

X%left '^' 

X%left '&' 

X%left NLT NGT LT GT EQ GE LE NE 

X%left RIGHTSHIFT LEFTSHIFT 

X%left '+' '-' 

X%left '*' '/' '%' PWR 

X%right UMINUS  '~' PNOT 

X%left PORDER 

X%left '`' 

X%left '.' 

X 

X 

X%{ 

Xstatic long     flag; 

Xstatic short    sqy_flag; 

X 

Xstatic char     path_name[1024]; 

Xstatic char     scratch[1024]; 

X 

X#include "gtok.h" 

X#define BEXPR { sqy_flag = 0; } 

X%} 

X%% 

Xdsl: 

X          statement ';' 

X          {puttok(T_ROOT);puttok(0);puttok(0);puttok(T_ENDCOMMAND);} 

X        | STORE PROGRAM prog_name '(' parm_list ')'stats ';' END STORE ';' 

X        ; 

X 

Xstats: 

X        statement 

X        | stats ';' statement 

X        ; 

X 

X        /* 

Xtrigger_list: 

X        trigger 

X        | trigger_list ',' trigger 

X        |error 

X        | trigger_list error trigger 

X        | trigger_list ',' error 

X        ; 

X        */ 

Xstatement: 

X          { puttok(0300);} alter 

X        | { puttok(0301);} audit 

X        | { puttok(0302);} begin 

X        | { puttok(0303);} check 

X        | { puttok(0304);} close 

X        | { puttok(0305);} comment 

X        | { puttok(0306);} commit 

X        | { puttok(0307);} create 

X        | { puttok(0310);} delete 

X        | { puttok(0311);} drop 

X        | { puttok(0312);} dump 

X        | { puttok(0313);} grant 

X        | { puttok(0314);} info 

X        | { puttok(0315);} insert 

X        | { puttok(0316);} lock 

X        | { puttok(0317);} open 

X        | { puttok(0320);} rollback 

X        | { puttok(0321);} rollforward 

X        | { puttok(0322);} repair 

X        | { puttok(0323);} restore 

X        | { puttok(0324);} revoke 

X        | { puttok(0325);} select 

X        | { puttok(0326);} set 

X        | { puttok(0327);} start 

X        | { puttok(0330);} sync 

X        | { puttok(0331);} update 

X        ; 

X 

Xstart: 

X          prog_name '(' expr_list ')' 

X          /* 

X        | START INTEGER '(' parm_list ')' 

X          */ 

X        ; 

X 

Xparm_list: 

X          parm 

X        | parm ',' parm_list 

X        ; 

X 

Xparm: 

X          parm_name 

X        | parm_name EQ expr %prec ASSIGN 

X        ; 

X 

X/* 

XData Manipulation 

X*/ 

X 

Xdelete: 

X          DELETE FROM rec_alias where_clause /* Set where flag */ 

X        ; 

X 

Xinsert: 

X            INSERT INTO rec_alias '(' field_list ')' icond 

X          | INSERT INTO rec_alias icond 

X          ; 

X 

Xupdate: 

X          UPDATE rec_alias set_show where_clause /* Set where flag */ 

X        ; 

X 

Xrec_alias: 

X          path 

X        | path alias 

X        ; 

X 

Xicond: 

X          FROM filename 

X        | select_statement 

X        | VALUES '(' const_list ')' 

X        ; 

X 

Xset_show: 

X          SHOW setelements 

X        | SET setelements 

X        ; 

X 

Xsetelements: 

X          setelement 

X        | setelements ',' setelement 

X        ; 

X 

Xsetelement: 

X          field EQ expr %prec ASSIGN 

X        | field EQ select_statement %prec ASSIGN 

X        | '[' field_list ']' EQ '[' expr_list ']' %prec ASSIGN 

X        | '[' field_list ']' EQ select_statement %prec ASSIGN 

⌨️ 快捷键说明

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