Ejemplo n.º 1
0
/*
 * Function: dodash
 * Description: Recursive descent regular expression parser.
 */
        private static void dodash(CharSet set)
        {
            int first = -1;

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

            while (Gen.EOS != spec.current_token &&
                   Gen.CCL_END != spec.current_token)
            {
                // DASH loses its special meaning if it is first in class.
                if (Gen.DASH == spec.current_token && -1 != first)
                {
                    gen.Advance();
                    // DASH loses its special meaning if it is last in class.
                    if (spec.current_token == Gen.CCL_END)
                    {
                        // 'first' already in set.
                        set.add('-');
                        break;
                    }
                    for ( ; first <= spec.lexeme; ++first)
                    {
                        if (spec.ignorecase)
                        {
                            set.addncase((char)first);
                        }
                        else
                        {
                            set.add(first);
                        }
                    }
                }
                else
                {
                    first = spec.lexeme;
                    if (spec.ignorecase)
                    {
                        set.addncase(spec.lexeme);
                    }
                    else
                    {
                        set.add(spec.lexeme);
                    }
                }

                gen.Advance();
            }

#if DESCENT_DEBUG
            Utility.leave("dodash", spec.lexeme, spec.current_token);
#endif
        }
Ejemplo n.º 2
0
        private static void dodash(CharSet set)
        {
            int i = -1;

            while (Tokens.EOS != MakeNfa.spec.current_token && Tokens.CCL_END != MakeNfa.spec.current_token)
            {
                if (Tokens.DASH == MakeNfa.spec.current_token && -1 != i)
                {
                    MakeNfa.gen.Advance();
                    if (MakeNfa.spec.current_token == Tokens.CCL_END)
                    {
                        set.add(45);
                        return;
                    }
                    while (i <= (int)MakeNfa.spec.current_token_value)
                    {
                        if (MakeNfa.spec.IgnoreCase)
                        {
                            set.addncase((char)i);
                        }
                        else
                        {
                            set.add(i);
                        }
                        i++;
                    }
                }
                else
                {
                    i = (int)MakeNfa.spec.current_token_value;
                    if (MakeNfa.spec.IgnoreCase)
                    {
                        set.addncase(MakeNfa.spec.current_token_value);
                    }
                    else
                    {
                        set.add((int)MakeNfa.spec.current_token_value);
                    }
                }
                MakeNfa.gen.Advance();
            }
        }
Ejemplo n.º 3
0
/*
 * Function: term
 * Description: Recursive descent regular expression parser.
 */
        private static void term(NfaPair pair)
        {
            Nfa  start;
            bool isAlphaL;

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

            if (Gen.OPEN_PAREN == spec.current_token)
            {
                gen.Advance();
                expr(pair);

                if (Gen.CLOSE_PAREN == spec.current_token)
                {
                    gen.Advance();
                }
                else
                {
                    Error.parse_error(Error.E_SYNTAX, input.line_number);
                }
            }
            else
            {
                start      = Alloc.NewNfa(spec);
                pair.start = start;

                start.SetNext(Alloc.NewNfa(spec));
                pair.end = start.GetNext();

                if (Gen.L == spec.current_token && Char.IsLetter(spec.lexeme))
                {
                    isAlphaL = true;
                }
                else
                {
                    isAlphaL = false;
                }
                if (false == (Gen.ANY == spec.current_token ||
                              Gen.CCL_START == spec.current_token ||
                              (spec.ignorecase && isAlphaL)))
                {
                    start.SetEdge(spec.lexeme);
                    gen.Advance();
                }
                else
                {
                    start.SetEdge(Nfa.CCL);
                    start.SetCharSet(new CharSet());
                    CharSet cset = start.GetCharSet();

                    /* Match case-insensitive letters using character class. */
                    if (spec.ignorecase && isAlphaL)
                    {
                        cset.addncase(spec.lexeme);
                    }
                    /* Match dot (.) using character class. */
                    else if (Gen.ANY == spec.current_token)
                    {
                        cset.add('\n');
                        cset.add('\r');
                        /* exclude BOL and EOF from character classes */
                        cset.add(spec.BOL);
                        cset.add(spec.EOF);
                        cset.complement();
                    }
                    else
                    {
                        gen.Advance();
                        if (Gen.AT_BOL == spec.current_token)
                        {
                            gen.Advance();
                            /* exclude BOL and EOF from character classes */
                            cset.add(spec.BOL);
                            cset.add(spec.EOF);
                            cset.complement();
                        }
                        if (!(Gen.CCL_END == spec.current_token))
                        {
                            dodash(cset);
                        }
                    }
                    gen.Advance();
                }
            }

#if DESCENT_DEBUG
            Utility.leave("term", spec.lexeme, spec.current_token);
#endif
        }
Ejemplo n.º 4
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;
     }
 }
Ejemplo n.º 5
0
		private static void dodash(CharSet set)
		{
			int i = -1;
			while (Tokens.EOS != MakeNfa.spec.current_token && Tokens.CCL_END != MakeNfa.spec.current_token)
			{
				if (Tokens.DASH == MakeNfa.spec.current_token && -1 != i)
				{
					MakeNfa.gen.Advance();
					if (MakeNfa.spec.current_token == Tokens.CCL_END)
					{
						set.add(45);
						return;
					}
					while (i <= (int)MakeNfa.spec.current_token_value)
					{
						if (MakeNfa.spec.IgnoreCase)
						{
							set.addncase((char)i);
						}
						else
						{
							set.add(i);
						}
						i++;
					}
				}
				else
				{
					i = (int)MakeNfa.spec.current_token_value;
					if (MakeNfa.spec.IgnoreCase)
					{
						set.addncase(MakeNfa.spec.current_token_value);
					}
					else
					{
						set.add((int)MakeNfa.spec.current_token_value);
					}
				}
				MakeNfa.gen.Advance();
			}
		}