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