Exemplo n.º 1
0
/*
 * Function: factor
 * Description: Recursive descent regular expression parser.
 */
        private static void factor(NfaPair pair)
        {
            Nfa start = null;
            Nfa end   = null;

#if DESCENT_DEBUG
            Utility.enter("factor", spec.lexeme, spec.current_token);
#endif

            term(pair);

            if (Gen.CLOSURE == spec.current_token ||
                Gen.PLUS_CLOSE == spec.current_token ||
                Gen.OPTIONAL == spec.current_token)
            {
                start = Alloc.NewNfa(spec);
                end   = Alloc.NewNfa(spec);

                start.SetNext(pair.start);
                pair.end.SetNext(end);

                if (Gen.CLOSURE == spec.current_token ||
                    Gen.OPTIONAL == spec.current_token)
                {
                    start.SetSib(end);
                }

                if (Gen.CLOSURE == spec.current_token ||
                    Gen.PLUS_CLOSE == spec.current_token)
                {
                    pair.end.SetSib(pair.start);
                }

                pair.start = start;
                pair.end   = end;
                gen.Advance();
            }

#if DESCENT_DEBUG
            Utility.leave("factor", spec.lexeme, spec.current_token);
#endif
        }
Exemplo n.º 2
0
/*
 * Function: rule
 * Description: Recursive descent regular expression parser.
 */
        private static Nfa rule()
        {
            NfaPair pair;
            Nfa     start  = null;
            Nfa     end    = null;
            int     anchor = Spec.NONE;

#if DESCENT_DEBUG
            Utility.enter("rule", spec.lexeme, spec.current_token);
#endif

            pair = Alloc.NewNfaPair();

            if (Gen.AT_BOL == spec.current_token)
            {
                anchor = anchor | Spec.START;
                gen.Advance();
                expr(pair);

                start = Alloc.NewNfa(spec);
                start.SetEdge(spec.BOL);
                start.SetNext(pair.start);
                end = pair.end;
            }
            else
            {
                expr(pair);
                start = pair.start;
                end   = pair.end;
            }

            if (Gen.AT_EOL == spec.current_token)
            {
                gen.Advance();

                NfaPair nlpair = Alloc.NewNLPair(spec);
                end.SetNext(Alloc.NewNfa(spec));
                Nfa enext = end.GetNext();
                enext.SetNext(nlpair.start);
                enext.SetSib(Alloc.NewNfa(spec));
                enext.GetSib().SetEdge(spec.EOF);
                enext.GetSib().SetNext(nlpair.end);
                end = nlpair.end;

                anchor = anchor | Spec.END;
            }

            /* check for null rules */
            if (end == null)
            {
                Error.parse_error(Error.E_ZERO, input.line_number);
            }

            /* Handle end of regular expression */
            end.SetAccept(gen.packAccept());
            end.SetAnchor(anchor);

#if DESCENT_DEBUG
            Utility.leave("rule", spec.lexeme, spec.current_token);
#endif
            return(start);
        }