public override string ToString()
        {
            switch (Type)
            {
            case SymbolType.IntValue:
                return(IntVal.ToString());

            case SymbolType.CharValue:
                var str = new StringBuilder();
                str.Append(CharVal);
                return(str.ToString());

            case SymbolType.RealValue:
                return(RealVal.ToString(CultureInfo.InvariantCulture));

            case SymbolType.True:
                return($"true ({IntVal})");

            case SymbolType.False:
                return($"false ({IntVal})");

            default:
                return("Array");
            }
        }
Beispiel #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (IntVal != 0)
            {
                hash ^= IntVal.GetHashCode();
            }
            if (StrVal.Length != 0)
            {
                hash ^= StrVal.GetHashCode();
            }
            if (msgVal_ != null)
            {
                hash ^= MsgVal.GetHashCode();
            }
            if (EnumVal != 0)
            {
                hash ^= EnumVal.GetHashCode();
            }
            if (NestEnumVal != 0)
            {
                hash ^= NestEnumVal.GetHashCode();
            }
            hash ^= msgArray_.GetHashCode();
            hash ^= nestEnumArray_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #3
0
        public static string Roll(string author, string cmd)
        {
            Expression root          = null;
            Expression curExpression = null;

            for (int i = 0; i < cmd.Length; i++)
            {
                switch (cmd[i])
                {
                case ' ':
                    break;

                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    int    intValue      = ReadInt(cmd, i, out i);
                    IntVal newExpression = new IntVal(intValue);
                    if (curExpression == null)
                    {
                        curExpression = newExpression;
                        root          = newExpression;
                    }
                    else if (curExpression is NumExpression)
                    {
                        ((NumExpression)curExpression).Right = newExpression;
                    }
                    break;

                case 'd':
                    int rndValue = ReadInt(cmd, i + 1, out i);
                    if (rndValue == 0)
                    {
                        return("Cannot roll a 0-sided dice.");
                    }
                    RdmVal rndExpression = new RdmVal(rndValue);
                    if (curExpression == null)
                    {
                        curExpression = rndExpression;
                        root          = rndExpression;
                    }
                    else if (curExpression is NumExpression)
                    {
                        ((NumExpression)curExpression).Right = rndExpression;
                    }
                    break;

                case '+':
                case '-':
                case '*':
                case '/':
                    NumExpression intExp = null;
                    switch (cmd[i])
                    {
                    case '+':
                        intExp = new NumExpression(Operator.Add);
                        break;

                    case '-':
                        intExp = new NumExpression(Operator.Subtract);
                        break;

                    case '*':
                        intExp = new NumExpression(Operator.Multiply);
                        break;

                    case '/':
                        intExp = new NumExpression(Operator.Divide);
                        break;
                    }

                    if (curExpression is RdmVal || curExpression is IntVal)
                    {
                        intExp.Left   = curExpression;
                        curExpression = intExp;
                        root          = intExp;
                    }
                    else if (curExpression != null && intExp != null)
                    {
                        if (((NumExpression)curExpression).opr == Operator.Add || ((NumExpression)curExpression).opr == Operator.Subtract)
                        {
                            if (intExp.opr == Operator.Add || intExp.opr == Operator.Subtract)
                            {
                                intExp.Left   = root;
                                root          = intExp;
                                curExpression = intExp;
                            }
                            else
                            {
                                intExp.Left = (curExpression as NumExpression).Right;
                                ((NumExpression)curExpression).Right = intExp;
                                curExpression = intExp;
                            }
                        }
                        else
                        {
                            intExp.Left   = root;
                            root          = intExp;
                            curExpression = intExp;
                        }
                    }
                    break;

                default:
                    return("Could not parse that expression. " + Emotes.Confused);
                }
            }

            if (root != null)
            {
                double sum = root.Calculate();

                if (root is NumExpression)
                {
                    return($"{author} rolled **{root.GetResult()}**, total: **{sum}**.");
                }

                return($"{author} rolled **{root.GetResult()}**.");
            }
            return("Not a valid expression.");
        }
Beispiel #4
0
    public static string convertcurrency(decimal amount)
    {
        string[] txtarray = new string[] { "", "", "Hundred", "Thousand", "Thousand", "Lac", "Lac", "Crore", "Crore" };
        decimal  IntVal;
        decimal  DecVal;
        string   RetVal = "";

        IntVal = Convert.ToDecimal(Convert.ToInt32(amount));
        DecVal = Convert.ToDecimal(Math.Round(amount - Convert.ToInt32(amount), 2)) * 100;
        if (IntVal.ToString().Length > 9)
        {
            //break;
        }
        switch (IntVal.ToString().Length)
        {
        case 1:
            RetVal = TwoDigit(IntVal);
            break;

        case 2:
            RetVal = TwoDigit(IntVal);
            break;

        case 3:
            RetVal = TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(0, 1))) + " Hundred and " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(1, 2)));
            break;

        case 4:
            RetVal = TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(0, 1))) + " Thousand " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(1, 1))) + " Hundred " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(2, 2)));
            break;

        case 5:
            RetVal = TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(0, 2))) + " Thousand " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(2, 1))) + " Hundred " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(3, 2)));
            break;

        case 6:
            RetVal = TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(0, 1))) + " Lac " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(1, 2))) + " Thousand " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(3, 1))) + " Hundred " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(4, 2)));
            break;

        case 7:
            RetVal = TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(0, 2))) + " Lac " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(2, 2))) + " Thousand " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(4, 1))) + " Hundred " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(5, 2)));
            break;

        case 8:
            RetVal = TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(0, 1))) + " Crore " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(1, 2))) + " Lac " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(3, 2))) + " Thousand " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(5, 1))) + " Hundred " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(6, 2)));
            break;

        case 9:
            RetVal = TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(0, 2))) + " Crore " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(2, 2))) + " Lac " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(4, 2))) + " Thousand " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(6, 1))) + " Hundred " + TwoDigit(Convert.ToDecimal(Convert.ToString(IntVal).Substring(7, 2)));
            break;
        }
        RetVal = RetVal.ToString().Trim();
        RetVal = RetVal.Replace("Hundred", "Hundred");
        RetVal = RetVal.Replace("Thousand  Hundred", "Thousand");
        RetVal = RetVal.Replace("Lac  Thousand", "Lac");
        RetVal = RetVal.Replace("Crore  Lac", "Crore");
        RetVal = RetVal.Replace(" and ", " ");
        RetVal = RetVal.Replace(" ", " ");
        if (DecVal > 0)
        {
            RetVal = "Rupees " + RetVal + " and Paise " + TwoDigit(DecVal) + " Only";
        }
        else
        {
            RetVal = "Rupees " + RetVal + " Only";
        }
        RetVal = RetVal.Replace(" Rupees ", " Rupees");
        RetVal = RetVal.Replace(" Only", " Only");
        RetVal = RetVal.Replace(" and Paise Only", " Only");
        RetVal = RetVal.Replace("Rupees Only", "Nil").Trim();
        RetVal = RetVal.Replace("Hundred Only", "Hundred Only");
        RetVal = RetVal.Replace("Thousand Only", "Thousand Only");
        RetVal = RetVal.Replace("Lac Only", "Lac Only");
        RetVal = RetVal.Replace("Crore Only", "Crore Only");
        RetVal = RetVal.Replace("Only", "Only");
        RetVal = RetVal.Replace("  ", " ");

        return(RetVal);
    }