public void Encode(ASTQuotient node)
        {
            NumExpr rhs = m_stack.Pop();
            NumExpr lhs = m_stack.Pop();

            m_stack.Push(new NumExpr(lhs.IsTrueValue && rhs.IsTrueValue, lhs.Value / rhs.Value, String.Format("{0} / {1}", lhs.Code, rhs.Code)));
        }
Example #2
0
        //<Num Term> ::= <Num Term> '*' <Num Unary>
        //            |  <Num Term> '/' <Num Unary>
        //            |  <Num Unary>
        private ASTNode GetNumTerm(string scaleName, NumericType numType)
        {
            ASTNode lhs = GetNumUnary(scaleName, numType);

            if (lhs == null)
            {
                return(null);
            }

            while ((m_symbol == Lexer.Symbol.Times) || (m_symbol == Lexer.Symbol.Div))
            {
                Lexer.Symbol operation = m_symbol;
                GetToken();

                ASTNode rhs = GetNumUnary(scaleName, numType);
                if (rhs == null)
                {
                    return(null);
                }
                else if (operation == Lexer.Symbol.Times)
                {
                    lhs = new ASTProduct(lhs, rhs);
                }
                else
                {
                    lhs = new ASTQuotient(lhs, rhs);
                }
            }
            return(lhs);
        }
        //<Dim Term> ::= <Dim Term> '*' <Dim Factor>
        //            |  <Dim Term> '^' <Dim Factor>
        //            |  <Dim Term> '/' <Dim Factor>
        //            |  <Dim Factor>
        private ASTNode GetDimTerm(UnitType candidate, NumericType numType)
        {
            ASTNode lhs = GetDimFactor(candidate, numType);

            if (lhs == null)
            {
                return(null);
            }

            while ((m_symbol == Lexer.Symbol.Times) || (m_symbol == Lexer.Symbol.Div) || (m_symbol == Lexer.Symbol.Wedge))
            {
                Lexer.Symbol operatorSymbol = m_symbol;
                string       operatorToken  = m_token;
                int          operatorLine   = m_lexer.TokenLine;
                int          operatorColumn = m_lexer.TokenColumn;

                GetToken();

                ASTNode rhs = GetDimFactor(candidate, numType);
                if (rhs == null)
                {
                    return(null);
                }

                else if (operatorSymbol == Lexer.Symbol.Div)
                {
                    lhs = new ASTQuotient(lhs, rhs);
                }

                else if (operatorSymbol == Lexer.Symbol.Times)
                {
                    lhs = new ASTProduct(lhs, rhs, iswedgeproduct: false);
                }

                else if (lhs.IsWedgeCompatible && rhs.IsWedgeCompatible)
                {
                    lhs = new ASTProduct(lhs, rhs, iswedgeproduct: true);
                }

                else
                {
                    string denote = "\u02C7\u02C7\u02C7{0}\u02C7\u02C7\u02C7";   //  ˇˇˇexprˇˇˇ
                    Note(operatorLine, operatorColumn, operatorToken,
                         String.Format("{0}: wedge product incompatible factor(s): {1} ^ {2}.", candidate.Name,
                                       lhs.IsWedgeCompatible ? lhs.ToString() : String.Format(denote, lhs),
                                       rhs.IsWedgeCompatible ? rhs.ToString() : String.Format(denote, rhs)
                                       )
                         );
                    return(null);
                }
            }
            return(lhs);
        }
        public void Encode(ASTQuotient node)
        {
            SenseExpr rhs = m_stack.Pop();
            SenseExpr lhs = m_stack.Pop();

            if (rhs.Value == Dimension.None)
            {
                m_stack.Push(new SenseExpr(lhs.Value, lhs.Code));
            }
            else
            {
                m_stack.Push(new SenseExpr(lhs.Value / rhs.Value, String.Format("{0} / {1}", lhs.Code, rhs.Code)));
            }
        }
Example #5
0
 // [Lhs / Rhs] * number
 public override ASTNode TryMultiply(ASTNode number)
 {
     if (Lhs.IsNumeric)
     {
         // [Lhs / Rhs] * number --> [Lhs * number] / Rhs
         return(new ASTQuotient(new ASTProduct(Lhs, number), Rhs));
     }
     else if (Rhs.IsNumeric)
     {
         // [Lhs / Rhs] * number --> Lhs * [number / Rhs]
         ASTNode quotient   = new ASTQuotient(number, Rhs);
         ASTNode normalized = Lhs.TryDivide(quotient);
         return((normalized != null) ? normalized : new ASTQuotient(Lhs, quotient));
     }
     return(null);
 }
Example #6
0
 // [Lhs * Rhs] / number
 public override ASTNode TryDivide(ASTNode number)
 {
     if (Lhs.IsNumeric)
     {
         // [Lhs * Rhs] / number --> [Lhs / number] * Rhs
         ASTNode quotient   = new ASTQuotient(Lhs, number);
         ASTNode normalized = Rhs.TryMultiply(quotient);
         return((normalized != null) ? normalized : new ASTProduct(quotient, Rhs));
     }
     if (Rhs.IsNumeric)
     {
         // [Lhs * Rhs] / number --> Lhs * [Rhs / number]
         ASTNode quotient   = new ASTQuotient(Rhs, number);
         ASTNode normalized = Lhs.TryMultiply(quotient);
         return((normalized != null) ? normalized : new ASTProduct(Lhs, quotient));
     }
     return(null);
 }