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