Beispiel #1
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);
        }
Beispiel #2
0
 private static void term(NfaPair pair)
 {
     if (Tokens.OPEN_PAREN == MakeNfa.spec.current_token)
     {
         MakeNfa.gen.Advance();
         MakeNfa.expr(pair);
         if (Tokens.CLOSE_PAREN == MakeNfa.spec.current_token)
         {
             MakeNfa.gen.Advance();
             return;
         }
         Error.ParseError(Errors.SYNTAX, MakeNfa.gen.InputFilePath, MakeNfa.input.line_number);
         return;
     }
     else
     {
         Nfa nfa = Alloc.NewNfa(MakeNfa.spec);
         pair.start = nfa;
         nfa.Next   = Alloc.NewNfa(MakeNfa.spec);
         pair.end   = nfa.Next;
         bool flag = MakeNfa.spec.current_token == Tokens.LETTER && char.IsLetter(MakeNfa.spec.current_token_value);
         if (MakeNfa.spec.current_token != Tokens.ANY && MakeNfa.spec.current_token != Tokens.CCL_START && (!MakeNfa.spec.IgnoreCase || !flag))
         {
             nfa.Edge = MakeNfa.spec.current_token_value;
             MakeNfa.gen.Advance();
             return;
         }
         nfa.Edge = '￾';
         nfa.SetCharSet(new CharSet());
         CharSet charSet = nfa.GetCharSet();
         if (MakeNfa.spec.IgnoreCase && flag)
         {
             charSet.addncase(MakeNfa.spec.current_token_value);
         }
         else
         {
             if (MakeNfa.spec.current_token == Tokens.ANY)
             {
                 charSet.add(10);
                 charSet.add(13);
                 charSet.add((int)MakeNfa.spec.BOL);
                 charSet.add((int)MakeNfa.spec.EOF);
                 charSet.complement();
             }
             else
             {
                 MakeNfa.gen.Advance();
                 if (MakeNfa.spec.current_token == Tokens.CHAR_CLASS)
                 {
                     MakeNfa.gen.Advance();
                     if (!charSet.AddClass(MakeNfa.spec.class_name.ToLower()))
                     {
                         Error.ParseError(Errors.InvalidCharClass, MakeNfa.gen.InputFilePath, MakeNfa.input.line_number);
                     }
                 }
                 else
                 {
                     if (MakeNfa.spec.current_token == Tokens.AT_BOL)
                     {
                         MakeNfa.gen.Advance();
                         charSet.add((int)MakeNfa.spec.BOL);
                         charSet.add((int)MakeNfa.spec.EOF);
                         charSet.complement();
                     }
                 }
                 if (MakeNfa.spec.current_token != Tokens.CCL_END)
                 {
                     MakeNfa.dodash(charSet);
                 }
             }
         }
         MakeNfa.gen.Advance();
         return;
     }
 }