Пример #1
0
 private static Nodes.Expression Term()
 {
     Nodes.Expression left = Deg();
     while (Lexer.LookAhead().LexType == Lexer.LexType.Multiply || Lexer.LookAhead().LexType == Lexer.LexType.Divide)
     {
         if (Lexer.LookAhead().LexType == Lexer.LexType.Multiply)
         {
             Lexer.NextLexem();
             Nodes.Expression right = Deg();
             left = new Nodes.BinaryOperation(Nodes.BinaryOperation.TypeOfOperations.Multiply, left, right);
         }
         else
             if (Lexer.LookAhead().LexType == Lexer.LexType.Divide)
             {
                 Lexer.NextLexem();
                 Nodes.Expression right = Deg();
                 left = new Nodes.BinaryOperation(Nodes.BinaryOperation.TypeOfOperations.Division, left, right);
             }
     }
     return left;
     /*StringBuilder result = Deg();
     Lexer.Lexem currLexem = Lexer.LookAhead();
     while (true)
     {
         if (currLexem.LexType == Lexer.LexType.Divide)
         {
             Lexer.NextLexem();
             result.Append(Lexer.Space);
             result.Append(Deg());
             result.Append(Lexer.Space);
             result.Append(Lexer.Divide);
         }
         else
             if (currLexem.LexType == Lexer.LexType.Multiply)
             {
                 Lexer.NextLexem();
                 result.Append(Lexer.Space);
                 result.Append(Deg());
                 result.Append(Lexer.Space);
                 result.Append(Lexer.Multiply);
             }
             else
                 break;
         currLexem = Lexer.LookAhead();
     }
     return result;*/
     /*Nodes.Expression left = Deg();
     Lexer.Lexem currLexem = Lexer.LookAhead();
     if (currLexem.LexType == Lexer.LexType.Multiply)
     {
         Lexer.NextLexem();
         return new Nodes.BinaryOperation(Nodes.BinaryOperation.TypeOfOperations.Multiply, left, Term());
     }
     if (currLexem.LexType == Lexer.LexType.Divide)
     {
         Lexer.NextLexem();
         return new Nodes.BinaryOperation(Nodes.BinaryOperation.TypeOfOperations.Division, left, Term());
     }*/
 }
Пример #2
0
        private static Nodes.Expression Expr()
        {
            Nodes.Node.Coords coords = Lexer.Coords;
            Nodes.Expression left = Term();

            while (Lexer.LookAhead().LexType == Lexer.LexType.Add || Lexer.LookAhead().LexType == Lexer.LexType.Minus)
            {
                if (Lexer.LookAhead().LexType == Lexer.LexType.Add)
                {
                    Lexer.NextLexem();
                    Nodes.Expression right = Term();
                    left = new Nodes.BinaryOperation(Nodes.BinaryOperation.TypeOfOperations.Add, left, right);
                }
                else
                    if (Lexer.LookAhead().LexType == Lexer.LexType.Minus)
                    {
                        Lexer.NextLexem();
                        Nodes.Expression right = Term();
                        left = new Nodes.BinaryOperation(Nodes.BinaryOperation.TypeOfOperations.Minus, left, right);
                    }
            }
            left.Coords = coords;
            return left;
        }