예제 #1
0
        /// <summary>
        /// Create a rule node, add to current tree, and make it current root
        /// </summary>
        /// <param name="s"></param>
        public override void traceIn(string s)                                  // throws TokenStreamException
        {
            if (inputState.guessing > 0)
            {
                return;
            }
            ParseTreeRule subRoot = new ParseTreeRule(s);

            if (currentParseTreeRoot.Count > 0)
            {
                ParseTreeRule oldRoot = (ParseTreeRule)currentParseTreeRoot.Peek();
                oldRoot.addChild(subRoot);
            }
            currentParseTreeRoot.Push(subRoot);
            numberOfDerivationSteps++;
        }
예제 #2
0
        /// <summary>
        /// Adds LT(1) to the current parse subtree.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Note that the match() routines add the node before checking for
        /// correct match.  This means that, upon mismatched token, there
        /// will a token node in the tree corresponding to where that token
        /// was expected.  For no viable alternative errors, no node will
        /// be in the tree as nothing was matched() (the lookahead failed
        /// to predict an alternative).
        /// </para>
        /// </remarks>
        protected void addCurrentTokenToParseTree()                     // throws TokenStreamException
        {
            if (inputState.guessing > 0)
            {
                return;
            }
            ParseTreeRule  root      = (ParseTreeRule)currentParseTreeRoot.Peek();
            ParseTreeToken tokenNode = null;

            if (LA(1) == Token.EOF_TYPE)
            {
                tokenNode = new ParseTreeToken(new antlr.CommonToken("EOF"));
            }
            else
            {
                tokenNode = new ParseTreeToken(LT(1));
            }
            root.addChild(tokenNode);
        }