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