示例#1
0
        public static NumberToken GetToken(Scanner scanner)
        {
            NumberToken t = new NumberToken();

            t.stringBuilder = new StringBuilder();
            t.sc            = scanner.col;
            t.sr            = scanner.row;

            t.AccumulateValue(scanner, ref t._value);
            t.wholePlaces = t.digitCount;

            if (scanner.curr == '.')
            {
                t.stringBuilder.Append(scanner.curr);
                scanner.Next();
                t.real = true;
                t.AccumulateValue(scanner, ref t._value);
                t.decimalPlaces = t.digitCount - t.wholePlaces;
            }

            if (scanner.curr == 'e' || scanner.curr == 'E')
            {
                t.real = true;
                t.stringBuilder.Append(scanner.curr);
                scanner.Next();

                if (scanner.curr == '+' || scanner.curr == '-')
                {
                    t.exponentSign = scanner.curr;
                    t.stringBuilder.Append(scanner.curr);
                    scanner.Next();
                }

                t.digitCount = 0;
                t.AccumulateValue(scanner, ref t.eValue);

                if (t.exponentSign == '-')
                {
                    t.eValue = -t.eValue;
                }
            }

            t.ec = scanner.col;
            t.er = scanner.row;

            var exponent = t.eValue - t.decimalPlaces;

            if (exponent != 0)
            {
                t.Value *= Math.Pow(10, exponent);
            }

            t.String = t.stringBuilder.ToString();

            return(t);
        }
示例#2
0
        public static NumberToken GetToken(Scanner scanner)
        {
            NumberToken t = new NumberToken();

            t.stringBuilder = new StringBuilder();
            t.sc            = scanner.col;
            t.sr            = scanner.row;

            t.AccumulateValue(scanner, ref t._value);
            t.wholePlaces = t.digitCount;

            // no dealing with real values, just integers
            // if (scanner.curr == '.')
            // {
            //     t.stringBuilder.Append(scanner.curr);
            //     scanner.Next();
            //     t.real = true;
            //     t.AccumulateValue(scanner, ref t._value);
            //     t.decimalPlaces = t.digitCount - t.wholePlaces;
            // }

            // if (scanner.curr == 'e' || scanner.curr == 'E')
            // {
            //     t.real = true;
            //     t.stringBuilder.Append(scanner.curr);
            //     scanner.Next();

            //     if (scanner.curr == '+' || scanner.curr == '-')
            //     {
            //         t.exponentSign = scanner.curr;
            //         t.stringBuilder.Append(scanner.curr);
            //         scanner.Next();
            //     }

            //     t.digitCount = 0;
            //     t.AccumulateValue(scanner, ref t.eValue);

            //     if (t.exponentSign == '-')
            //     {
            //         t.eValue = -t.eValue;
            //     }
            // }

            t.ec = scanner.col;
            t.er = scanner.row;

            // var exponent = t.eValue - t.decimalPlaces;
            // if (exponent != 0)
            // {
            //     t.Value *= Math.Pow(10, exponent);
            // }

            t.String = t.stringBuilder.ToString();

            return(t);
        }