예제 #1
0
 public CalExpression(string Expression)
 {
     MyWords   = new WordAnalyse(Expression);
     bResult   = false;
     nResult   = 0;
     dResult   = 0;
     ValueType = -1;
 }
예제 #2
0
 protected void E(WordAnalyse pWords)
 {
     if (pWords.GetWord(WordIndex).CompareTo('(') == 0)
     {
         WordIndex++;
         RoundBracketsi = RoundBracketsR + 1;
         RoundBracketsR++;
         //                ValutStack.Push(RoundBracketsi);
         //if (ValutStack.Get(ref itemp))
         //MessageBox.Show(itemp+"");
         ValutStack.Push(RoundBracketsi);
         //if (ValutStack.Get(ref itemp))
         //MessageBox.Show(itemp+"","2");
         E(pWords);
         //               RoundBracketsi=ValutStack.Pop();
         ValutStack.Pop(ref RoundBracketsi);
         //if( ValutStack.Get( ref itemp))
         // MessageBox.Show(itemp+"","3");
         //else
         // MessageBox.Show(0 + "", "33");
         if (pWords.GetWord(WordIndex).CompareTo(')') == 0)
         {
             WordIndex++;
             RoundBracketsL++;
             E_(pWords);
         }
         else
         {
             MessageBox.Show("第" + RoundBracketsi + "个左括号缺少右括号", "右括号");
             bResult = false;
             return;
         }
     }
     else
     if (pWords.GetWordAttribute(WordIndex) != 2)
     {
         WordIndex++;
         E_(pWords);
     }
     else
     {
         bResult = false;
         return;
     }
 }
예제 #3
0
        public bool ISIllegal(string Expression, bool ismess)
        {
            if (Expression.ToCharArray().Length >= 400)
            {
                MessageBox.Show("表达式太长");
                return(false);
            }
            string      ExpressionTemp = Expression + "#";
            WordAnalyse MyWords        = new WordAnalyse(ExpressionTemp);

            MyWords.GetResult();
            SyntaxAnalyse MySyntax = new SyntaxAnalyse();

            if (!MySyntax.Analyse(MyWords) && ismess)
            {
                MessageBox.Show("语法错误");
                return(false);
            }
            return(true);
        }
예제 #4
0
 protected void E_(WordAnalyse pWords)
 {
     //char tem[100] = "\0";
     //	strcpy(tem,Words.GetWord(WordIndex));
     //	char Operator = tem[0];
     if (pWords.GetWord(WordIndex).CompareTo('+') == 0 ||
         pWords.GetWord(WordIndex).CompareTo('-') == 0 ||
         pWords.GetWord(WordIndex).CompareTo('*') == 0 ||
         pWords.GetWord(WordIndex).CompareTo('^') == 0 ||
         pWords.GetWord(WordIndex).CompareTo('/') == 0
         )
     {
         WordIndex++;
         E(pWords);
         E_(pWords);
     }
     else
     {
         return;
     }
 }
예제 #5
0
        public bool Analyse(WordAnalyse pWords)
        {
            if (pWords.GetResult() == false)
            {
                return(false);
            }
            E(pWords);
            if (WordIndex < pWords.GetWordNum() - 1)
            {
                if (pWords.GetWord(WordIndex).CompareTo(')') == 0)
                {
                    MessageBox.Show("第" + (RoundBracketsL + 1) + "个右括号缺少左括号", "缺少左括号");
                }

                bResult   = true;
                WordIndex = 0;
                return(false);
            }
            bool tem = bResult;

            bResult   = true;
            WordIndex = 0;
            return(tem);
        }