001/* Generated By:JavaCC: Do not edit this line. UParser.java */
002/*
003
004 Copyright (c) 1998-2008 The Regents of the University of California.
005 All rights reserved.
006 Permission is hereby granted, without written agreement and without
007 license or royalty fees, to use, copy, modify, and distribute this
008 software and its documentation for any purpose, provided that the above
009 copyright notice and the following two paragraphs appear in all copies
010 of this software.
011
012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
016 SUCH DAMAGE.
017
018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
023 ENHANCEMENTS, OR MODIFICATIONS.
024
025                                        PT_COPYRIGHT_VERSION_3
026                                        COPYRIGHTENDKEY
027*/
028
029package ptolemy.moml.unit;
030
031import java.io.Reader;
032import java.io.StringReader;
033import java.util.Vector;
034
035//////////////////////////////////////////////////////////////////////
036//// UParser.jj
037/**
038This file implements a Unit parser for Ptolemy II using the
039JavaCC parser generator.
040
041@author Rowland R Johnson
042@version UParser.jj,v 1.9 2004/04/14 14:18:38 rowland Exp
043@since Ptolemy II 4.0
044@Pt.ProposedRating Red (rowland)
045@Pt.AcceptedRating Red (rowland)
046*/
047@SuppressWarnings("unused")
048public class UParser implements UParserConstants {
049
050    boolean debug = false;
051
052    public UParser() {
053        this(new StringReader(""));
054    }
055
056    /** Parse a unit expression.
057     * @param expression
058     * @exception ParseException If parsing error is encountered.
059     */
060    public UnitExpr parseUnitExpr(String expression) throws ParseException {
061
062        if (expression.equals("")) {
063            return null;
064        }
065        Reader reader = new StringReader(expression);
066        this.ReInit(reader);
067        // Parse the expression to obtain the parse tree
068        UnitExpr unitExpr = uExpr();
069        return unitExpr;
070    }
071
072    /** Parse a set of equations separated by semicolons.
073     * @param expression
074     * @exception ParseException If parsing error is encountered.
075     */
076    public Vector parseEquations(String expression) throws ParseException {
077
078        if (expression.equals("")) {
079            return null;
080        }
081        Reader reader = new StringReader(expression);
082        this.ReInit(reader);
083        // Parse the expression to obtain the parse tree
084        Vector _equations = Equations();
085        return _equations;
086    }
087
088    final public UnitExpr uExpr() throws ParseException {
089        UnitTerm unitTerm = null;
090        UnitTerm firstUnitTerm = null;
091
092        UnitExpr unitExpr = new UnitExpr();
093        firstUnitTerm = uTerm();
094        unitExpr.addUnitTerm(firstUnitTerm);
095        label_1: while (true) {
096            switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
097            case MULTIPLY:
098            case DIVIDE:
099            case INTEGER:
100            case DOUBLE:
101            case UNITLABEL:
102            case PORT:
103            case LPAREN:
104                ;
105                break;
106            default:
107                jj_la1[0] = jj_gen;
108                break label_1;
109            }
110            switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
111            case DIVIDE:
112                jj_consume_token(DIVIDE);
113                unitTerm = uTerm();
114                unitExpr.addUnitTerm(unitTerm.invert());
115                break;
116            case MULTIPLY:
117                jj_consume_token(MULTIPLY);
118                unitTerm = uTerm();
119                unitExpr.addUnitTerm(unitTerm);
120                break;
121            case INTEGER:
122            case DOUBLE:
123            case UNITLABEL:
124            case PORT:
125            case LPAREN:
126                unitTerm = uTerm();
127                unitExpr.addUnitTerm(unitTerm);
128                break;
129            default:
130                jj_la1[1] = jj_gen;
131                jj_consume_token(-1);
132                throw new ParseException();
133            }
134        }
135        {
136            if (true) {
137                return unitExpr;
138            }
139        }
140        throw new Error("Missing return statement in function");
141    }
142
143    final public UnitTerm uTerm() throws ParseException {
144        UnitTerm unitTerm = new UnitTerm();
145        UnitExpr unitExpr;
146        Token U;
147        int exponent;
148        double scale;
149        if (jj_2_1(2)) {
150            U = unit();
151            jj_consume_token(POWER);
152            exponent = exponent();
153            String unitLabel = U.image;
154            if (U.kind == UParserConstants.PORT) {
155                unitTerm.setVariable(unitLabel.substring(1));
156            } else if (U.kind == UParserConstants.UNITLABEL) {
157                Unit unit = UnitLibrary.getUnitByName(unitLabel);
158                if (unit != null) {
159                    unitTerm.setUnit(unit);
160                } else {
161                    {
162                        if (true) {
163                            throw new ParseException(unitLabel
164                                    + " is a not variable and is not grounded in the Units Library");
165                        }
166                    }
167                }
168            } else {
169                {
170                    if (true) {
171                        throw new ParseException(unitLabel
172                                + " is a not variable and is not a Unit");
173                    }
174                }
175            }
176
177            unitTerm.setExponent(exponent);
178        } else {
179            switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
180            case UNITLABEL:
181            case PORT:
182                U = unit();
183                String unitLabel = U.image;
184                if (U.kind == UParserConstants.PORT) {
185                    unitTerm.setVariable(unitLabel.substring(1));
186                } else if (U.kind == UParserConstants.UNITLABEL) {
187                    Unit unit = UnitLibrary.getUnitByName(unitLabel);
188                    if (unit != null) {
189                        unitTerm.setUnit(unit);
190                    } else {
191                        {
192                            if (true) {
193                                throw new ParseException(unitLabel
194                                        + " is a not variable and is not grounded in the Units Library");
195                            }
196                        }
197                    }
198                } else {
199                    {
200                        if (true) {
201                            throw new ParseException(unitLabel
202                                    + " is a not variable and is not a Unit");
203                        }
204                    }
205                }
206                break;
207            case INTEGER:
208            case DOUBLE:
209                scale = number();
210                Unit unit = new Unit();
211                unit.setScale(scale);
212                unitTerm.setUnit(unit);
213                break;
214            case LPAREN:
215                jj_consume_token(LPAREN);
216                unitExpr = uExpr();
217                jj_consume_token(RPAREN);
218                unitTerm.setUnitExpr(unitExpr);
219                ;
220                break;
221            default:
222                jj_la1[2] = jj_gen;
223                jj_consume_token(-1);
224                throw new ParseException();
225            }
226        }
227        {
228            if (true) {
229                return unitTerm;
230            }
231        }
232        throw new Error("Missing return statement in function");
233    }
234
235    final public Token unit() throws ParseException {
236        Token retv;
237        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
238        case UNITLABEL:
239            retv = jj_consume_token(UNITLABEL);
240            break;
241        case PORT:
242            retv = jj_consume_token(PORT);
243            break;
244        default:
245            jj_la1[3] = jj_gen;
246            jj_consume_token(-1);
247            throw new ParseException();
248        }
249        {
250            if (true) {
251                return retv;
252            }
253        }
254        throw new Error("Missing return statement in function");
255    }
256
257    final public Vector Equations() throws ParseException {
258        Vector l = null;
259        UnitEquation node;
260        node = Equation();
261        label_2: while (true) {
262            if (jj_2_2(2)) {
263                ;
264            } else {
265                break label_2;
266            }
267            jj_consume_token(SEMICOLON);
268            l = Equations();
269        }
270        if (l == null) {
271            l = new Vector();
272        }
273        l.add(node);
274        {
275            if (true) {
276                return l;
277            }
278        }
279        throw new Error("Missing return statement in function");
280    }
281
282    final public UnitEquation Equation() throws ParseException {
283        UnitEquation uEquation;
284        Token r;
285        UnitExpr lhs, rhs;
286        lhs = uExpr();
287        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
288        case EQUALS:
289            r = jj_consume_token(EQUALS);
290            break;
291        case LT:
292            r = jj_consume_token(LT);
293            break;
294        default:
295            jj_la1[4] = jj_gen;
296            jj_consume_token(-1);
297            throw new ParseException();
298        }
299        rhs = uExpr();
300        uEquation = new UnitEquation(lhs, rhs);
301        {
302            if (true) {
303                return uEquation;
304            }
305        }
306        throw new Error("Missing return statement in function");
307    }
308
309    final public int exponent() throws ParseException {
310        Token x;
311        int retv;
312        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
313        case INTEGER:
314            x = jj_consume_token(INTEGER);
315            retv = Integer.parseInt(x.image); {
316            if (true) {
317                return retv;
318            }
319        }
320            break;
321        case MINUS:
322            jj_consume_token(MINUS);
323            x = jj_consume_token(INTEGER);
324            retv = -Integer.parseInt(x.image); {
325            if (true) {
326                return retv;
327            }
328        }
329            break;
330        default:
331            jj_la1[5] = jj_gen;
332            jj_consume_token(-1);
333            throw new ParseException();
334        }
335        throw new Error("Missing return statement in function");
336    }
337
338    final public double number() throws ParseException {
339        int len;
340        String tidied, x;
341        switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
342        case DOUBLE:
343            jj_consume_token(DOUBLE);
344            Double value;
345            try {
346                x = token.image.toLowerCase();
347                len = x.length();
348                if (x.endsWith("d") || x.endsWith("f")) {
349                    // all floating point numbers are double
350                    value = new Double(x.substring(0, len - 1));
351                } else {
352                    value = new Double(x);
353                }
354            } catch (NumberFormatException ee) {
355                {
356                    if (true) {
357                        throw new ParseException("Unable to convert token "
358                                + token.image + " to an float or double");
359                    }
360                }
361            } {
362            if (true) {
363                return value.doubleValue();
364            }
365        }
366            break;
367        case INTEGER:
368            jj_consume_token(INTEGER);
369            try {
370                x = token.image.toLowerCase();
371                len = x.length();
372
373                int radix;
374                boolean mustBeLong = x.endsWith("l");
375
376                int prefixLength;
377                int suffixLength;
378
379                if (mustBeLong) {
380                    suffixLength = 1;
381                } else {
382                    suffixLength = 0;
383                }
384
385                if (x.startsWith("0x")) {
386                    // Input is a hex number.
387                    radix = 16;
388                    prefixLength = 2;
389                } else if (x.startsWith("0")) {
390                    // Input is an octal number.
391                    radix = 8;
392                    prefixLength = 0;
393                } else {
394                    // Input is a decimal number.
395                    radix = 10;
396                    prefixLength = 0;
397                }
398
399                // Strip off the radix prefix and the length suffix.
400                x = x.substring(prefixLength, len - suffixLength);
401
402                if (mustBeLong) {
403                    // If the size was specified as long, then create a long.
404                    {
405                        if (true) {
406                            return (Long.parseLong(x, radix));
407                        }
408                    }
409                } else {
410                    // Try to infer the size.  Inferred sizes are at least
411                    // integer.
412                    try {
413                        {
414                            if (true) {
415                                return Integer.parseInt(x, radix);
416                            }
417                        }
418                    } catch (NumberFormatException nfe) {
419                        {
420                            if (true) {
421                                return Double.NaN;
422                            }
423                        }
424                    }
425                }
426            } catch (NumberFormatException ee) {
427                {
428                    if (true) {
429                        throw new ParseException("Unable to convert token "
430                                + token.image + " to an integer or long");
431                    }
432                }
433            }
434            break;
435        default:
436            jj_la1[6] = jj_gen;
437            jj_consume_token(-1);
438            throw new ParseException();
439        }
440        throw new Error("Missing return statement in function");
441    }
442
443    private boolean jj_2_1(int xla) {
444        jj_la = xla;
445        jj_lastpos = jj_scanpos = token;
446        try {
447            return !jj_3_1();
448        } catch (LookaheadSuccess ls) {
449            return true;
450        } finally {
451            jj_save(0, xla);
452        }
453    }
454
455    private boolean jj_2_2(int xla) {
456        jj_la = xla;
457        jj_lastpos = jj_scanpos = token;
458        try {
459            return !jj_3_2();
460        } catch (LookaheadSuccess ls) {
461            return true;
462        } finally {
463            jj_save(1, xla);
464        }
465    }
466
467    private boolean jj_3R_9() {
468        if (jj_3R_11()) {
469            return true;
470        }
471        return false;
472    }
473
474    private boolean jj_3R_7() {
475        Token xsp;
476        xsp = jj_scanpos;
477        if (jj_3_1()) {
478            jj_scanpos = xsp;
479            if (jj_3R_8()) {
480                jj_scanpos = xsp;
481                if (jj_3R_9()) {
482                    jj_scanpos = xsp;
483                    if (jj_3R_10()) {
484                        return true;
485                    }
486                }
487            }
488        }
489        return false;
490    }
491
492    private boolean jj_3R_13() {
493        if (jj_scan_token(INTEGER)) {
494            return true;
495        }
496        return false;
497    }
498
499    private boolean jj_3R_3() {
500        Token xsp;
501        xsp = jj_scanpos;
502        if (jj_scan_token(17)) {
503            jj_scanpos = xsp;
504            if (jj_scan_token(19)) {
505                return true;
506            }
507        }
508        return false;
509    }
510
511    private boolean jj_3R_12() {
512        if (jj_scan_token(DOUBLE)) {
513            return true;
514        }
515        return false;
516    }
517
518    private boolean jj_3R_11() {
519        Token xsp;
520        xsp = jj_scanpos;
521        if (jj_3R_12()) {
522            jj_scanpos = xsp;
523            if (jj_3R_13()) {
524                return true;
525            }
526        }
527        return false;
528    }
529
530    private boolean jj_3R_4() {
531        if (jj_3R_5()) {
532            return true;
533        }
534        return false;
535    }
536
537    private boolean jj_3_2() {
538        if (jj_scan_token(SEMICOLON)) {
539            return true;
540        }
541        if (jj_3R_4()) {
542            return true;
543        }
544        return false;
545    }
546
547    private boolean jj_3R_6() {
548        if (jj_3R_7()) {
549            return true;
550        }
551        return false;
552    }
553
554    private boolean jj_3R_10() {
555        if (jj_scan_token(LPAREN)) {
556            return true;
557        }
558        return false;
559    }
560
561    private boolean jj_3R_5() {
562        if (jj_3R_6()) {
563            return true;
564        }
565        return false;
566    }
567
568    private boolean jj_3R_8() {
569        if (jj_3R_3()) {
570            return true;
571        }
572        return false;
573    }
574
575    private boolean jj_3_1() {
576        if (jj_3R_3()) {
577            return true;
578        }
579        if (jj_scan_token(POWER)) {
580            return true;
581        }
582        return false;
583    }
584
585    /** Generated Token Manager. */
586    public UParserTokenManager token_source;
587    SimpleCharStream jj_input_stream;
588    /** Current token. */
589    public Token token;
590    /** Next token. */
591    public Token jj_nt;
592    private int jj_ntk;
593    private Token jj_scanpos, jj_lastpos;
594    private int jj_la;
595    private int jj_gen;
596    final private int[] jj_la1 = new int[7];
597    static private int[] jj_la1_0;
598    static {
599        jj_la1_init_0();
600    }
601
602    private static void jj_la1_init_0() {
603        jj_la1_0 = new int[] { 0x1b4180, 0x1b4180, 0x1b4000, 0xa0000, 0xc00,
604                0x4040, 0x14000, };
605    }
606
607    final private JJCalls[] jj_2_rtns = new JJCalls[2];
608    private boolean jj_rescan = false;
609    private int jj_gc = 0;
610
611    /** Constructor with InputStream. */
612    public UParser(java.io.InputStream stream) {
613        this(stream, null);
614    }
615
616    /** Constructor with InputStream and supplied encoding */
617    public UParser(java.io.InputStream stream, String encoding) {
618        try {
619            jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1);
620        } catch (java.io.UnsupportedEncodingException e) {
621            throw new RuntimeException(e);
622        }
623        token_source = new UParserTokenManager(jj_input_stream);
624        token = new Token();
625        jj_ntk = -1;
626        jj_gen = 0;
627        for (int i = 0; i < 7; i++) {
628            jj_la1[i] = -1;
629        }
630        for (int i = 0; i < jj_2_rtns.length; i++) {
631            jj_2_rtns[i] = new JJCalls();
632        }
633    }
634
635    /** Reinitialise. */
636    public void ReInit(java.io.InputStream stream) {
637        ReInit(stream, null);
638    }
639
640    /** Reinitialise. */
641    public void ReInit(java.io.InputStream stream, String encoding) {
642        try {
643            jj_input_stream.ReInit(stream, encoding, 1, 1);
644        } catch (java.io.UnsupportedEncodingException e) {
645            throw new RuntimeException(e);
646        }
647        token_source.ReInit(jj_input_stream);
648        token = new Token();
649        jj_ntk = -1;
650        jj_gen = 0;
651        for (int i = 0; i < 7; i++) {
652            jj_la1[i] = -1;
653        }
654        for (int i = 0; i < jj_2_rtns.length; i++) {
655            jj_2_rtns[i] = new JJCalls();
656        }
657    }
658
659    /** Constructor. */
660    public UParser(java.io.Reader stream) {
661        jj_input_stream = new SimpleCharStream(stream, 1, 1);
662        token_source = new UParserTokenManager(jj_input_stream);
663        token = new Token();
664        jj_ntk = -1;
665        jj_gen = 0;
666        for (int i = 0; i < 7; i++) {
667            jj_la1[i] = -1;
668        }
669        for (int i = 0; i < jj_2_rtns.length; i++) {
670            jj_2_rtns[i] = new JJCalls();
671        }
672    }
673
674    /** Reinitialise. */
675    public void ReInit(java.io.Reader stream) {
676        jj_input_stream.ReInit(stream, 1, 1);
677        token_source.ReInit(jj_input_stream);
678        token = new Token();
679        jj_ntk = -1;
680        jj_gen = 0;
681        for (int i = 0; i < 7; i++) {
682            jj_la1[i] = -1;
683        }
684        for (int i = 0; i < jj_2_rtns.length; i++) {
685            jj_2_rtns[i] = new JJCalls();
686        }
687    }
688
689    /** Constructor with generated Token Manager. */
690    public UParser(UParserTokenManager tm) {
691        token_source = tm;
692        token = new Token();
693        jj_ntk = -1;
694        jj_gen = 0;
695        for (int i = 0; i < 7; i++) {
696            jj_la1[i] = -1;
697        }
698        for (int i = 0; i < jj_2_rtns.length; i++) {
699            jj_2_rtns[i] = new JJCalls();
700        }
701    }
702
703    /** Reinitialise. */
704    public void ReInit(UParserTokenManager tm) {
705        token_source = tm;
706        token = new Token();
707        jj_ntk = -1;
708        jj_gen = 0;
709        for (int i = 0; i < 7; i++) {
710            jj_la1[i] = -1;
711        }
712        for (int i = 0; i < jj_2_rtns.length; i++) {
713            jj_2_rtns[i] = new JJCalls();
714        }
715    }
716
717    private Token jj_consume_token(int kind) throws ParseException {
718        Token oldToken;
719        if ((oldToken = token).next != null) {
720            token = token.next;
721        } else {
722            token = token.next = token_source.getNextToken();
723        }
724        jj_ntk = -1;
725        if (token.kind == kind) {
726            jj_gen++;
727            if (++jj_gc > 100) {
728                jj_gc = 0;
729                for (int i = 0; i < jj_2_rtns.length; i++) {
730                    JJCalls c = jj_2_rtns[i];
731                    while (c != null) {
732                        if (c.gen < jj_gen) {
733                            c.first = null;
734                        }
735                        c = c.next;
736                    }
737                }
738            }
739            return token;
740        }
741        token = oldToken;
742        jj_kind = kind;
743        throw generateParseException();
744    }
745
746    static private final class LookaheadSuccess extends java.lang.Error {
747    }
748
749    final private LookaheadSuccess jj_ls = new LookaheadSuccess();
750
751    private boolean jj_scan_token(int kind) {
752        if (jj_scanpos == jj_lastpos) {
753            jj_la--;
754            if (jj_scanpos.next == null) {
755                jj_lastpos = jj_scanpos = jj_scanpos.next = token_source
756                        .getNextToken();
757            } else {
758                jj_lastpos = jj_scanpos = jj_scanpos.next;
759            }
760        } else {
761            jj_scanpos = jj_scanpos.next;
762        }
763        if (jj_rescan) {
764            int i = 0;
765            Token tok = token;
766            while (tok != null && tok != jj_scanpos) {
767                i++;
768                tok = tok.next;
769            }
770            if (tok != null) {
771                jj_add_error_token(kind, i);
772            }
773        }
774        if (jj_scanpos.kind != kind) {
775            return true;
776        }
777        if (jj_la == 0 && jj_scanpos == jj_lastpos) {
778            throw jj_ls;
779        }
780        return false;
781    }
782
783    /** Get the next Token. */
784    final public Token getNextToken() {
785        if (token.next != null) {
786            token = token.next;
787        } else {
788            token = token.next = token_source.getNextToken();
789        }
790        jj_ntk = -1;
791        jj_gen++;
792        return token;
793    }
794
795    /** Get the specific Token. */
796    final public Token getToken(int index) {
797        Token t = token;
798        for (int i = 0; i < index; i++) {
799            if (t.next != null) {
800                t = t.next;
801            } else {
802                t = t.next = token_source.getNextToken();
803            }
804        }
805        return t;
806    }
807
808    private int jj_ntk() {
809        if ((jj_nt = token.next) == null) {
810            return (jj_ntk = (token.next = token_source.getNextToken()).kind);
811        } else {
812            return (jj_ntk = jj_nt.kind);
813        }
814    }
815
816    private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
817    private int[] jj_expentry;
818    private int jj_kind = -1;
819    private int[] jj_lasttokens = new int[100];
820    private int jj_endpos;
821
822    private void jj_add_error_token(int kind, int pos) {
823        if (pos >= 100) {
824            return;
825        }
826        if (pos == jj_endpos + 1) {
827            jj_lasttokens[jj_endpos++] = kind;
828        } else if (jj_endpos != 0) {
829            jj_expentry = new int[jj_endpos];
830            for (int i = 0; i < jj_endpos; i++) {
831                jj_expentry[i] = jj_lasttokens[i];
832            }
833            jj_entries_loop: for (java.util.Iterator<?> it = jj_expentries
834                    .iterator(); it.hasNext();) {
835                int[] oldentry = (int[]) (it.next());
836                if (oldentry.length == jj_expentry.length) {
837                    for (int i = 0; i < jj_expentry.length; i++) {
838                        if (oldentry[i] != jj_expentry[i]) {
839                            continue jj_entries_loop;
840                        }
841                    }
842                    jj_expentries.add(jj_expentry);
843                    break jj_entries_loop;
844                }
845            }
846            if (pos != 0) {
847                jj_lasttokens[(jj_endpos = pos) - 1] = kind;
848            }
849        }
850    }
851
852    /** Generate ParseException. */
853    public ParseException generateParseException() {
854        jj_expentries.clear();
855        boolean[] la1tokens = new boolean[22];
856        if (jj_kind >= 0) {
857            la1tokens[jj_kind] = true;
858            jj_kind = -1;
859        }
860        for (int i = 0; i < 7; i++) {
861            if (jj_la1[i] == jj_gen) {
862                for (int j = 0; j < 32; j++) {
863                    if ((jj_la1_0[i] & (1 << j)) != 0) {
864                        la1tokens[j] = true;
865                    }
866                }
867            }
868        }
869        for (int i = 0; i < 22; i++) {
870            if (la1tokens[i]) {
871                jj_expentry = new int[1];
872                jj_expentry[0] = i;
873                jj_expentries.add(jj_expentry);
874            }
875        }
876        jj_endpos = 0;
877        jj_rescan_token();
878        jj_add_error_token(0, 0);
879        int[][] exptokseq = new int[jj_expentries.size()][];
880        for (int i = 0; i < jj_expentries.size(); i++) {
881            exptokseq[i] = jj_expentries.get(i);
882        }
883        return new ParseException(token, exptokseq, tokenImage);
884    }
885
886    /** Enable tracing. */
887    final public void enable_tracing() {
888    }
889
890    /** Disable tracing. */
891    final public void disable_tracing() {
892    }
893
894    private void jj_rescan_token() {
895        jj_rescan = true;
896        for (int i = 0; i < 2; i++) {
897            try {
898                JJCalls p = jj_2_rtns[i];
899                do {
900                    if (p.gen > jj_gen) {
901                        jj_la = p.arg;
902                        jj_lastpos = jj_scanpos = p.first;
903                        switch (i) {
904                        case 0:
905                            jj_3_1();
906                            break;
907                        case 1:
908                            jj_3_2();
909                            break;
910                        }
911                    }
912                    p = p.next;
913                } while (p != null);
914            } catch (LookaheadSuccess ls) {
915            }
916        }
917        jj_rescan = false;
918    }
919
920    private void jj_save(int index, int xla) {
921        JJCalls p = jj_2_rtns[index];
922        while (p.gen > jj_gen) {
923            if (p.next == null) {
924                p = p.next = new JJCalls();
925                break;
926            }
927            p = p.next;
928        }
929        p.gen = jj_gen + xla - jj_la;
930        p.first = token;
931        p.arg = xla;
932    }
933
934    static final class JJCalls {
935        int gen;
936        Token first;
937        int arg;
938        JJCalls next;
939    }
940
941}