public void Encode(ASTProduct 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))); }
//<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(ASTProduct node) { SenseExpr rhs = m_stack.Pop(); SenseExpr lhs = m_stack.Pop(); if (lhs.Value == Dimension.None) { m_stack.Push(new SenseExpr(rhs.Value, rhs.Code)); } else 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))); } }
// [Lhs * Rhs] * number public override ASTNode TryMultiply(ASTNode number) { if (Lhs.IsNumeric) { // [Lhs * Rhs] * number --> [Lhs * number] * Rhs ASTNode product = new ASTProduct(Lhs, number); ASTNode normalized = Rhs.TryMultiply(product); return((normalized != null) ? normalized : new ASTProduct(product, Rhs)); } if (Rhs.IsNumeric) { // [Lhs * Rhs] * number --> Lhs * [Rhs * number] ASTNode product = new ASTProduct(Rhs, number); ASTNode normalized = Lhs.TryMultiply(product); return((normalized != null) ? normalized : new ASTProduct(Lhs, product)); } return(null); }