001// lexical analyzer for GSQLParser component java version 002 003/**************************************************** 004 Lexical analizer for GSQLParser Java component 005 Copyright (c) 2004-2023 by Gudu software 006****************************************************/ 007 008package gudusoft.gsqlparser; 009 010import java.util.ArrayList; 011import java.util.HashMap; 012import java.io.InputStreamReader; 013 014import java.util.Locale; 015import java.io.BufferedReader; 016import java.io.IOException; 017 018 019public class TLexerGaussDB extends TCustomLexer{ 020 static int yynmarks = 0 ; 021 static int yynmatches ; 022 static int yyntrans ; 023 static int yynstates ; 024 static int[] yyk,yym ; // 1 based 025 static int[] yytint; // 1 based 026 static TYytRec[] yyt ; // 1 based 027 static int[] yykl,yykh,yyml,yymh,yytl,yyth ; // 0 based 028 private static String[] keywordlist; 029 static String table_file; 030 static HashMap<String, Integer> keywordValueList; 031 static HashMap<Integer, Integer> keywordTypeList; 032 static int[][] yystateTable; 033 static HashMap<String, Integer> operatorList; 034 035 boolean isEQuote = false; 036 boolean isReadyForFunctionBody = false, isInFunctionBody = false; 037 int functionBodyDelimiterIndex = -1; 038 ArrayList<String> functionBodyDelimiter = new ArrayList<>(); 039 040 static { 041 keywordValueList = new HashMap<String, Integer>(); 042 keywordTypeList = new HashMap<Integer, Integer>(); 043 044 operatorList = new HashMap<String, Integer>(); 045 operatorList.put("+", Integer.valueOf('+')); 046 operatorList.put("-", Integer.valueOf('-')); 047 operatorList.put("*", Integer.valueOf('*')); 048 operatorList.put("/", Integer.valueOf('/')); 049 operatorList.put("%", Integer.valueOf('%')); 050 operatorList.put("^", Integer.valueOf('^')); 051 operatorList.put("@", Integer.valueOf('@')); 052 operatorList.put("&", Integer.valueOf('&')); 053 operatorList.put("|", Integer.valueOf('|')); 054 operatorList.put("~", Integer.valueOf('~')); 055 operatorList.put("!", Integer.valueOf('!')); 056 operatorList.put(">", Integer.valueOf('>')); 057 operatorList.put("<", Integer.valueOf('<')); 058 operatorList.put("#", Integer.valueOf('#')); 059 operatorList.put("?", Integer.valueOf('?')); 060 operatorList.put("<=", TBaseType.less_equal); 061 operatorList.put("<<", TBaseType.OP_LESS_LESS); 062 operatorList.put("<<<", TBaseType.OP_LESS_LESS_LESS); 063 operatorList.put("<<|", TBaseType.OP_LESS_LESS_BAR); 064 operatorList.put("<<=", TBaseType.OP_LESS_LESS_EQUAL); 065 operatorList.put("<>", TBaseType.not_equal); 066 operatorList.put("<->", TBaseType.OP_LESS_MINUS_GREAT); 067 operatorList.put("<@", TBaseType.OP_LESS_AT); 068 operatorList.put("<^", TBaseType.OP_LESS_CARET); 069 operatorList.put("<%", TBaseType.OP_LESS_PERCENT); 070 operatorList.put(">=", TBaseType.great_equal); 071 operatorList.put(">%", TBaseType.OP_GREAT_PERCENT); 072 operatorList.put(">>", TBaseType.OP_GREAT_GREAT); 073 operatorList.put(">>>", TBaseType.OP_GREAT_GREAT_GREAT); 074 operatorList.put(">>=", TBaseType.OP_GREAT_GREAT_EQUAL); 075 operatorList.put(">^", TBaseType.OP_GREAT_CARET); 076 operatorList.put("!=", TBaseType.not_equal); 077 operatorList.put("<=>", TBaseType.OP_SAFE_EQUAL); 078 operatorList.put("!!", TBaseType.OP_EXCLAMATION_EXCLAMATION); 079 operatorList.put("!~", TBaseType.OP_EXCLAMATION_TILDE); 080 operatorList.put("!~~", TBaseType.OP_EXCLAMATION_TIDLE_TIDLE); 081 operatorList.put("!~*", TBaseType.OP_EXCLAMATION_TIDLE_STAR); 082 operatorList.put("!~~*", TBaseType.OP_EXCLAMATION_TIDLE_TIDLE_STAR); 083 operatorList.put("^=", TBaseType.not_equal); 084 operatorList.put("*=", TBaseType.OP_STAR_EQUAL); 085 operatorList.put("*<", TBaseType.OP_STAR_LESS); 086 operatorList.put("*>", TBaseType.OP_STAR_GREAT); 087 operatorList.put("*<>", TBaseType.OP_STAR_LESS_GREAT); 088 operatorList.put("*<=", TBaseType.OP_STAR_LESS_EQUAL); 089 operatorList.put("*>=", TBaseType.OP_STAR_GREAT_EQUAL); 090 operatorList.put("|/", TBaseType.OP_SQUARE_ROOT); 091 operatorList.put("||", TBaseType.concatenationop); 092 operatorList.put("||/", TBaseType.OP_CUBE_ROOT); 093 operatorList.put("|>>", TBaseType.OP_BAR_GREAT_GREAT); 094 operatorList.put("|&>", TBaseType.OP_BAR_PUNCTUATION_GREAT); 095 operatorList.put("~~", TBaseType.OP_TILDE_TILDE); 096 operatorList.put("~~*", TBaseType.OP_TILDE_TILDE_STAR); 097 operatorList.put("~*", TBaseType.OP_TILDE_STAR); 098 operatorList.put("~=", TBaseType.OP_TILDE_EQUAL); 099 operatorList.put("~>~", TBaseType.OP_TILDE_GREAT_TILDE); 100 operatorList.put("~<~", TBaseType.OP_TILDE_LESS_TILDE); 101 operatorList.put("~>=~", TBaseType.OP_TILDE_GREAT_EQUAL_TILDE); 102 operatorList.put("~<=~", TBaseType.OP_TILDE_LESS_EQUAL_TILDE); 103 operatorList.put("@@", TBaseType.OP_AT_AT); 104 operatorList.put("@@@", TBaseType.OP_AT_AT_AT); 105 operatorList.put("@>", TBaseType.OP_AT_GREAT); 106 operatorList.put("@?", TBaseType.OP_AT_QUESTION); 107 operatorList.put("@-@", TBaseType.OP_AT_MINUS_AT); 108 operatorList.put("##", TBaseType.OP_POUND_POUND); 109 operatorList.put("#>", TBaseType.OP_POUND_GREAT); 110 operatorList.put("#>>", TBaseType.OP_POUND_GREAT_GREAT); 111 operatorList.put("#-", TBaseType.OP_POUND_MINUS); 112 operatorList.put("&&", TBaseType.OP_PUNCTUATION_PUNCTUATION); 113 operatorList.put("&<", TBaseType.OP_PUNCTUATION_LESS); 114 operatorList.put("&<|", TBaseType.OP_PUNCTUATION_LESS_BAR); 115 operatorList.put("&>", TBaseType.OP_PUNCTUATION_GREAT); 116 operatorList.put("?#", TBaseType.OP_QUESTION_POUND); 117 operatorList.put("?-", TBaseType.OP_QUESTION_MINUS); 118 operatorList.put("?-|", TBaseType.OP_QUESTION_MINUS_BAR); 119 operatorList.put("?||", TBaseType.OP_QUESTION_BAR_BAR); 120 operatorList.put("?|", TBaseType.OP_QUESTION_BAR); 121 operatorList.put("?&", TBaseType.OP_QUESTION_PUNCTUATION); 122 operatorList.put("->", TBaseType.OP_MINUS_GREAT); 123 operatorList.put("->>", TBaseType.OP_MINUS_GREAT_GREAT); 124 operatorList.put("-|-", TBaseType.OP_MINUS_BAR_MINUS); 125 126 table_file = "/gudusoft/gsqlparser/parser/gaussdb/gaussdb_lex_table.txt"; 127 if (TBaseType.enterprise_edition||TBaseType.gaussdb_edition){ 128 inittable(); 129 } 130 } 131 132 public TLexerGaussDB(){ 133 super(); 134 dbvendor = EDbVendor.dbvgaussdb; 135 } 136 137public boolean canBeColumnName(int tokencode){ 138 //http://blog.csdn.net/superbeck/article/details/5387476 139 boolean ret = false; 140 int modifiers = keyword_type_identifier | keyword_type_column ; 141 Integer s = keywordTypeList.get(tokencode); 142 if (s != null){ 143 int modifier = s; 144 ret = (modifiers & modifier) == modifier; 145 } 146 147 return ret; 148} 149 150 public int iskeyword(String str){ 151 int ret = -1; 152 Integer s = keywordValueList.get(str.toUpperCase(Locale.ENGLISH)); 153 if( s != null){ 154 ret = s; 155 } 156 return ret;// -1 means not a keyword 157 } 158 159 public int getkeywordvalue(String keyword){ 160 int ret = 0; 161 Integer s = keywordValueList.get(keyword.toUpperCase(Locale.ENGLISH)); 162 if( s != null){ 163 ret = s; 164 } 165 return ret;// 0 means not a keyword 166 } 167 168 static void yystateLookupConfigure() { 169 int yystates = yytl.length; 170 yystateTable = new int[257][yystates]; 171 172 // initialize to empty 173 for(int i = 0; i < yystates; i++) { 174 for (int j = 0; j < 257; j++) 175 yystateTable[j][i] = -1; 176 } 177 178 for(int i = 0; i < yystates; i++) { 179 int low = yytl[i]; 180 int high = yyth[i]; 181 for (int j = low; j <= high; j++) { 182 for (char c: yyt[j].cc) { 183 yystateTable[c][i] = j; 184 } 185 } 186 } 187 } 188 189 int yylex(){ 190 int yyn; 191 while (true) { // top level while 192 yynew(); 193 while (true){ //scan 194 for(yyn = yykl[yystate]; yyn <= yykh[yystate]; yyn++){ 195 yymark(yyk[yyn]); 196 } 197 198 for(yyn=yymh[yystate]; yyn>= yyml[yystate]; yyn--){ 199 yymatch(yym[yyn]); 200 } 201 202 if(yytl[yystate] > yyth[yystate]){ 203 break; 204 } 205 206 yyscan(); 207// yyn = yytl[yystate]; 208 totablechar(); 209// while( (yyn <= yyth[yystate]) && (!(charinarray(yytablechar,yyt[yyn].cc))) ){ 210// yyn++; 211// } 212// if (yyn > yyth[yystate]){ 213// break; 214// } 215 216 yyn = yystateTable[yytablechar][yystate]; 217 if (yyn == -1) 218 break; 219 220 yystate = yyt[yyn].s; 221 } //scan 222 223 while (true){ //action 224 int yyrule; 225 if ( (yyrule = yyfind()) != -1 ){ 226 yyaction(yyrule); 227 if (yyreject){ 228 continue; 229 } 230 }else if( (!yydefault() ) && (yywrap()) ){ 231 yyclear(); 232 returni(0); 233 } 234 break; 235 } 236 237 if (!yydone) { 238 continue; 239 } 240 break; 241 } // top level while 242 243 return yyretval; 244 } 245 246 static void inittable(){ 247 248 //if (yynmarks > 0) return; //init table already 249 250 String line; 251 boolean inyyk=false,inyym=false,inyykl=false,inyykh=false,inyyml=false,inyymh=false,inyytl=false,inyyth=false,inyytint=false,inyyt=false,inkeyword=false; 252 int yyk_count=0,yym_count=0,yykl_count=0,yykh_count=0,yyml_count=0,yymh_count=0,yytl_count=0,yyth_count=0,yytint_count=0,yyt_count=0; 253 int c=0; 254 keywordValueList.clear(); 255 keywordTypeList.clear(); 256 257 BufferedReader br = new BufferedReader(new InputStreamReader(TLexerGaussDB.class.getResourceAsStream(table_file))); 258 259 try{ 260 while( (line = br.readLine()) != null){ 261 if (line.trim().startsWith("yynmarks=")){ 262 String[] ss = line.split("[=;]"); 263 yynmarks=Integer.parseInt(ss[1].trim()); 264 yyk = new int[yynmarks+1]; 265 }else if (line.trim().startsWith("yynmatches=")){ 266 String[] ss = line.split("[=;]"); 267 yynmatches=Integer.parseInt(ss[1].trim()); 268 yym = new int[yynmatches+1]; 269 }else if (line.trim().startsWith("yyntrans=")){ 270 String[] ss = line.split("[=;]"); 271 yyntrans=Integer.parseInt(ss[1].trim()); 272 yytint = new int[yyntrans+1]; 273 yyt = new TYytRec[yyntrans+1]; 274 }else if (line.trim().startsWith("yynstates=")){ 275 String[] ss = line.split("[=;]"); 276 yynstates=Integer.parseInt(ss[1].trim()); 277 yykl = new int[yynstates]; 278 yykh = new int[yynstates]; 279 yyml = new int[yynstates]; 280 yymh = new int[yynstates]; 281 yytl = new int[yynstates]; 282 yyth = new int[yynstates]; 283 }else if (line.trim().startsWith("<end>")){ 284 if (inyyk){ 285 inyyk = false; 286 if (yynmarks+1 != yyk_count ){ 287 System.out.println("required1:"+(yynmarks)+" actually:"+(yyk_count-1)); 288 } 289 } 290 else if(inyym){ 291 inyym = false; 292 if (yynmatches+1 != yym_count ){ 293 System.out.println("required2:"+(yynmatches)+" actually:"+(yym_count-1)); 294 } 295 } 296 else if(inyykl){ 297 inyykl = false; 298 if (yynstates != yykl_count ){ 299 System.out.println("required3:"+(yynstates)+" actually:"+(yykl_count)); 300 } 301 } 302 else if(inyykh){ 303 inyykh = false; 304 if (yynstates != yykh_count ){ 305 System.out.println("required4:"+(yynstates)+" actually:"+(yykh_count)); 306 } 307 } 308 else if(inyyml){ 309 inyyml = false; 310 if (yynstates != yyml_count ){ 311 System.out.println("required5:"+(yynstates)+" actually:"+(yyml_count)); 312 } 313 } 314 else if(inyymh){ 315 inyymh = false; 316 if (yynstates != yymh_count ){ 317 System.out.println("required:"+(yynstates)+" actually:"+(yymh_count)); 318 } 319 } 320 else if(inyytl){ 321 inyytl = false; 322 if (yynstates != yytl_count ){ 323 System.out.println("required6:"+(yynstates)+" actually:"+(yytl_count)); 324 } 325 } 326 else if(inyyth){ 327 inyyth = false; 328 if (yynstates != yyth_count ){ 329 System.out.println("required7:"+(yynstates)+" actually:"+(yyth_count)); 330 } 331 } 332 else if(inyytint){ 333 inyytint = false; 334 if (yyntrans + 1 != yytint_count ){ 335 System.out.println("required8:"+(yyntrans)+" actually:"+(yytint_count-1)); 336 } 337 } 338 else if(inyyt){ 339 inyyt = false; 340 if (yyntrans+1 != yyt_count ){ 341 System.out.println("required9:"+(yyntrans)+" actually:"+(yyt_count-1)); 342 } 343 } 344 else if(inkeyword){ 345 inkeyword = false; 346 } 347 }else if(line.trim().startsWith("yyk =")){ 348 inyyk = true; 349 }else if(line.trim().startsWith("yym =")){ 350 inyym = true; 351 }else if(line.trim().startsWith("yykl =")){ 352 inyykl = true; 353 }else if(line.trim().startsWith("yykh =")){ 354 inyykh = true; 355 }else if(line.trim().startsWith("yyml =")){ 356 inyyml = true; 357 }else if(line.trim().startsWith("yymh =")){ 358 inyymh = true; 359 }else if(line.trim().startsWith("yytl =")){ 360 inyytl = true; 361 }else if(line.trim().startsWith("yyth =")){ 362 inyyth = true; 363 }else if(line.trim().startsWith("yytint =")){ 364 inyytint = true; 365 }else if(line.trim().startsWith("yyt =")){ 366 inyyt = true; 367 }else if(line.trim().startsWith("keywordsvalue =")){ 368 inkeyword = true; 369 }else if(inyyk){ 370 String[] ss = line.split("[,]"); 371 for(int j=0;j<ss.length;j++){ 372 // System.out.println(ss[j].trim()); 373 yyk[yyk_count++] = Integer.parseInt(ss[j].trim()); 374 } 375 }else if(inyym){ 376 String[] ss = line.split("[,]"); 377 for(int j=0;j<ss.length;j++){ 378 // System.out.println(ss[j].trim()); 379 yym[yym_count++] = Integer.parseInt(ss[j].trim()); 380 } 381 }else if(inyykl){ 382 String[] ss = line.split("[,]"); 383 for(int j=0;j<ss.length;j++){ 384 // System.out.println(ss[j].trim()); 385 yykl[yykl_count++] = Integer.parseInt(ss[j].trim()); 386 } 387 }else if(inyykh){ 388 String[] ss = line.split("[,]"); 389 for(int j=0;j<ss.length;j++){ 390 // System.out.println(ss[j].trim()); 391 yykh[yykh_count++] = Integer.parseInt(ss[j].trim()); 392 } 393 }else if(inyyml){ 394 String[] ss = line.split("[,]"); 395 for(int j=0;j<ss.length;j++){ 396 // System.out.println(ss[j].trim()); 397 yyml[yyml_count++] = Integer.parseInt(ss[j].trim()); 398 } 399 }else if(inyymh){ 400 String[] ss = line.split("[,]"); 401 for(int j=0;j<ss.length;j++){ 402 // System.out.println(ss[j].trim()); 403 yymh[yymh_count++] = Integer.parseInt(ss[j].trim()); 404 } 405 }else if(inyytl){ 406 String[] ss = line.split("[,]"); 407 for(int j=0;j<ss.length;j++){ 408 // System.out.println(ss[j].trim()); 409 yytl[yytl_count++] = Integer.parseInt(ss[j].trim()); 410 } 411 }else if(inyyth){ 412 String[] ss = line.split("[,]"); 413 for(int j=0;j<ss.length;j++){ 414 // System.out.println(ss[j].trim()); 415 yyth[yyth_count++] = Integer.parseInt(ss[j].trim()); 416 } 417 }else if(inyytint){ 418 String[] ss = line.split("[,]"); 419 for(int j=0;j<ss.length;j++){ 420 // System.out.println(ss[j].trim()); 421 yytint[yytint_count++] = Integer.parseInt(ss[j].trim()); 422 } 423 }else if(inyyt){ 424 //System.out.println(line.trim()); 425 426 c = 0; 427 String[] st = line.trim().split(",,"); 428 char[] tmp = new char[st.length]; 429 for(int i=0;i<st.length;i++){ 430 431 if(st[i].startsWith("\'")) { 432 if(st[i].length() == 3){ // 'a' 433 tmp[c++] = st[i].charAt(1); 434 }else if(st[i].length() == 4) { // '\\' 435 tmp[c++] = st[i].charAt(2); 436 }else{ 437 System.out.println(" read yytstr error, error string is "+st[i]+ "line: "+ yyt_count); 438 } 439 }else{ 440 try{ 441 tmp[c++] = (char)Integer.parseInt(st[i]); // char in number like 32 that represent space 442 } catch (NumberFormatException nfe) { 443 System.out.println("NumberFormatException: " + nfe.getMessage()); 444 } 445 } 446 } //while hasmoreTokens 447 448 //yyt[lineno] = new YYTrec(tmp,yytint[lineno]); 449 yyt[yyt_count] = new TYytRec(tmp,yytint[yyt_count]); 450 yyt_count++; 451 452 }else if(inkeyword){ 453 String[] ss =line.split("[=]"); 454 455 int val1 = -1; 456 int val2 = -1; 457 try { 458 val1 = Integer.parseInt(ss[1]); 459 val2 = Integer.parseInt(ss[2]); 460 } 461 catch (NumberFormatException nfe) { 462 System.out.println("NumberFormatException: " + nfe.getMessage()); 463 } 464 keywordValueList.put(ss[0].toUpperCase(),val1); 465 keywordTypeList.put(val1,val2); 466 } 467 } 468 }catch(IOException e){ 469 System.out.println(e.toString()); 470 } 471 472 yystateLookupConfigure(); 473 474 } 475 476 477 void yyaction(int yyruleno){ 478 479 480 int ic; 481 char[] tmparray = {'=','+','-','*','/','>','<'}; 482 483 yylvalstr = getyytext(); 484 /* actions: */ 485 switch(yyruleno){ 486 case 1: 487 488 { 489 if (yylvalstr.equalsIgnoreCase(dolqstart)) 490 { 491 //dolqstart = ""; 492 start(init); 493 addlit(yylvalstr,yytextlen); 494 yylvalstr = litbufdup(); 495 returni(sconst); 496 } 497 else 498 { 499 //nchars = yytextlen; 500 addlit(yylvalstr, yytextlen-1); 501 yyless(yytextlen-1); 502 return; 503 } 504 //System.out.println("<xdolq>{dolqdelim}: "+dolqstart); 505 break; 506 } 507 508 case 2: 509 510 { 511 512 if (isReadyForFunctionBody) { // meet the first $$ 513 //isInFunctionBody = true; 514 isReadyForFunctionBody = false; 515 functionBodyDelimiterIndex++; 516 functionBodyDelimiter.add(yylvalstr); 517 //System.out.println("start function body:"+functionBodyDelimiter.get(functionBodyDelimiterIndex)); 518 returni(postgresql_function_delimiter); 519 }else if ((functionBodyDelimiterIndex>=0)&&(functionBodyDelimiter.get(functionBodyDelimiterIndex).equalsIgnoreCase(yylvalstr))){ // meet the second $$ 520 //isInFunctionBody = false; 521 //System.out.println("end function body:"+functionBodyDelimiter.get(functionBodyDelimiterIndex)); 522 functionBodyDelimiter.remove(functionBodyDelimiterIndex); 523 functionBodyDelimiterIndex--; 524 525 returni(postgresql_function_delimiter); 526 }else { 527 if (getyysstate() == xq) { 528 addlit(yylvalstr, yytextlen); 529 } else { 530 start(xdolq); 531 startlit(); 532 dolqstart = yylvalstr; 533 addlit(yylvalstr,yytextlen); 534 //System.out.println("dolqdelim: "+dolqstart); 535 } 536 } 537 538 break; 539 } 540 541 case 3: 542 543 { 544 addlit(yylvalstr, yytextlen); 545 //System.out.println("<xdolq>{dolqinside}: "+yylvalstr); 546 break; 547 } 548 549 case 4: 550 551 { 552 addlit(yylvalstr, yytextlen); 553 break; 554 } 555 556 case 5: 557 558 { 559 addlitchar(yylvalstr.charAt(0)); 560 break; 561 } 562 563 564 case 6: 565 566 { 567 if (getyysstate() == xq) 568 { 569 nchars = yytextlen; 570 addlit(yylvalstr, yytextlen-1); 571 yyless(nchars-1); 572 return;//exit; 573 } 574 575 start(xq); 576 startlit(); 577 addlit(yylvalstr,yytextlen); 578 break; 579 } 580 581 case 7: 582 583 { 584 if (getyysstate() == xq) 585 { 586 nchars = yytextlen; 587 addlit(yylvalstr, yytextlen-1); 588 yyless(nchars-1); 589 return;//exit; 590 } 591 592 start(xq); 593 startlit(); 594 addlit(yylvalstr,yytextlen); 595 break; 596 } 597 598 case 8: 599 600 { 601 if (getyysstate() == xq) 602 { 603 nchars = yytextlen; 604 addlit(yylvalstr, yytextlen-1); 605 yyless(nchars-1); 606 return;//exit; 607 } 608 609 start(xq); 610 startlit(); 611 addlit(yylvalstr,yytextlen); 612 break; 613 } 614 615 case 9: 616 617 { 618 addlit(yylvalstr,yytextlen); 619 620 if (xcdepth <= 0) 621 { 622 start(init); 623 yylvalstr = litbufdup(); 624 returni(cmtslashstar); 625 } 626 else{ 627 xcdepth--; 628 629 } 630 631 break; 632 } 633 634 635 case 10: 636 637 { 638 if (yylvalstr.startsWith("/*")){ 639 xcdepth++; 640 yyless(2); 641 addlit(yylvalstr,yytextlen); 642 643 }else{ 644 yyless(1); 645 addlit(yylvalstr,1); 646 } 647 648 break; 649 650 } 651 652 case 11: 653 654 { 655 656 if (getyysstate() == xq) 657 { 658 nchars = yytextlen; 659 addlit(yylvalstr, yytextlen-1); 660 yyless(nchars-1); 661 return;//exit; 662 } 663 664 xcdepth = 0; 665 start(xc); 666 startlit(); 667 yyless(2); 668 addlit(yylvalstr,yytextlen); 669 670 break; 671 } 672 673 case 12: 674 675 { 676 addlit(yylvalstr,yytextlen); 677 678 break; 679 } 680 681 case 13: 682 683 { 684 addlitchar(yylvalstr.charAt(0)); 685 686 break; 687 } 688 689 case 14: 690 691 { 692 start(init); 693 isEQuote = false; 694 addlit(yylvalstr, yytextlen); 695 yylvalstr = litbufdup(); 696 if( yylvalstr.startsWith("b")|| (yylvalstr.startsWith("B"))){ 697 returni(bconst); 698 }else if( yylvalstr.startsWith("x")|| (yylvalstr.startsWith("X"))){ 699 returni(xconst); 700 }else 701 { 702 returni(sconst); 703 } 704 break; 705 } 706 707 case 15: 708 709 { 710 if (insqlpluscmd){ 711 yyless(0); 712 yylvalstr = litbufdup(); 713 start(init); 714 returni(sconst); 715 }else{ 716 addlit(yylvalstr,yytextlen); 717 } 718 719 break; 720 } 721 case 16: 722 723 { 724 if (getyysstate() == xq) 725 { 726 nchars = yytextlen; 727 addlit(yylvalstr, yytextlen-1); 728 yyless(nchars-1); 729 return;//exit; 730 } 731 732 start(xq); 733 if (yylvalstr.startsWith("E")||yylvalstr.startsWith("e")) {isEQuote = true;} 734 startlit(); 735 addlit(yylvalstr,yytextlen); 736 737 dummych1 = get_char(); 738 if (dummych1 == '\\') // recognize string like '\' 739 { 740 dummych2 = get_char(); 741 if (dummych2 == '\'') 742 { 743 // start(init); 744 addlit("\\", 1); 745 addlit("\'", 1); 746 //yylvalstr = litbufdup(); 747 //returni(sconst); 748 } 749 else 750 { 751 unget_char(dummych2); 752 unget_char(dummych1); 753 } 754 } 755 else 756 { unget_char(dummych1);} 757 758 break; 759 } 760 761 case 17: 762 763 { 764 start(xq); 765 startlit(); 766 addlit(yylvalstr, yytextlen); 767 dummych1 = get_char(); 768 if (dummych1 == '\\') // recognize string like '\' 769 { 770 dummych2 = get_char(); 771 if (dummych2 == '\'') 772 { 773 start(init); 774 addlit("\\", 1); 775 addlit("\'", 1); 776 yylvalstr = litbufdup(); 777 returni(sconst); 778 } 779 else 780 { 781 unget_char(dummych2); 782 unget_char(dummych1); 783 } 784 } 785 else 786 { unget_char(dummych1);} 787 788 break; 789 } 790 791 case 18: 792 793 { 794 addlit(yylvalstr, yytextlen); 795 break; 796 } 797 798 case 19: 799 800 { 801 dummych1 = get_char(); 802 unget_char(dummych1); 803 if (dummych1 == (char)10) 804 { 805 if (insqlpluscmd){ 806 nchars = yytextlen; 807 if(yylvalstr.charAt(nchars-1) == (char)13){ 808 yyless(nchars - 1); 809 yylvalstr = yylvalstr.substring(0,nchars); 810 } 811 start(init); 812 addlit(yylvalstr, nchars-1); 813 yylvalstr = litbufdup(); 814 returni(sconst); //in sqlplus command, characters between ' and return is treated as a string 815 816 }else{ 817 dummych1 = get_char(); 818 addlit(yylvalstr+dummych1, yytextlen+1); 819 } 820 }else if ((dummych1 == '\\')&&(isEQuote)) 821 { 822 dummych1 = get_char(); 823 dummych2 = get_char(); 824 addlit(yylvalstr+dummych1+dummych2, yytextlen+2); 825 if (dummych2 == '\'') { 826 dummych3 = get_char(); 827 if (dummych3 != '\'') 828 unget_char(dummych3); 829 } 830 831 //addlit(yylvalstr, yytextlen); 832 } 833 else 834 { addlit(yylvalstr, yytextlen);} 835 836 break; 837 } 838 839 case 20: 840 841 { 842 addlit(yylvalstr, yytextlen); 843 //System.out.println("Found xqliteral"+yylvalstr); 844 break; 845 } 846 847 848 849 case 21: 850 851 { 852 dummych1 = get_char(); 853 unget_char(dummych1); 854 if (dummych1 == '\''){ 855 dummych1 = get_char(); 856 addlit(yylvalstr+dummych1, yytextlen+1); 857 }else{ 858 859 start(init); 860 addlit(yylvalstr, yytextlen); 861 if ((literallen == 0) && (!insqlpluscmd)) 862 {returni (error);} 863 if (literallen >= namedatalen) 864 { 865 setlengthofliteralbuf(namedatalen); 866 literallen = namedatalen; 867 } 868 yylvalstr = litbufdup(); 869 returni (ident); 870 871 } 872 873 874 break; 875 } 876 877 878 case 22: 879 880 { 881 if (insqlpluscmd){ 882 yyless(0); 883 yylvalstr = litbufdup(); 884 start(init); 885 returni(sconst); 886 }else{ 887 addlit(yylvalstr, yytextlen); 888 } 889 890 break; 891 } 892 893 case 23: 894 895 { 896 addlit(yylvalstr, yytextlen); 897 break; 898 } 899 900 case 24: 901 902 { 903 start(xd); 904 startlit(); 905 addlit(yylvalstr, yytextlen); 906 break; 907 } 908 909 case 25: 910 911 { 912 dummych1 = get_char(); 913 unget_char(dummych1); 914 if (dummych1 == (char)10) 915 { 916 if (insqlpluscmd){ 917 nchars = yytextlen; 918 if(yylvalstr.charAt(nchars-1) == (char)13){ 919 yyless(nchars - 1); 920 yylvalstr = yylvalstr.substring(0,nchars); 921 } 922 start(init); 923 addlit(yylvalstr, nchars-1); 924 yylvalstr = litbufdup(); 925 returni(sconst); //in sqlplus command, characters between ' and return is treated as a string 926 927 }else{ 928 dummych1 = get_char(); 929 addlit(yylvalstr+dummych1, yytextlen+1); 930 } 931 932 } else 933 addlit(yylvalstr, yytextlen); 934 935 break; 936 } 937 938 case 26: 939 940 { 941 returni(lexnewline); 942 break; 943 } 944 945 case 27: 946 947 { 948 returni(lexspace); 949 break; 950 } 951 952 case 28: 953 954 { 955 if ((getyysstate() == xq) 956 || (getyysstate() == xd) 957 || (getyysstate() == xc) 958 ) 959 { 960 addlit(yylvalstr, 1); 961 yyless(1); 962 return;//exit; 963 } 964 965 returni(cmtdoublehyphen); 966 break; 967 } 968 969 case 29: 970 971 { 972 returnc( lexer_charAt(yylvalstr,0)); 973 break; 974 } 975 976 case 30: 977 978 { 979 returni(cmpop); 980 break; 981 } 982 983 case 31: 984 985 { 986 987 if (getyysstate() == xc) 988 { 989 slashstar = yylvalstr.indexOf("*/"); 990 if (slashstar >= 0) 991 { 992 if (xcdepth > 0){ 993 addlit(yylvalstr,2); 994 yyless(2); 995 xcdepth--; 996 }else{ 997 start(init); 998 addlit(yylvalstr,slashstar+2); 999 yylvalstr = litbufdup(); 1000 yyless(slashstar+2); 1001 returni(cmtslashstar); 1002 } 1003 } 1004 else 1005 { 1006 addlit(yylvalstr,1); 1007 yyless(1); 1008 } 1009 } 1010 else if (getyysstate() == xq) 1011 { 1012 addlit(yylvalstr,1); 1013 yyless(1); 1014 } 1015 else 1016 { 1017 nchars = yytextlen; 1018 slashstar = yylvalstr.indexOf("/*"); 1019 dashdash = yylvalstr.indexOf("--"); 1020 if ((slashstar > 0) && (dashdash > 0)) 1021 { 1022 //if both appear, take the first one 1023 if (slashstar > dashdash) 1024 {slashstar = dashdash;} 1025 } 1026 else 1027 { 1028 // if slashstar=0 then slashstar := dashdash; 1029 // add (getyysstate <> xc) to avoid something like this */--,here */ should be handled instead of -- 1030 if ((slashstar > 0) && (getyysstate() != xc)) { 1031 nchars = slashstar; 1032 } 1033 } 1034 1035 boolean searchOp = false; 1036 while (nchars > 0){ 1037 String opStr = yylvalstr.substring(0,nchars); 1038 Integer opCode = operatorList.get(opStr); 1039 if (opCode != null){ 1040 // this is an operator 1041 if (nchars < yytextlen){ 1042 yyless(nchars); 1043 yylvalstr = yylvalstr.substring(0,nchars); 1044 } 1045 searchOp = true; 1046 returni(opCode); 1047 break; 1048 }else{ 1049 1050 } 1051 nchars--; 1052 } 1053 1054 if (searchOp) break; 1055 1056 nchars = yytextlen; // reset nchars 1057 1058 while ((nchars > 1) 1059 && ( (yylvalstr.charAt(nchars-1) == '+' ) 1060 || (yylvalstr.charAt(nchars-1) =='-')) 1061 && (getyysstate() != xc)) 1062 { 1063 for (ic = nchars - 1; ic>=1; ic--) 1064 { 1065 if (isopchar(yylvalstr.charAt(ic-1))) break; 1066 } 1067 if (ic >= 1) break; 1068 nchars--; 1069 } 1070 1071 if (nchars < yytextlen) 1072 { 1073 //Strip the unwanted chars from the token 1074 yyless(nchars); 1075 yylvalstr = yylvalstr.substring(0,nchars); 1076 } 1077 1078 ///* 1079 // * If what we have left is only one char, and it's 1080 // * one of the characters matching "self", then 1081 // * return it as a character token the same way 1082 // * that the "self" rule would have. 1083 // * make sure @ return as self char, by james wang 1084 // */ 1085 if ((nchars == 1) && (isselfchar(yylvalstr.charAt(0)) || (yylvalstr.charAt(0) == '@'))) 1086 { 1087 returnc(lexer_charAt(yylvalstr,0)); 1088 } 1089 else if ( 1090 (nchars >= 2) 1091 &&( 1092 charinarray(yylvalstr.charAt(nchars-1-1), tmparray) 1093 && ((yylvalstr.charAt(nchars-1) == ':') 1094 ||(yylvalstr.charAt(nchars-1) == '.') 1095 ) 1096 ) 1097 ) 1098 { 1099 yyless(nchars-1); 1100 yylvalstr = yylvalstr.substring(0,nchars-1); 1101 if (nchars == 2) 1102 returnc(lexer_charAt(yylvalstr,0)); 1103 else 1104 returni(op); 1105 } 1106 else if ( 1107 (nchars >= 2) 1108 && ( 1109 charinarray(yylvalstr.charAt(nchars-1-1),tmparray) 1110 && (yylvalstr.charAt(nchars-1) == '&') 1111 ) 1112 ) 1113 { 1114 yyless(nchars-1); 1115 yylvalstr = yylvalstr.substring(0,nchars-1); 1116 if (nchars == 2) 1117 returnc(lexer_charAt(yylvalstr,0)); 1118 else 1119 returni(op); 1120 } 1121 else if ( (nchars == 2) && (yylvalstr.charAt(0) == '.') && (yylvalstr.charAt(1) == '*')) 1122 { 1123 yyless(1); 1124 returnc(lexer_charAt(yylvalstr,0)); 1125 } 1126 else if ((nchars == 2) && ((yylvalstr.charAt(0) == '=') && ( (yylvalstr.charAt(1) == '?')) )) 1127 { 1128 yyless(1); 1129 returnc(lexer_charAt(yylvalstr,0)); 1130 } 1131 else if ( (nchars >= 2) && ((yylvalstr.charAt(0) == '@') && (yylvalstr.charAt(1) != '>') && (yylvalstr.charAt(1) != '@'))) 1132 { 1133 yyless(1); 1134 returnc(lexer_charAt(yylvalstr,0)); 1135 } 1136 else if ( (nchars >= 2) && (yylvalstr.charAt(0) == '?')&&(yylvalstr.charAt(1) != '&')&&(yylvalstr.charAt(1) != '|')) 1137 { 1138 yyless(1); 1139 returnc(lexer_charAt(yylvalstr,0)); 1140 } 1141 else if (((nchars > 2) && (yylvalstr.charAt(0) == '*')) 1142 && (yylvalstr.charAt(1) == '/') 1143 && (getyysstate() == xc) 1144 ) 1145 { //in comment, and find */ , then it must the end of comment 1146 yyless(2); 1147 addlit(yylvalstr,yytextlen); 1148 if (xcdepth <= 0) 1149 { 1150 start(init); 1151 yylvalstr = litbufdup(); 1152 returni(cmtslashstar); 1153 } 1154 else 1155 xcdepth--; 1156 } 1157 else 1158 returni(op); 1159 } 1160 1161 break; 1162 } 1163 1164 case 32: 1165 1166 { 1167 returni(iconst); 1168 break; 1169 } 1170 1171 case 33: 1172 1173 { 1174 ///* for i in 1..5 loop, we can't recognize 1. as a decimal,but 1 as decimal 1175 nchars = yytextlen; 1176 if (yylvalstr.charAt(nchars-1) == '.') 1177 { 1178 dummych1 = get_char(); 1179 unget_char(dummych1); 1180 if (dummych1 == '.') 1181 { 1182 yyless(nchars-1); 1183 yylvalstr = yylvalstr.substring(0,nchars - 1); 1184 returni (iconst); 1185 return;//exit; 1186 } 1187 } 1188 returni (fconst); 1189 break; 1190 } 1191 1192 case 34: 1193 1194 { 1195 returni (fconst); 1196 break; 1197 } 1198 1199 case 35: 1200 1201 { 1202 boolean dollarConstant = false; 1203 if (getyysstate() == xdolq){ 1204 int p = yylvalstr.indexOf("$"); 1205 if (p > 0){ 1206 dollarConstant = true; 1207 addlit(yylvalstr, p); 1208 yyless(p); 1209 return; 1210 } 1211 } 1212 1213 if (!dollarConstant){ 1214 int rw; 1215 if ( (rw = iskeyword(yylvalstr)) != -1) { 1216 //System.out.println(yylvalstr+",rw:"+rw); 1217 if ((rw == TBaseType.rrw_as)||(rw == TBaseType.rrw_do)){ 1218 isReadyForFunctionBody = true; 1219 }else{ 1220 isReadyForFunctionBody = false; 1221 } 1222 returni(rw); 1223 } 1224 else 1225 { 1226 isReadyForFunctionBody = false; 1227 returni(ident); 1228 } 1229 } 1230 break; 1231 } 1232 1233 case 36: 1234 1235 { 1236 returni (outer_join); 1237 break; 1238 } 1239 1240 case 37: 1241 1242 { 1243 if (getyysstate() == xdolq){ 1244 addlit(yylvalstr, yytextlen); 1245 return; 1246 }else{ 1247 returni (param); 1248 } 1249 1250 break; 1251 } 1252 1253 1254 case 38: 1255 1256 { 1257 returni (typecast); 1258 break; 1259 } 1260 1261 case 39: 1262 1263 { 1264 returni (double_dot); 1265 break; 1266 } 1267 1268 case 40: 1269 1270 { 1271 returni (assign_sign); 1272 break; 1273 } 1274 1275 case 41: 1276 1277 { 1278 returni(ident); 1279 break; 1280 } 1281 1282 case 42: 1283 1284 { 1285 returni (bind_v); 1286 break; 1287 } 1288 1289 case 43: 1290 1291 { 1292 returni (error); 1293 break; 1294 } 1295 1296 default:{ 1297 System.out.println("fatal error in yyaction"); 1298 } 1299 }//switch 1300}/*yyaction*/; 1301 1302 1303 1304 }