1 2 package prefuse.data.expression.parser; 3 4 import java.io.StringReader ; 5 import java.util.logging.Logger ; 6 7 import prefuse.data.expression.AndPredicate; 8 import prefuse.data.expression.ArithmeticExpression; 9 import prefuse.data.expression.BooleanLiteral; 10 import prefuse.data.expression.ColumnExpression; 11 import prefuse.data.expression.ComparisonPredicate; 12 import prefuse.data.expression.Expression; 13 import prefuse.data.expression.Function; 14 import prefuse.data.expression.FunctionTable; 15 import prefuse.data.expression.IfExpression; 16 import prefuse.data.expression.NotPredicate; 17 import prefuse.data.expression.NumericLiteral; 18 import prefuse.data.expression.ObjectLiteral; 19 import prefuse.data.expression.OrPredicate; 20 import prefuse.data.expression.Predicate; 21 import prefuse.data.expression.XorPredicate; 22 import prefuse.util.StringLib; 23 24 467 public class ExpressionParser implements ExpressionParserConstants { 468 469 private static final Logger s_logger 470 = Logger.getLogger(ExpressionParser.class.getName()); 471 472 private static boolean s_init = false; 473 private static Throwable s_error; 474 475 483 public synchronized static Expression parse(String expr, 484 boolean throwsException) 485 { 486 if ( !s_init ) { 488 new ExpressionParser(new StringReader (expr)); 489 s_init = true; 490 } else { 491 ExpressionParser.ReInit(new StringReader (expr)); 492 } 493 try { 495 Expression e = Parse(); 496 s_error = null; 497 s_logger.info("Parsed Expression: "+e); 498 return e; 499 } catch ( ParseException t ) { 500 s_error = t; 501 if ( throwsException ) { 502 throw t; 503 } else { 504 s_logger.warning("Expression Parse Error: " + t.getMessage() 505 + "\n" + StringLib.getStackTrace(t)); 506 return null; 507 } 508 } 509 } 510 511 518 public synchronized static Expression parse(String expr) { 519 return parse(expr, false); 520 } 521 522 529 public synchronized static Predicate predicate(String expr) { 530 Expression ex = parse(expr, false); 531 if ( ex == null ) { 532 return null; 533 } else if ( ex instanceof Predicate ) { 534 return (Predicate) ex; 535 } else { 536 s_error = new ClassCastException ("Expression is not a predicate"); 537 return null; 538 } 539 } 540 541 545 public synchronized static Throwable getError() { 546 return s_error; 547 } 548 549 555 private static String unescape(String s) { 556 int len = s.length(), base = 0, idx; 557 String escapes = "tnrbf\\\"'"; 558 String chars = "\t\n\r\b\f\\\"'"; 559 560 StringBuffer sbuf = null; 561 562 while ( (idx=s.indexOf('\\',base)) != -1) { 563 if ( sbuf != null ) 564 sbuf.append(s.substring(base, idx)); 565 566 if (idx+1 == len) break; 567 568 char c = s.charAt(idx+1); 570 571 int cidx = escapes.indexOf(c); 573 if (cidx == -1) { 574 sbuf.append('\\'); 576 sbuf.append(c); 577 } else { 578 if ( sbuf == null ) 580 sbuf = new StringBuffer (s.substring(base, idx)); 581 sbuf.append(chars.charAt(cidx)); 582 } 583 584 base = idx + 2; 586 } 587 if ( sbuf != null && base < len ) 588 sbuf.append(s.substring(base)); 589 590 return ( sbuf == null ? s : sbuf.toString() ); 591 } 592 593 static final public String Name() throws ParseException { 596 Token t; 597 t = jj_consume_token(IDENTIFIER); 598 {if (true) return t.image;} 599 throw new Error ("Missing return statement in function"); 600 } 601 602 static final public String Quoted() throws ParseException { 603 Token t; 604 t = jj_consume_token(QUOTED); 605 {if (true) return t.image.substring(1,t.image.length()-1);} 606 throw new Error ("Missing return statement in function"); 607 } 608 609 static final public Expression Parse() throws ParseException { 610 Expression e; 611 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 612 case TRUE: 613 case FALSE: 614 case NULL: 615 case IF: 616 case NOT: 617 case INT: 618 case LONG: 619 case DOUBLE: 620 case FLOAT: 621 case STRING: 622 case QUOTED: 623 case IDENTIFIER: 624 case LPAREN: 625 case ADD: 626 case SUB: 627 e = Expression(); 628 jj_consume_token(0); 629 {if (true) return e;} 630 break; 631 case 0: 632 jj_consume_token(0); 633 {if (true) throw new ParseException("No expression provided");} 634 break; 635 default: 636 jj_la1[0] = jj_gen; 637 jj_consume_token(-1); 638 throw new ParseException(); 639 } 640 throw new Error ("Missing return statement in function"); 641 } 642 643 static final public Expression Expression() throws ParseException { 644 Expression e; 645 e = OrExpression(); 646 {if (true) return e;} 647 throw new Error ("Missing return statement in function"); 648 } 649 650 static final public Expression OrExpression() throws ParseException { 651 Expression l, r; 652 l = XorExpression(); 653 label_1: 654 while (true) { 655 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 656 case OR: 657 ; 658 break; 659 default: 660 jj_la1[1] = jj_gen; 661 break label_1; 662 } 663 jj_consume_token(OR); 664 r = XorExpression(); 665 if ( l instanceof OrPredicate ) { 666 ((OrPredicate)l).add((Predicate)r); 667 } else { 668 l = new OrPredicate((Predicate)l,(Predicate)r); 669 } 670 } 671 {if (true) return l;} 672 throw new Error ("Missing return statement in function"); 673 } 674 675 static final public Expression XorExpression() throws ParseException { 676 Expression l, r; 677 l = AndExpression(); 678 label_2: 679 while (true) { 680 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 681 case XOR: 682 ; 683 break; 684 default: 685 jj_la1[2] = jj_gen; 686 break label_2; 687 } 688 jj_consume_token(XOR); 689 r = AndExpression(); 690 if ( l instanceof XorPredicate ) { 691 ((XorPredicate)l).add((Predicate)r); 692 } else { 693 l = new XorPredicate((Predicate)l,(Predicate)r); 694 } 695 } 696 {if (true) return l;} 697 throw new Error ("Missing return statement in function"); 698 } 699 700 static final public Expression AndExpression() throws ParseException { 701 Expression l, r; 702 l = EqualityExpression(); 703 label_3: 704 while (true) { 705 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 706 case AND: 707 ; 708 break; 709 default: 710 jj_la1[3] = jj_gen; 711 break label_3; 712 } 713 jj_consume_token(AND); 714 r = EqualityExpression(); 715 if ( l instanceof AndPredicate ) { 716 ((AndPredicate)l).add((Predicate)r); 717 } else { 718 l = new AndPredicate((Predicate)l,(Predicate)r); 719 } 720 } 721 {if (true) return l;} 722 throw new Error ("Missing return statement in function"); 723 } 724 725 static final public Expression EqualityExpression() throws ParseException { 726 Expression l, r; Token t; int op; 727 l = RelationalExpression(); 728 label_4: 729 while (true) { 730 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 731 case EQ: 732 case NE: 733 ; 734 break; 735 default: 736 jj_la1[4] = jj_gen; 737 break label_4; 738 } 739 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 740 case EQ: 741 t = jj_consume_token(EQ); 742 break; 743 case NE: 744 t = jj_consume_token(NE); 745 break; 746 default: 747 jj_la1[5] = jj_gen; 748 jj_consume_token(-1); 749 throw new ParseException(); 750 } 751 r = RelationalExpression(); 752 op = (t.kind==EQ ? ComparisonPredicate.EQ : ComparisonPredicate.NEQ); 753 l = new ComparisonPredicate(op, l, r); 754 } 755 {if (true) return l;} 756 throw new Error ("Missing return statement in function"); 757 } 758 759 static final public Expression RelationalExpression() throws ParseException { 760 Expression l, r; Token t; int op=-1; 761 l = AdditiveExpression(); 762 label_5: 763 while (true) { 764 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 765 case GT: 766 case LT: 767 case LE: 768 case GE: 769 ; 770 break; 771 default: 772 jj_la1[6] = jj_gen; 773 break label_5; 774 } 775 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 776 case LT: 777 t = jj_consume_token(LT); 778 break; 779 case GT: 780 t = jj_consume_token(GT); 781 break; 782 case LE: 783 t = jj_consume_token(LE); 784 break; 785 case GE: 786 t = jj_consume_token(GE); 787 break; 788 default: 789 jj_la1[7] = jj_gen; 790 jj_consume_token(-1); 791 throw new ParseException(); 792 } 793 r = AdditiveExpression(); 794 switch ( t.kind ) { 795 case LT: 796 op = ComparisonPredicate.LT; 797 break; 798 case GT: 799 op = ComparisonPredicate.GT; 800 break; 801 case LE: 802 op = ComparisonPredicate.LTEQ; 803 break; 804 case GE: 805 op = ComparisonPredicate.GTEQ; 806 break; 807 } 808 l = new ComparisonPredicate(op, l, r); 809 } 810 {if (true) return l;} 811 throw new Error ("Missing return statement in function"); 812 } 813 814 static final public Expression AdditiveExpression() throws ParseException { 815 Expression l, r; Token t; int op=-1; 816 l = MultiplicativeExpression(); 817 label_6: 818 while (true) { 819 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 820 case ADD: 821 case SUB: 822 case MOD: 823 ; 824 break; 825 default: 826 jj_la1[8] = jj_gen; 827 break label_6; 828 } 829 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 830 case ADD: 831 t = jj_consume_token(ADD); 832 break; 833 case SUB: 834 t = jj_consume_token(SUB); 835 break; 836 case MOD: 837 t = jj_consume_token(MOD); 838 break; 839 default: 840 jj_la1[9] = jj_gen; 841 jj_consume_token(-1); 842 throw new ParseException(); 843 } 844 r = MultiplicativeExpression(); 845 switch ( t.kind ) { 846 case ADD: 847 op = ArithmeticExpression.ADD; 848 break; 849 case SUB: 850 op = ArithmeticExpression.SUB; 851 break; 852 case MOD: 853 op = ArithmeticExpression.MOD; 854 break; 855 } 856 l = new ArithmeticExpression(op, l, r); 857 } 858 {if (true) return l;} 859 throw new Error ("Missing return statement in function"); 860 } 861 862 static final public Expression MultiplicativeExpression() throws ParseException { 863 Expression l, r; Token t; int op=-1; 864 l = UnaryExpression(); 865 label_7: 866 while (true) { 867 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 868 case MUL: 869 case DIV: 870 case POW: 871 ; 872 break; 873 default: 874 jj_la1[10] = jj_gen; 875 break label_7; 876 } 877 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 878 case MUL: 879 t = jj_consume_token(MUL); 880 break; 881 case DIV: 882 t = jj_consume_token(DIV); 883 break; 884 case POW: 885 t = jj_consume_token(POW); 886 break; 887 default: 888 jj_la1[11] = jj_gen; 889 jj_consume_token(-1); 890 throw new ParseException(); 891 } 892 r = UnaryExpression(); 893 switch ( t.kind ) { 894 case MUL: 895 op = ArithmeticExpression.MUL; 896 break; 897 case DIV: 898 op = ArithmeticExpression.DIV; 899 break; 900 case POW: 901 op = ArithmeticExpression.POW; 902 break; 903 } 904 l = new ArithmeticExpression(op, l, r); 905 } 906 {if (true) return l;} 907 throw new Error ("Missing return statement in function"); 908 } 909 910 static final public Expression UnaryExpression() throws ParseException { 911 Expression e; Token t; 912 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 913 case ADD: 914 case SUB: 915 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 916 case ADD: 917 t = jj_consume_token(ADD); 918 break; 919 case SUB: 920 t = jj_consume_token(SUB); 921 break; 922 default: 923 jj_la1[12] = jj_gen; 924 jj_consume_token(-1); 925 throw new ParseException(); 926 } 927 e = UnaryExpression(); 928 if ( t.kind == SUB && e instanceof NumericLiteral ) { 929 Number n = (Number )e.get(null); 930 if ( n instanceof Integer ) { 931 {if (true) return new NumericLiteral(-1*n.intValue());} 932 } if ( n instanceof Double ) { 933 {if (true) return new NumericLiteral(-1*n.doubleValue());} 934 } if ( n instanceof Long ) { 935 {if (true) return new NumericLiteral(-1*n.longValue());} 936 } if ( n instanceof Float ) { 937 {if (true) return new NumericLiteral(-1*n.floatValue());} 938 } else { 939 {if (true) return new ArithmeticExpression(ArithmeticExpression.MUL, 940 new NumericLiteral(-1), e);} 941 } 942 } else if ( t.kind == SUB ) { 943 {if (true) return new ArithmeticExpression(ArithmeticExpression.MUL, 944 new NumericLiteral(-1), e);} 945 } else { 946 {if (true) return e;} 947 } 948 break; 949 case NOT: 950 e = UnaryExpressionNotPlusMinus(); 951 {if (true) return e;} 952 break; 953 case TRUE: 954 case FALSE: 955 case NULL: 956 case IF: 957 case INT: 958 case LONG: 959 case DOUBLE: 960 case FLOAT: 961 case STRING: 962 case QUOTED: 963 case IDENTIFIER: 964 case LPAREN: 965 e = PrimaryExpression(); 966 {if (true) return e;} 967 break; 968 default: 969 jj_la1[13] = jj_gen; 970 jj_consume_token(-1); 971 throw new ParseException(); 972 } 973 throw new Error ("Missing return statement in function"); 974 } 975 976 static final public Expression UnaryExpressionNotPlusMinus() throws ParseException { 977 Expression e; 978 jj_consume_token(NOT); 979 e = UnaryExpression(); 980 if ( e instanceof NotPredicate ) { 981 {if (true) return ((NotPredicate)e).getPredicate();} 982 } else { 983 if ( !(e instanceof Predicate) ) { 984 {if (true) throw new ParseException("Can't negate a non-predicate");} 985 } else { 986 {if (true) return new NotPredicate((Predicate)e);} 987 } 988 } 989 throw new Error ("Missing return statement in function"); 990 } 991 992 static final public Expression PrimaryExpression() throws ParseException { 993 Expression e; 994 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 995 case TRUE: 996 case FALSE: 997 case NULL: 998 case INT: 999 case LONG: 1000 case DOUBLE: 1001 case FLOAT: 1002 case STRING: 1003 e = Literal(); 1004 {if (true) return e;} 1005 break; 1006 case IF: 1007 e = IfStatement(); 1008 {if (true) return e;} 1009 break; 1010 case QUOTED: 1011 case IDENTIFIER: 1012 e = Identifier(); 1013 {if (true) return e;} 1014 break; 1015 case LPAREN: 1016 jj_consume_token(LPAREN); 1017 e = Expression(); 1018 jj_consume_token(RPAREN); 1019 {if (true) return e;} 1020 break; 1021 default: 1022 jj_la1[14] = jj_gen; 1023 jj_consume_token(-1); 1024 throw new ParseException(); 1025 } 1026 throw new Error ("Missing return statement in function"); 1027 } 1028 1029 static final public Expression Literal() throws ParseException { 1030 Token t; 1031 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 1032 case INT: 1033 t = jj_consume_token(INT); 1034 {if (true) return new NumericLiteral(Integer.parseInt(t.image));} 1035 break; 1036 case LONG: 1037 t = jj_consume_token(LONG); 1038 {if (true) return new NumericLiteral(Long.parseLong(t.image));} 1039 break; 1040 case FLOAT: 1041 t = jj_consume_token(FLOAT); 1042 {if (true) return new NumericLiteral(Float.parseFloat(t.image));} 1043 break; 1044 case DOUBLE: 1045 t = jj_consume_token(DOUBLE); 1046 {if (true) return new NumericLiteral(Double.parseDouble(t.image));} 1047 break; 1048 case STRING: 1049 t = jj_consume_token(STRING); 1050 String s = unescape(t.image.substring(1, t.image.length()-1)); 1051 {if (true) return new ObjectLiteral(s);} 1052 break; 1053 case TRUE: 1054 jj_consume_token(TRUE); 1055 {if (true) return new BooleanLiteral(true);} 1056 break; 1057 case FALSE: 1058 jj_consume_token(FALSE); 1059 {if (true) return new BooleanLiteral(false);} 1060 break; 1061 case NULL: 1062 jj_consume_token(NULL); 1063 {if (true) return new ObjectLiteral(null);} 1064 break; 1065 default: 1066 jj_la1[15] = jj_gen; 1067 jj_consume_token(-1); 1068 throw new ParseException(); 1069 } 1070 throw new Error ("Missing return statement in function"); 1071 } 1072 1073 static final public Expression Identifier() throws ParseException { 1074 String s; Function f=null; Expression e; 1075 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 1076 case QUOTED: 1077 s = Quoted(); 1078 {if (true) return new ColumnExpression(s);} 1079 break; 1080 case IDENTIFIER: 1081 s = Name(); 1082 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 1083 case LPAREN: 1084 jj_consume_token(LPAREN); 1085 f = FunctionTable.createFunction(s); 1086 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 1087 case TRUE: 1088 case FALSE: 1089 case NULL: 1090 case IF: 1091 case NOT: 1092 case INT: 1093 case LONG: 1094 case DOUBLE: 1095 case FLOAT: 1096 case STRING: 1097 case QUOTED: 1098 case IDENTIFIER: 1099 case LPAREN: 1100 case ADD: 1101 case SUB: 1102 e = Expression(); 1103 f.addParameter(e); 1104 label_8: 1105 while (true) { 1106 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 1107 case 43: 1108 ; 1109 break; 1110 default: 1111 jj_la1[16] = jj_gen; 1112 break label_8; 1113 } 1114 jj_consume_token(43); 1115 e = Expression(); 1116 f.addParameter(e); 1117 } 1118 break; 1119 default: 1120 jj_la1[17] = jj_gen; 1121 ; 1122 } 1123 jj_consume_token(RPAREN); 1124 break; 1125 default: 1126 jj_la1[18] = jj_gen; 1127 ; 1128 } 1129 {if (true) return f==null ? new ColumnExpression(s) : (Expression)f;} 1130 break; 1131 default: 1132 jj_la1[19] = jj_gen; 1133 jj_consume_token(-1); 1134 throw new ParseException(); 1135 } 1136 throw new Error ("Missing return statement in function"); 1137 } 1138 1139 static final public Expression IfStatement() throws ParseException { 1140 Expression p, t, e; 1141 jj_consume_token(IF); 1142 p = Expression(); 1143 jj_consume_token(THEN); 1144 t = Expression(); 1145 jj_consume_token(ELSE); 1146 e = Expression(); 1147 if ( !(p instanceof Predicate) ) 1148 {if (true) throw new ParseException("IF-statement test must be a predicate");} 1149 {if (true) return new IfExpression((Predicate)p, t, e);} 1150 throw new Error ("Missing return statement in function"); 1151 } 1152 1153 static private boolean jj_initialized_once = false; 1154 static public ExpressionParserTokenManager token_source; 1155 static JavaCharStream jj_input_stream; 1156 static public Token token, jj_nt; 1157 static private int jj_ntk; 1158 static private int jj_gen; 1159 static final private int[] jj_la1 = new int[20]; 1160 static private int[] jj_la1_0; 1161 static private int[] jj_la1_1; 1162 static { 1163 jj_la1_0(); 1164 jj_la1_1(); 1165 } 1166 private static void jj_la1_0() { 1167 jj_la1_0 = new int[] {0x277143c1,0x2000,0x8000,0x1000,0x80000000,0x80000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x277143c0,0x277103c0,0x17101c0,0x0,0x277143c0,0x20000000,0x6000000,}; 1168 } 1169 private static void jj_la1_1() { 1170 jj_la1_1 = new int[] {0x60,0x0,0x0,0x0,0x10,0x10,0xf,0xf,0x460,0x460,0x380,0x380,0x60,0x60,0x0,0x0,0x800,0x60,0x0,0x0,}; 1171 } 1172 1173 public ExpressionParser(java.io.InputStream stream) { 1174 if (jj_initialized_once) { 1175 System.out.println("ERROR: Second call to constructor of static parser. You must"); 1176 System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); 1177 System.out.println(" during parser generation."); 1178 throw new Error (); 1179 } 1180 jj_initialized_once = true; 1181 jj_input_stream = new JavaCharStream(stream, 1, 1); 1182 token_source = new ExpressionParserTokenManager(jj_input_stream); 1183 token = new Token(); 1184 jj_ntk = -1; 1185 jj_gen = 0; 1186 for (int i = 0; i < 20; i++) jj_la1[i] = -1; 1187 } 1188 1189 static public void ReInit(java.io.InputStream stream) { 1190 jj_input_stream.ReInit(stream, 1, 1); 1191 ExpressionParserTokenManager.ReInit(jj_input_stream); 1192 token = new Token(); 1193 jj_ntk = -1; 1194 jj_gen = 0; 1195 for (int i = 0; i < 20; i++) jj_la1[i] = -1; 1196 } 1197 1198 public ExpressionParser(java.io.Reader stream) { 1199 if (jj_initialized_once) { 1200 System.out.println("ERROR: Second call to constructor of static parser. You must"); 1201 System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); 1202 System.out.println(" during parser generation."); 1203 throw new Error (); 1204 } 1205 jj_initialized_once = true; 1206 jj_input_stream = new JavaCharStream(stream, 1, 1); 1207 token_source = new ExpressionParserTokenManager(jj_input_stream); 1208 token = new Token(); 1209 jj_ntk = -1; 1210 jj_gen = 0; 1211 for (int i = 0; i < 20; i++) jj_la1[i] = -1; 1212 } 1213 1214 static public void ReInit(java.io.Reader stream) { 1215 jj_input_stream.ReInit(stream, 1, 1); 1216 ExpressionParserTokenManager.ReInit(jj_input_stream); 1217 token = new Token(); 1218 jj_ntk = -1; 1219 jj_gen = 0; 1220 for (int i = 0; i < 20; i++) jj_la1[i] = -1; 1221 } 1222 1223 public ExpressionParser(ExpressionParserTokenManager tm) { 1224 if (jj_initialized_once) { 1225 System.out.println("ERROR: Second call to constructor of static parser. You must"); 1226 System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); 1227 System.out.println(" during parser generation."); 1228 throw new Error (); 1229 } 1230 jj_initialized_once = true; 1231 token_source = tm; 1232 token = new Token(); 1233 jj_ntk = -1; 1234 jj_gen = 0; 1235 for (int i = 0; i < 20; i++) jj_la1[i] = -1; 1236 } 1237 1238 public void ReInit(ExpressionParserTokenManager tm) { 1239 token_source = tm; 1240 token = new Token(); 1241 jj_ntk = -1; 1242 jj_gen = 0; 1243 for (int i = 0; i < 20; i++) jj_la1[i] = -1; 1244 } 1245 1246 static final private Token jj_consume_token(int kind) throws ParseException { 1247 Token oldToken; 1248 if ((oldToken = token).next != null) token = token.next; 1249 else token = token.next = ExpressionParserTokenManager.getNextToken(); 1250 jj_ntk = -1; 1251 if (token.kind == kind) { 1252 jj_gen++; 1253 return token; 1254 } 1255 token = oldToken; 1256 jj_kind = kind; 1257 throw generateParseException(); 1258 } 1259 1260 static final public Token getNextToken() { 1261 if (token.next != null) token = token.next; 1262 else token = token.next = ExpressionParserTokenManager.getNextToken(); 1263 jj_ntk = -1; 1264 jj_gen++; 1265 return token; 1266 } 1267 1268 static final public Token getToken(int index) { 1269 Token t = token; 1270 for (int i = 0; i < index; i++) { 1271 if (t.next != null) t = t.next; 1272 else t = t.next = ExpressionParserTokenManager.getNextToken(); 1273 } 1274 return t; 1275 } 1276 1277 static final private int jj_ntk() { 1278 if ((jj_nt=token.next) == null) 1279 return (jj_ntk = (token.next=ExpressionParserTokenManager.getNextToken()).kind); 1280 else 1281 return (jj_ntk = jj_nt.kind); 1282 } 1283 1284 static private java.util.Vector jj_expentries = new java.util.Vector (); 1285 static private int[] jj_expentry; 1286 static private int jj_kind = -1; 1287 1288 static public ParseException generateParseException() { 1289 jj_expentries.removeAllElements(); 1290 boolean[] la1tokens = new boolean[44]; 1291 for (int i = 0; i < 44; i++) { 1292 la1tokens[i] = false; 1293 } 1294 if (jj_kind >= 0) { 1295 la1tokens[jj_kind] = true; 1296 jj_kind = -1; 1297 } 1298 for (int i = 0; i < 20; i++) { 1299 if (jj_la1[i] == jj_gen) { 1300 for (int j = 0; j < 32; j++) { 1301 if ((jj_la1_0[i] & (1<<j)) != 0) { 1302 la1tokens[j] = true; 1303 } 1304 if ((jj_la1_1[i] & (1<<j)) != 0) { 1305 la1tokens[32+j] = true; 1306 } 1307 } 1308 } 1309 } 1310 for (int i = 0; i < 44; i++) { 1311 if (la1tokens[i]) { 1312 jj_expentry = new int[1]; 1313 jj_expentry[0] = i; 1314 jj_expentries.addElement(jj_expentry); 1315 } 1316 } 1317 int[][] exptokseq = new int[jj_expentries.size()][]; 1318 for (int i = 0; i < jj_expentries.size(); i++) { 1319 exptokseq[i] = (int[])jj_expentries.elementAt(i); 1320 } 1321 return new ParseException(token, exptokseq, tokenImage); 1322 } 1323 1324 static final public void enable_tracing() { 1325 } 1326 1327 static final public void disable_tracing() { 1328 } 1329 1330} 1331 | Popular Tags |