Exemplo n.º 1
0
        public static NfaPair NewNLPair(Spec spec)
        {
            NfaPair nfaPair = Alloc.NewNfaPair();

            nfaPair.end   = Alloc.NewNfa(spec);
            nfaPair.start = Alloc.NewNfa(spec);
            Nfa start = nfaPair.start;

            start.Next = Alloc.NewNfa(spec);
            Nfa next = start.Next;

            next.Edge = '￾';
            next.SetCharSet(new CharSet());
            next.GetCharSet().add(10);
            next.Next     = nfaPair.end;
            start.Sibling = Alloc.NewNfa(spec);
            Nfa sibling = start.Sibling;

            sibling.Edge = '\r';
            sibling.Next = Alloc.NewNfa(spec);
            Nfa next2 = sibling.Next;

            next2.Next         = null;
            next2.Sibling      = Alloc.NewNfa(spec);
            next2.Sibling.Edge = '\n';
            next2.Sibling.Next = nfaPair.end;
            return(nfaPair);
        }
Exemplo n.º 2
0
/*
 * 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
        }
Exemplo n.º 3
0
        private static void cat_expr(NfaPair pair)
        {
            NfaPair nfaPair = Alloc.NewNfaPair();

            if (MakeNfa.first_in_cat(MakeNfa.spec.current_token))
            {
                MakeNfa.factor(pair);
            }
            while (MakeNfa.first_in_cat(MakeNfa.spec.current_token))
            {
                MakeNfa.factor(nfaPair);
                pair.end.mimic(nfaPair.start);
                MakeNfa.discardNfa(nfaPair.start);
                pair.end = nfaPair.end;
            }
        }
Exemplo n.º 4
0
        private static Nfa rule()
        {
            int     num     = 0;
            NfaPair nfaPair = Alloc.NewNfaPair();
            Nfa     nfa;
            Nfa     end;

            if (MakeNfa.spec.current_token == Tokens.AT_BOL)
            {
                num |= 1;
                MakeNfa.gen.Advance();
                MakeNfa.expr(nfaPair);
                nfa      = Alloc.NewNfa(MakeNfa.spec);
                nfa.Edge = MakeNfa.spec.BOL;
                nfa.Next = nfaPair.start;
                end      = nfaPair.end;
            }
            else
            {
                MakeNfa.expr(nfaPair);
                nfa = nfaPair.start;
                end = nfaPair.end;
            }
            if (Tokens.AT_EOL == MakeNfa.spec.current_token)
            {
                MakeNfa.gen.Advance();
                NfaPair nfaPair2 = Alloc.NewNLPair(MakeNfa.spec);
                end.Next = Alloc.NewNfa(MakeNfa.spec);
                Nfa next = end.Next;
                next.Next         = nfaPair2.start;
                next.Sibling      = Alloc.NewNfa(MakeNfa.spec);
                next.Sibling.Edge = MakeNfa.spec.EOF;
                next.Sibling.Next = nfaPair2.end;
                end  = nfaPair2.end;
                num |= 2;
            }
            if (end == null)
            {
                Error.ParseError(Errors.ZERO, MakeNfa.gen.InputFilePath, MakeNfa.input.line_number);
            }
            end.SetAccept(MakeNfa.gen.packAccept());
            end.SetAnchor(num);
            return(nfa);
        }
Exemplo n.º 5
0
        private static void expr(NfaPair pair)
        {
            NfaPair nfaPair = Alloc.NewNfaPair();

            MakeNfa.cat_expr(pair);
            while (Tokens.OR == MakeNfa.spec.current_token)
            {
                MakeNfa.gen.Advance();
                MakeNfa.cat_expr(nfaPair);
                Nfa nfa = Alloc.NewNfa(MakeNfa.spec);
                nfa.Sibling      = nfaPair.start;
                nfa.Next         = pair.start;
                pair.start       = nfa;
                nfa              = Alloc.NewNfa(MakeNfa.spec);
                pair.end.Next    = nfa;
                nfaPair.end.Next = nfa;
                pair.end         = nfa;
            }
        }
Exemplo n.º 6
0
/*
 * 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
        }
Exemplo n.º 7
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);
        }