Exemplo n.º 1
0
        /**
        * It uses "currentToken" and "expectedTokenSequences" to generate a parse
        * error message and returns it.  If this object has been created
        * due to a parse error, and you do not catch it (it gets thrown
        * from the parser) the correct error message
        * gets displayed.
        */
        private static string initialise(MiniToken currentToken,
            int[][] expectedTokenSequences,
            string[] tokenImage)
        {
            string eol = Environment.NewLine;
            StringBuilder expected = new StringBuilder();
            int maxSize = 0;

            for (int i = 0; i < expectedTokenSequences.Length; i++)
            {
                if (maxSize < expectedTokenSequences[i].Length)
                {
                    maxSize = expectedTokenSequences[i].Length;
                }
                for (int j = 0; j < expectedTokenSequences[i].Length; j++)
                {
                    expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(' ');
                }
                if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
                {
                    expected.Append("...");
                }
                expected.Append(eol).Append("    ");
            }

            string retval = "Encountered \"";
            MiniToken tok = currentToken.next;
            for (int i = 0; i < maxSize; i++)
            {
                if (i != 0) retval += " ";
                if (tok.kind == 0)
                {
                    retval += tokenImage[0];
                    break;
                }
                retval += " " + tokenImage[(int)tok.kind];
                retval += " \"";
                retval += add_escapes(tok.image);
                retval += " \"";
                tok = tok.next;
            }
            retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
            retval += "." + eol;
            if (expectedTokenSequences.Length == 1)
            {
                retval += "Was expecting:" + eol + "    ";
            }
            else
            {
                retval += "Was expecting one of:" + eol + "    ";
            }
            retval += expected.ToString();
            return retval;
        }
Exemplo n.º 2
0
 /** Reinitialise. */
 public void ReInit(miniParserTokenManager tm)
 {
     token_source = tm;
     token = new PsrToken();
     jj_ntk = -1;
     jj_gen = 0;
     for (int i = 0; i < 45; i++) jj_la1[i] = -1;
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
 }
Exemplo n.º 3
0
 /**
  * This constructor is used by the method "generateParseException"
  * in the generated parser.  Calling this constructor generates
  * a new object of this type with the fields "currentToken",
  * "expectedTokenSequences", and "tokenImage" set.
  */
 public MiniParseException(MiniToken currentTokenVal, int[][] expectedTokenSequencesVal, string[] tokenImageVal)
     : base(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal))
 {
     currentToken = currentTokenVal;
     expectedTokenSequences = expectedTokenSequencesVal;
     tokenImage = tokenImageVal;
 }
Exemplo n.º 4
0
 /** Constructor with generated Token Manager. */
 public miniParser(miniParserTokenManager tm)
 {
     if (jj_initialized_once) {
     System.out.println("ERROR: Second call to constructor of static parser. ");
     System.out.println("       You must either use ReInit() or set the JavaCC option STATIC to false");
     System.out.println("       during parser generation.");
     throw new Error();
     }
     jj_initialized_once = true;
     token_source = tm;
     token = new PsrToken();
     jj_ntk = -1;
     jj_gen = 0;
     for (int i = 0; i < 45; i++) jj_la1[i] = -1;
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
 }
Exemplo n.º 5
0
 /** Reinitialise. */
 public static void ReInit(java.io.Reader stream)
 {
     jj_input_stream.ReInit(stream, 1, 1);
     token_source.ReInit(jj_input_stream);
     token = new PsrToken();
     jj_ntk = -1;
     jj_gen = 0;
     for (int i = 0; i < 45; i++) jj_la1[i] = -1;
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
 }
Exemplo n.º 6
0
 private static bool jj_scan_token(MpRegExpId kind)
 {
     if (jj_scanpos == jj_lastpos)
     {
         jj_la--;
         if (jj_scanpos.next == null)
         {
             jj_lastpos = jj_scanpos = jj_scanpos.next = MiniParserTokenManager.getNextToken();
         }
         else
         {
             jj_lastpos = jj_scanpos = jj_scanpos.next;
         }
     }
     else
     {
         jj_scanpos = jj_scanpos.next;
     }
     if (jj_rescan)
     {
         int i = 0; MiniToken tok = token;
         while (tok != null && tok != jj_scanpos)
         {
             i++; tok = tok.next;
         }
         if (tok != null)
             jj_add_error_token(kind, i);
     }
     if (jj_scanpos.kind != kind) return true;
     if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
     return false;
 }
Exemplo n.º 7
0
 /** Constructor. */
 public miniParser(java.io.Reader stream)
 {
     if (jj_initialized_once)
     {
         // System.out.println("ERROR: Second call to constructor of static parser. ");
         // System.out.println("       You must either use ReInit() or set the JavaCC option STATIC to false");
         // System.out.println("       during parser generation.");
         // throw new Error();
     }
     jj_initialized_once = true;
     jj_input_stream = new SimpleCharStream(stream, 1, 1);
     token_source = new miniParserTokenManager(jj_input_stream);
     token = new PsrToken();
     jj_ntk = -1;
     jj_gen = 0;
     for (int i = 0; i < 45; i++) jj_la1[i] = -1;
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
 }
