/[vdw]/trunk/obj_srvr.l
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/obj_srvr.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations)
Tue Feb 8 21:59:58 2005 UTC (19 years, 1 month ago) by dpavlin
File size: 6678 byte(s)
re-added ANY keyword (renamed to sqlANY to avoid conflict with allready defined ANY)

1 %{
2 /*
3 * This SQL Lexer is copied from the O'Reilly Lex & Yacc book, 2nd Edition,
4 * 1995, by John R. Levine, Tony Mason, and Doug Brown. It probably contains
5 * words that we don't need for the Object Server, and will probably need
6 * enhancements. I removed the DDL and non-query words, but I'm going to
7 * leave in all other O'Reilly stuff unless it becomes real obvious that we
8 * don't need it.
9 *
10 * Jeremy Hickerson, 5/8/2002
11 */
12 #define LEX_SOURCE_FILE
13
14 #include <string.h>
15 #include "obj_srvr.h"
16 #include "flexdef.h"
17
18 #ifdef VMS
19 #include <unixio.h>
20 #endif
21
22 #include <string.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #ifdef VMS
26 #include <types.h>
27 #include <socket.h>
28 #include <in.h>
29 #include <inet.h>
30 #include <timeb.h>
31 #else
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
36 #include <sys/timeb.h>
37 #endif
38 #include <netdb.h>
39 #include <stdio.h>
40 #include <errno.h>
41 #include <time.h>
42
43 #define bcopy(s,d,l) memcpy(d,s,l)
44 #define bzero(d,l) memset(d,0,l)
45 #define BUF_SIZE 2048
46
47 char buf[BUF_SIZE];
48 int sock;
49
50 #ifdef VMS
51 #include "obj_srvr_tab.h"
52 #else
53 #include "obj_srvr.tab.h"
54 #endif
55
56 int lineno = 1;
57 char mode;
58
59 void yyerror(char *s);
60 void connect_to_oracle_obj_srvr(char *host, int port);
61
62 /* macro to save the text of a SQL token */
63 #define SV save_str(yytext)
64
65 /* macro to save the text and return a token */
66 #define TOK(name) { SV; token = name; return name; }
67
68 /* read input through perl, since perl has access to oracle_obj_srvr socket */
69 /* (we connected to it in perl, because if we connect in C (here) then haven't
70 figured out how to make perl see socket for output) */
71 #define YY_INPUT(buf,result,max_size) { \
72 strcpy(buf, call_perl_get_yyin(max_size) ); \
73 result = strlen(buf); \
74 }
75
76 %}
77
78 %s SQL
79 %%
80
81 /* EXEC[ \t]+SQL { BEGIN SQL; printf("SQL> "); start_save(); } */
82 SQL {
83
84 BEGIN SQL;
85
86 call_perl_send_yyout("SQL> ");
87
88 if (mode == 'S')
89 call_perl_send_yyout("\n");
90
91 start_save();
92 }
93
94 QUIT { close(sock); exit(0); }
95
96 /* literal keyword tokens */
97 <SQL>ALL TOK(ALL)
98 <SQL>AND TOK(AND)
99 <SQL>AVG TOK(AMMSC)
100 <SQL>MIN TOK(AMMSC)
101 <SQL>MAX TOK(AMMSC)
102 <SQL>SUM TOK(AMMSC)
103 <SQL>COUNT TOK(AMMSC)
104 <SQL>ANY TOK(sqlANY)
105 <SQL>AS TOK(AS)
106 <SQL>ASC TOK(ASC)
107 <SQL>AUTHORIZATION TOK(AUTHORIZATION)
108 <SQL>BETWEEN TOK(BETWEEN)
109 <SQL>BY TOK(BY)
110 <SQL>CHAR(ACTER)? TOK(CHARACTER)
111 <SQL>CHECK TOK(CHECK)
112 <SQL>CLOSE TOK(CLOSE)
113 <SQL>CONTINUE TOK(CONTINUE)
114 <SQL>CURRENT TOK(CURRENT)
115 <SQL>CURSOR TOK(CURSOR)
116 <SQL>DECIMAL TOK(DECIMAL)
117 <SQL>DECLARE TOK(DECLARE)
118 <SQL>DEFAULT TOK(DEFAULT)
119 <SQL>DESC TOK(DESC)
120 <SQL>DISTINCT TOK(DISTINCT)
121 <SQL>DOUBLE TOK(DOUBLE)
122 <SQL>ESCAPE TOK(ESCAPE)
123 <SQL>EXISTS TOK(EXISTS)
124 <SQL>FETCH TOK(FETCH)
125 <SQL>FLOAT TOK(FLOAT)
126 <SQL>FOR TOK(FOR)
127 <SQL>FOREIGN TOK(FOREIGN)
128 <SQL>FOUND TOK(FOUND)
129 <SQL>FROM TOK(FROM)
130 <SQL>GO[ \t]*TO TOK(GOTO)
131 <SQL>GROUP TOK(GROUP)
132 <SQL>HAVING TOK(HAVING)
133 <SQL>IN TOK(IN)
134 <SQL>INDICATOR TOK(INDICATOR)
135 <SQL>INT(EGER)? TOK(INTEGER)
136 <SQL>INTO TOK(INTO)
137 <SQL>IS TOK(IS)
138 <SQL>KEY TOK(KEY)
139 <SQL>LANGUAGE TOK(LANGUAGE)
140 <SQL>LIKE TOK(LIKE)
141 <SQL>NOT TOK(NOT)
142 <SQL>NULL TOK(NULLX)
143 <SQL>NUMERIC TOK(NUMERIC)
144 <SQL>OF TOK(OF)
145 <SQL>ON TOK(ON)
146 <SQL>OPEN TOK(OPEN)
147 <SQL>OPTION TOK(OPTION)
148 <SQL>OR TOK(OR)
149 <SQL>ORDER TOK(ORDER)
150 <SQL>PRECISION TOK(PRECISION)
151 <SQL>PRIMARY TOK(PRIMARY)
152 <SQL>PRIVILEGES TOK(PRIVILEGES)
153 <SQL>PROCEDURE TOK(PROCEDURE)
154 <SQL>REAL TOK(REAL)
155 <SQL>REFERENCES TOK(REFERENCES)
156 <SQL>SCHEMA TOK(SCHEMA)
157 <SQL>SELECT TOK(SELECT)
158 <SQL>SMALLINT TOK(SMALLINT)
159 <SQL>SOME TOK(SOME)
160 <SQL>SQLCODE TOK(SQLCODE)
161 <SQL>TO TOK(TO)
162 <SQL>UNION TOK(UNION)
163 <SQL>UNIQUE TOK(UNIQUE)
164 <SQL>USER TOK(USER)
165 <SQL>VALUES TOK(VALUES)
166 <SQL>WHENEVER TOK(WHENEVER)
167 <SQL>WHERE TOK(WHERE)
168 <SQL>WITH TOK(WITH)
169 <SQL>WORK TOK(WORK)
170
171
172
173 /* punctuation */
174 <SQL>"=" TOK(COMP_EQ)
175 <SQL>"<>" TOK(COMP_NE1)
176 <SQL>"!=" TOK(COMP_NE2)
177 <SQL>"<" TOK(COMP_LT)
178 <SQL>">" TOK(COMP_GT)
179 <SQL>"<=" TOK(COMP_LE)
180 <SQL>">=" TOK(COMP_GE)
181
182 <SQL>[-+*/:(),.;] TOK(yytext[0])
183
184
185 /* names */
186 <SQL>[A-Za-z][A-Za-z0-9_]* TOK(NAME)
187
188 /* strings */
189 <SQL>'[^'\n]*' TOK(STRING)
190
191 <SQL>'[^'\n]*$ { yyerror("Unterminated string"); }
192
193
194 /* numbers */
195 <SQL>[0-9]+ |
196 <SQL>[0-9]+"."[0-9]* |
197 <SQL>"."[0-9]* TOK(INTNUM)
198
199 <SQL>[0-9]+[eE][+-]?[0-9]+ |
200 <SQL>[0-9]+"."[0-9]*[eE][+-]?[0-9]+ |
201 <SQL>"."[0-9]*[eE][+-]?[0-9]+ TOK(APPROXNUM)
202
203
204 /* whitespace */
205 <SQL>\n { save_str(" "); lineno++; }
206 \n { save_str(" "); lineno++; } /* jh: non-SQL */
207
208 <SQL>[ \t\r]+ save_str(" "); /* whitespace */
209
210 <SQL>"--".* ; /* comment */
211
212
213 /* anything else */
214 . ; /* ignore */
215
216 %%
217
218
219 void yyerror(char *s) {
220 printf("%d: %s at %s\n", lineno, s, yytext);
221 }
222
223
224 /* leave SQL lexing mode */
225 un_sql() {
226 BEGIN INITIAL;
227 }
228
229
230 main(int argc, char *argv[]) {
231
232
233 if (argc < 4) {
234 fprintf(stderr, "Usage: obj_srvr <db_uid> db_passwd> <mode: (I)nteractive/(S)erver> [host] [port]\n");
235 return;
236 }
237
238 char perlscript_to_embed[] = "obj_srvr.pl";
239 static char *perl_argv[5];
240 int i;
241
242 perl_argv[0] = argv[0];
243 perl_argv[1] = perlscript_to_embed;
244 perl_argv[2] = argv[1];
245 perl_argv[3] = argv[2];
246
247 /* start the perl interpreter and compile obj_srvr.pl */
248 if ( !strcmp(argv[3], "S") || !strcmp(argv[3], "s") ) {
249 strcpy(perl_argv[2], "");
250 strcpy(perl_argv[3], "");
251 }
252 embed_perl_obj_srvr(4, perl_argv, NULL);
253
254 /* connect to "wrapper" server running on foreign tnslsnr */
255 if ( !strcmp(argv[3], "S") || !strcmp(argv[3], "s") ) {
256 mode = 'S';
257 call_perl_connect2client(argv[4], argv[5]);
258 }
259
260 do {
261 if (yyparse() ) {
262 call_perl_send_yyout("\nQUIT\n");
263 break;
264 }
265 } while (!feof(yyin) ) ;
266
267 end_perl();
268 }
269

  ViewVC Help
Powered by ViewVC 1.1.26