示例#1
0
 public void Convert()
 {
     while (index < tokens.Count)
     {
         if (TokenInitializer.IsNumber(Token))
         {
             result.Push(Token);
         }
         else if (TokenInitializer.IsOpenBracket(Token))
         {
             operators.Push(Token);
         }
         else if (TokenInitializer.IsOperator(Token))
         {
             PerformOperator();
         }
         else if (TokenInitializer.IsFunction(Token))
         {
             PerformFunction();
         }
         else if (TokenInitializer.IsCloseBracket(Token))
         {
             if (!PerformCloseBracket())
             {
                 throw new InvalidBracketEcxeption();
             }
         }
         else if (TokenInitializer.IsDelimeter(Token))
         {
             if (TokenInitializer.IsCorrectDelimeter(GetPrevNotSpace(), GetNextNotSpace()))
             {
                 PerformDelimeter();
             }
             else
             {
                 throw new DelimeterPositioningException();
             }
         }
         else if (TokenInitializer.IsSpace(Token))
         {
             index++;
             continue;
         }
         else
         {
             throw new InvalidTokenException(Token);
         }
         index++;
     }
     if (!IsExpressionParsed())
     {
         throw new InvalidBracketEcxeption();
     }
     ReverseResult();
 }
示例#2
0
        private bool IsUnary()
        {
            var maybeUnary        = Token == "-" || Token == "+";
            var isOpenBracketPrev = TokenInitializer.IsOpenBracket(GetPrevNotSpace());
            var isOpenBracketNext = TokenInitializer.IsOpenBracket(GetNextNotSpace());
            var isNumberNext      = TokenInitializer.IsNumber(GetNextNotSpace());
            var isFunctionNext    = TokenInitializer.IsFunction(GetNextNotSpace());
            var isDelimeterPrev   = TokenInitializer.IsDelimeter(GetPrevNotSpace());

            if (maybeUnary && (isOpenBracketPrev || isDelimeterPrev) && (isNumberNext || isFunctionNext || isOpenBracketNext))
            {
                return(true);
            }
            return(false);
        }