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