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