Exemplo n.º 8
0
 private static MpRegExpId jj_ntk_fn()
 {
     if ((jj_nt = token.next) == null)
         return (jj_ntk = (token.next = MiniParserTokenManager.getNextToken()).kind);
     else
         return (jj_ntk = jj_nt.kind);
 }
Exemplo n.º 9
0
 private static void jj_rescan_token()
 {
     jj_rescan = true;
     for (int i = 0; i < 3; i++)
     {
         try
         {
             JJCalls p = jj_2_rtns[i];
             do
             {
                 if (p.gen > jj_gen)
                 {
                     jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
                     switch (i)
                     {
                         case 0: jj_3_1(); break;
                         case 1: jj_3_2(); break;
                         case 2: jj_3_3(); break;
                     }
             }
             p = p.next;
             } while (p != null);
         }
         catch(LookaheadSuccess ls)
         {
         }
     }
     jj_rescan = false;
 }
Exemplo n.º 10
0
 private static bool jj_3R_20()
 {
     MiniToken xsp;
     xsp = jj_scanpos;
     if (jj_3R_22()) {
     jj_scanpos = xsp;
     if (jj_3R_23()) return true;
     }
     return false;
 }
Exemplo n.º 11
0
        /* throws ParseException */
        private static MiniToken jj_consume_token(MpRegExpId kind)
        {
            MiniToken oldToken;

            if ((oldToken = token).next != null)
                token = token.next;
            else
                token = token.next = MiniParserTokenManager.getNextToken();

            jj_ntk = MpRegExpId.UNDEFINED;

            if (token.kind == kind)
            {
                jj_gen++;
                if (++jj_gc > 100)
                {
                    jj_gc = 0;
                    for (int i = 0; i < jj_2_rtns.Length; i++)
                    {
                        JJCalls c = jj_2_rtns[i];
                        while (c != null)
                        {
                            if (c.gen < jj_gen) c.first = null;
                            c = c.next;
                        }
                    }
                }
                return token;
            }
            token = oldToken;
            jj_kind = kind;
            throw generateParseException();
        }
Exemplo n.º 12
0
 private static bool jj_3R_18()
 {
     if (jj_3R_20()) return true;
     MiniToken xsp;
     xsp = jj_scanpos;
     if (jj_3R_21()) jj_scanpos = xsp;
     return false;
 }
Exemplo n.º 13
0
 private static bool jj_2_3(int xla)
 {
     jj_la = xla; jj_lastpos = jj_scanpos = token;
     try { return !jj_3_3(); }
     catch(LookaheadSuccess ls) { return true; }
     finally { jj_save(2, xla); }
 }
Exemplo n.º 14
0
        /** Reinitialise. */
        public static void ReInit(Stream stream, Encoding encoding)
        {
            try
            {
                jj_input_stream.ReInit(stream, encoding, 1, 1);
            }
            catch(UnsupportedEncodingException e)
            {
                throw new RuntimeException(e);
            }

            MiniParserTokenManager.ReInit(jj_input_stream);
            token = new MiniToken();
            jj_ntk = MpRegExpId.UNDEFINED;
            jj_gen = 0;
            for (int i = 0; i < 45; i++) jj_la1[i] = -1;
            for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
        }
Exemplo n.º 15
0
        /** Constructor with InputStream and supplied encoding */
        public MiniParser(Stream stream, Encoding encoding)
        {
            if (jj_initialized_once)
            {
                ReInit(stream, encoding);
                // System.out.println("ERROR: Second call to constructor of static parser.  ");
                // System.out.println("       You must either use ReInit() or set the JavaCC option STATIC to false");
                // System.out.println("       during parser generation.");
                // throw new Error();
            }
            else
            {
                jj_initialized_once = true;

                try
                {
                    jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1);
                }
                catch (UnsupportedEncodingException e)
                {
                    throw new RuntimeException(e);
                }
                token_source = new MiniParserTokenManager(jj_input_stream);
            }

            token = new MiniToken();
            jj_ntk = MpRegExpId.UNDEFINED;
            jj_gen = 0;
            for (int i = 0; i < 45; i++) jj_la1[i] = -1;
            for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
        }
Exemplo n.º 16
0
 /** Get the next Token. */
 /* final */
 public static MiniToken getNextToken()
 {
     if (token.next != null)
         token = token.next;
     else
         token = token.next = MiniParserTokenManager.getNextToken();
     jj_ntk = MpRegExpId.UNDEFINED;
     jj_gen++;
     return token;
 }