Ejemplo n.º 1
0
        public override EpsilonNfa Apply(PositiveExpression expression, Automaton param)
        {
            var nfa  = new EpsilonNfa(param);
            var body = Invoke(expression.Matched, param);

            param.AddTransition(nfa.Start, body.Start, Transition.Type.Positive);
            param.AddTransition(body.End, nfa.End, Transition.Type.End);
            return(nfa);
        }
Ejemplo n.º 2
0
 Expression ParseFunction()
 {
     if (_sourceWindow.AdvanceIfMatches("(="))
     {
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new PositiveExpression(sub);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(!"))
     {
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new NegativeExpression(sub);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(<&"))
     {
         //表达式引用
         string name;
         if (!_sourceWindow.AdvanceIfName(out name))
         {
             throw new ArgumentException("invalid name.");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost.");
         }
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost.");
         }
         var exp = new ReferenceExpression(name);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(<$"))
     {
         string name;
         int    index = -1;
         if (_sourceWindow.AdvanceIfName(out name))
         {
             if (_sourceWindow.AdvanceIfMatches(';'))
             {
                 if (!_sourceWindow.AdvanceIfPositiveInteger(out index))
                 {
                     throw new ArgumentException("Positive numbers required after ;");
                 }
             }
         }
         else if (!_sourceWindow.AdvanceIfPositiveInteger(out index))
         {
             throw new ArgumentException("Positive numbers required after (<$");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost.");
         }
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost.");
         }
         var exp = new MatchExpression(name, index);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(<"))
     {
         string name;
         if (!_sourceWindow.AdvanceIfName(out name))
         {
             throw new ArgumentException("Name lost");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost");
         }
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new CaptureExpression(name, sub);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(?"))
     {
         var sub = ParseExpression();
         if (_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new CaptureExpression(sub);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches('('))//subexpression
     {
         var exp = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         return(exp);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
 public override Expression Apply(PositiveExpression expression, MergeParameter param)
 {
     return(new PositiveExpression(
                Invoke(expression, param)));
 }
Ejemplo n.º 4
0
 public bool Equals(PositiveExpression obj)
 {
     return(Matched.Equals(obj.Matched));
 }
Ejemplo n.º 5
0
 public void Visit(PositiveExpression expression)
 {
     _returnValue = this.Apply(expression, _paramValue);
 }
Ejemplo n.º 6
0
 public abstract ReturnT Apply(PositiveExpression expression, ParamT param);
Ejemplo n.º 7
0
 Expression ParseFunction()
 {
     if (_sourceWindow.AdvanceIfMatches("(="))
     {
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new PositiveExpression(sub);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(!"))
     {
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new NegativeExpression(sub);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(<&"))
     {
         //表达式引用
         string name;
         if (!_sourceWindow.AdvanceIfName(out name))
         {
             throw new ArgumentException("invalid name.");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost.");
         }
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost.");
         }
         var exp = new ReferenceExpression(name);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(<$"))
     {
         string name;
         int index = -1;
         if (_sourceWindow.AdvanceIfName(out name))
         {
             if (_sourceWindow.AdvanceIfMatches(';'))
             {
                 if (!_sourceWindow.AdvanceIfPositiveInteger(out index))
                 {
                     throw new ArgumentException("Positive numbers required after ;");
                 }
             }
         }
         else if (!_sourceWindow.AdvanceIfPositiveInteger(out index))
         {
             throw new ArgumentException("Positive numbers required after (<$");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost.");
         }
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost.");
         }
         var exp = new MatchExpression(name, index);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(<"))
     {
         string name;
         if (!_sourceWindow.AdvanceIfName(out name))
         {
             throw new ArgumentException("Name lost");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost");
         }
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new CaptureExpression(name, sub);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(?"))
     {
         var sub = ParseExpression();
         if (_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new CaptureExpression(sub);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches('('))//subexpression
     {
         var exp = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         return exp;
     }
     else return null;
 }
Ejemplo n.º 8
0
 public bool Equals(PositiveExpression obj)
 {
     return Matched.Equals(obj.Matched);
 }