コード例 #1
0
        // unit: NAME
        // { $$ = new ScaledUnit($1) }

        // unit: NAME '^' INT
        // { $$ = new ScaledUnit($1, $3) }

        ScaledUnit unit()
        {
            var t = PeekToken();

            if (!t.Id.EQ(TokenId.NAME))
            {
                throw new ParserException(t, "unit ::= . NAME ( '^' INT )?");
            }
            GetToken();

            Unit s1;

            if (!ScaledUnit.TryParse(t.Value, out s1))
            {
                throw new ParserException(t, $"unit ::= . '{t.Value}' ( '^' INT )? ; NAME '{t.Value}' not recognised.");
            }

            int s3 = 1;

            t = PeekToken();
            if (t.Id.EQ(TokenId.PWR))
            {
                GetToken();

                t = PeekToken();
                if (!t.Id.EQ(TokenId.INT))
                {
                    throw new ParserException(t, "unit ::= NAME '^' . INT");
                }
                GetToken();
                s3 = int.Parse(t.Value);
            }

            return(new ScaledUnit(s1, s3));
        }
コード例 #2
0
 /// <summary>
 /// Append: Multiply (or divide) this Scale with an extra factor
 /// </summary>
 /// <param name="scale">Scale to append to this Scale</param>
 /// <param name="reciproce">true: append [scale^-1] else append [scale]</param>
 public void Append(ScaledUnit scale, bool reciproce = false)
 {
     Scale.Append(scale, reciproce);
 }
コード例 #3
0
 /// <summary>
 /// .ctor copy construtor to create a copy of another scale.
 /// </summary>
 /// <param name="other">scale to copy</param>
 public ScaledUnit(ScaledUnit other)
 {
     Unit = other.Unit;
     Exp  = other.Exp;
 }