示例#1
0
文件: MakeNfa.cs 项目: maxild/CsLex
        /*
         * Function: cat_expr
         * Description: Recursive descent regular expression parser.
         */
        private static void cat_expr(NfaPair pair)
        {
            NfaPair e2_pair;

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

#if DEBUG
            Utility.assert(null != pair);
#endif

            e2_pair = Alloc.NewNfaPair();

            if (first_in_cat(spec.current_token))
            {
                factor(pair);
            }

            while (first_in_cat(spec.current_token))
            {
                factor(e2_pair);

                /* Destroy */
                pair.end.mimic(e2_pair.start);
                discardNfa(e2_pair.start);

                pair.end = e2_pair.end;
            }

#if DESCENT_DEBUG
            Utility.leave("cat_expr", spec.lexeme, spec.current_token);
#endif
        }
示例#2
0
文件: MakeNfa.cs 项目: maxild/CsLex
        /*
         * Function: expr
         * Description: Recursive descent regular expression parser.
         */
        private static void expr(NfaPair pair)
        {
            NfaPair e2_pair;
            Nfa     p;

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

#if DEBUG
            Utility.assert(null != pair);
#endif

            e2_pair = Alloc.NewNfaPair();

            cat_expr(pair);

            while (Gen.OR == spec.current_token)
            {
                gen.Advance();
                cat_expr(e2_pair);

                p = Alloc.NewNfa(spec);
                p.SetSib(e2_pair.start);
                p.SetNext(pair.start);
                pair.start = p;

                p = Alloc.NewNfa(spec);
                pair.end.SetNext(p);
                e2_pair.end.SetNext(p);
                pair.end = p;
            }

#if DESCENT_DEBUG
            Utility.leave("expr", spec.lexeme, spec.current_token);
#endif
        }
示例#3
0
文件: MakeNfa.cs 项目: maxild/CsLex
        /*
         * 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);
        }