public ScaleType(string name, string refpoint, UnitType unit, NumExpr offset) : base(MeasureType.DefaultNamespace, name) { RefPoint = refpoint; Unit = unit; Offset = offset; }
public void Encode(ASTSum 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))); }
public void Encode(ASTUnary node) { NumExpr expr = m_stack.Pop(); m_stack.Push(node.Plus ? new NumExpr(expr.IsTrueValue, expr.Value, String.Format("+{0}", expr.Code)) : new NumExpr(expr.IsTrueValue, expr.Value.Negate(), String.Format("-{0}", expr.Code)) ); }
//<Dim Expr> ::= <Dim Expr> '|' <Dim Term> // | <Dim Term> public bool GetDimExpr(UnitType candidate, NumericType numType) { ASTNode basic = GetDimTerm(candidate, numType); if (basic == null) { return(false); } candidate.Sense = m_senseEncoder.Encode(basic); candidate.Factor = m_exprEncoder.Encode(basic, numType); basic.Normalized().Bind(candidate); while (m_symbol == Lexer.Symbol.Pipe) { GetToken(); ASTNode alternate = GetDimTerm(candidate, numType); if (alternate == null) { return(false); } SenseExpr sense = m_senseEncoder.Encode(alternate); if (sense.Value != candidate.Sense.Value) { Note("{0}: inconsistent dimensions: {1} == {2} != {3} == {4}.", candidate.Name, candidate.Sense.Code, candidate.Sense.Value, sense.Value, sense.Code); return(false); } NumExpr factor = m_exprEncoder.Encode(alternate, numType); if (factor.IsTrueValue && candidate.Factor.IsTrueValue && (factor.Value != candidate.Factor.Value)) { Note("{0}: inconsistent conversion factors: {1} == {2} != {3} == {4}.", candidate.Name, candidate.Factor.Code, candidate.Factor.Value, factor.Value, factor.Code); return(false); } alternate.Normalized().Bind(candidate); } return(true); }
public UnitType(string name, SenseExpr sense, NumExpr factor) : this(name) { Sense = sense; Factor = factor; }
public void Encode(ASTParenthesized node) { NumExpr expr = m_stack.Pop(); m_stack.Push(new NumExpr(expr.IsTrueValue, expr.Value, String.Format("({0})", expr.Code))); }
// <Scale> ::= 'scale' Identifier <Format> Identifier '=' Identifier <Num Expr> ';' // 1st identifier = scale identifier, // 2nd identifier = ref.point identifier, // 3rd identifier = unit identifier, private bool ParseScale() { // Identifier (scale name) string scaleName = GetEntityName("scale"); if (scaleName == null) { return(false); } // Format string format = GetFormat(scaleName, String.Empty); if (format == null) { return(false); } // Identifier (refpoint) string refpoint = GetReferencePoint(scaleName); if (refpoint == null) { return(false); } // "=" if (m_symbol == Lexer.Symbol.EQ) { GetToken(); } else { Note("{0}: \"{1}\" found while expected equal sign \"=\".", scaleName, m_token); return(false); } // Identifier (unit) UnitType unit = GetScaleUnit(refpoint, scaleName); if (unit == null) { return(false); } // Scale offset <Num Expr> ASTNode offsetAST = GetNumExpr(scaleName, unit.Factor.Value.Type); if (offsetAST == null) { return(false); } // Semicolon ";" bool done = GetSemicolon(scaleName); if (done) { NumExpr offsetExpr = m_exprEncoder.Encode(offsetAST, unit.Factor.Value.Type); ScaleType scale = new ScaleType(scaleName, refpoint, unit, offsetExpr); scale.Format = String.IsNullOrWhiteSpace(format) ? unit.Format : format; ScaleType relative = GetRelativeScale(scale); if (relative != null) { relative.AddRelative(scale); } m_scales.Add(scale); } return(done); }