Ejemplo n.º 1
0
 /** Reinitialise. */
 public void ReInit(astParserTokenManager tm)
 {
     token_source = tm;
     token = new AstToken();
     jj_ntk = AstRegExpId.UNDEFINED;
     jj_gen = 0;
     for (int i = 0; i < 14; i++)
         jj_la1[i] = -1;
 }
Ejemplo n.º 2
0
 /** Constructor with generated Token Manager. */
 public astParser(astParserTokenManager 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 AstToken();
     jj_ntk = AstRegExpId.UNDEFINED;
     jj_gen = 0;
     for (int i = 0; i < 14; i++)
         jj_la1[i] = -1;
 }
Ejemplo n.º 3
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 AstToken();
     jj_ntk = AstRegExpId.UNDEFINED;
     jj_gen = 0;
     for (int i = 0; i < 14; i++) jj_la1[i] = -1;
 }
Ejemplo n.º 4
0
 private static AstRegExpId jj_ntk_fn()
 {
     if ((jj_nt=token.next) == null)
         return (jj_ntk = (token.next = AstParserTokenManager.getNextToken()).kind);
     else
         return (jj_ntk = jj_nt.kind);
 }
Ejemplo n.º 5
0
        /** Constructor with InputStream and supplied encoding */
        public AstParser(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 AstParserTokenManager(jj_input_stream);
            }

            token = new AstToken();
            jj_ntk = AstRegExpId.UNDEFINED;
            jj_gen = 0;

            for (int i = 0; i < 14; i++)
                jj_la1[i] = -1;
        }
Ejemplo n.º 6
0
        /* throws ParseException */
        private static AstToken jj_consume_token(AstParserConstants.AstRegExpId kind)
        {
            AstToken oldToken;
            if ((oldToken = token).next != null)
                token = token.next;
            else
                token = token.next = AstParserTokenManager.getNextToken();
            jj_ntk = AstRegExpId.UNDEFINED;

            if (token.kind == kind)
            {
                jj_gen++;
                return token;
            }
            token = oldToken;
            jj_kind = kind;
            throw generateParseException();
        }
Ejemplo n.º 7
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);
     }
     AstParserTokenManager.ReInit(jj_input_stream);
     token = new AstToken();
     jj_ntk = AstRegExpId.UNDEFINED;
     jj_gen = 0;
     for (int i = 0; i < 14; i++) jj_la1[i] = -1;
 }
Ejemplo n.º 8
0
 /** Get the next Token. */
 /* final */
 public static AstToken getNextToken()
 {
     if (token.next != null)
         token = token.next;
     else
         token = token.next = AstParserTokenManager.getNextToken();
     jj_ntk = AstRegExpId.UNDEFINED;
     jj_gen++;
     return token;
 }
Ejemplo n.º 9
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(AstToken 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 \"";
            AstToken tok = currentToken.next;

            for (int i = 0; i < maxSize; i++)
            {
                if (i != 0) retval += " ";
                if (tok.kind == 0)
                {
                    retval += tokenImage[0];
                    break;
                }
                retval += " " + AstParserConstants.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;
        }
Ejemplo n.º 10
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 AstParseException(AstToken currentTokenVal,
     int[][] expectedTokenSequencesVal,
     string[] tokenImageVal)
     : base(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal))
 {
     currentToken = currentTokenVal;
     expectedTokenSequences = expectedTokenSequencesVal;
     tokenImage = tokenImageVal;
 }