Example #1
0
        /***************************************************************
         *    Function: expr
         *    Description: Recursive descent regular expression parser.
         **************************************************************/
        private void expr
        (
            CNfaPair pair
        )
        {
            CNfaPair e2_pair;
            CNfa     p;

      #if (DESCENT_DEBUG)
            {
                CUtility.enter("expr", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif

      #if (DEBUG)
            {
                CUtility.ASSERT(null != pair);
            }
      #endif

            e2_pair = CAlloc.newCNfaPair();

            cat_expr(pair);

            while (CLexGen.OR == m_spec.m_current_token)
            {
                m_lexGen.advance();
                cat_expr(e2_pair);

                p            = CAlloc.newCNfa(m_spec);
                p.m_next2    = e2_pair.m_start;
                p.m_next     = pair.m_start;
                pair.m_start = p;

                p = CAlloc.newCNfa(m_spec);
                pair.m_end.m_next    = p;
                e2_pair.m_end.m_next = p;
                pair.m_end           = p;
            }

      #if (DESCENT_DEBUG)
            {
                CUtility.leave("expr", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif
        }
Example #2
0
        /***************************************************************
         *    Function: cat_expr
         *    Description: Recursive descent regular expression parser.
         **************************************************************/
        private void cat_expr
        (
            CNfaPair pair
        )
        {
            CNfaPair e2_pair;

      #if (DESCENT_DEBUG)
            {
                CUtility.enter("cat_expr", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif

      #if (DEBUG)
            {
                CUtility.ASSERT(null != pair);
            }
      #endif

            e2_pair = CAlloc.newCNfaPair();

            if (first_in_cat(m_spec.m_current_token))
            {
                factor(pair);
            }

            while (first_in_cat(m_spec.m_current_token))
            {
                factor(e2_pair);

                /* Destroy */
                pair.m_end.mimic(e2_pair.m_start);
                discardCNfa(e2_pair.m_start);

                pair.m_end = e2_pair.m_end;
            }

      #if (DESCENT_DEBUG)
            {
                CUtility.leave("cat_expr", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif
        }
Example #3
0
        /***************************************************************
         *    Function: rule
         *    Description: Recursive descent regular expression parser.
         **************************************************************/
        private CNfa rule
        (
        )
        {
            CNfaPair pair;
            //CNfa p;
            CNfa start  = null;
            CNfa end    = null;
            int  anchor = CSpec.NONE;

      #if (DESCENT_DEBUG)
            {
                CUtility.enter("rule", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif

            pair = CAlloc.newCNfaPair();

            if (CLexGen.AT_BOL == m_spec.m_current_token)
            {
                anchor = anchor | CSpec.START;
                m_lexGen.advance();
                expr(pair);

                // CSA: fixed beginning-of-line operator. 8-aug-1999
                start        = CAlloc.newCNfa(m_spec);
                start.m_edge = m_spec.BOL;
                start.m_next = pair.m_start;
                end          = pair.m_end;
            }
            else
            {
                expr(pair);
                start = pair.m_start;
                end   = pair.m_end;
            }

            if (CLexGen.AT_EOL == m_spec.m_current_token)
            {
                m_lexGen.advance();
                // CSA: fixed end-of-line operator. 8-aug-1999
                CNfaPair nlpair = CAlloc.newNLPair(m_spec);
                end.m_next                = CAlloc.newCNfa(m_spec);
                end.m_next.m_next         = nlpair.m_start;
                end.m_next.m_next2        = CAlloc.newCNfa(m_spec);
                end.m_next.m_next2.m_edge = m_spec.EOF;
                end.m_next.m_next2.m_next = nlpair.m_end;
                end    = nlpair.m_end;
                anchor = anchor | CSpec.END;
            }

            /* Check for null rules. Charles Fischer found this bug. [CSA] */
            if (end == null)
            {
                CError.parse_error(CError.E_ZERO, m_input.m_line_number);
            }

            /* Handle end of regular expression.  See page 103. */
            end.m_accept = m_lexGen.packAccept();
            end.m_anchor = anchor;

            /* Begin: Removed for states. */
            /*m_lexGen.advance();*/
            /* End: Removed for states. */

      #if (DESCENT_DEBUG)
            {
                CUtility.leave("rule", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif

            return(start);
        }