Beispiel #1
0
        private object CreateHexIntegerLiteral(char first)
        {
            CharBuilder cb = new CharBuilder();

            cb.Append(first);
            cb.Append(ReadChar());//x or X (ever tested before)
            double val = 0;

            while (CanAdvance)
            {
                char next = PeekChar();
                switch (next)
                {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                {
                    cb.Append(next);
                    val = val * 16 + next - '0';
                    ReadChar();
                    continue;
                }

                case 'a':
                case 'b':
                case 'c':
                case 'd':
                case 'e':
                case 'f':
                {
                    cb.Append(next);
                    val = val * 16 + next - 'a' + 10;
                    ReadChar();
                    continue;
                }

                case 'A':
                case 'B':
                case 'C':
                case 'D':
                case 'E':
                case 'F':
                {
                    cb.Append(next);
                    val = val * 16 + next - 'A' + 10;
                    ReadChar();
                    continue;
                }
                }
                break;
            }
            return(int.Parse(cb.ToString()));
        }
Beispiel #2
0
        private object CreateOctalIntegerLiteral(char first)
        {
            var cb = new CharBuilder();

            cb.Append(first);//0
            double val = 0;

            while (CanAdvance)
            {
                char next = PeekChar();
                switch (next)
                {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                {
                    cb.Append(next);
                    val = val * 8 + next - '0';
                    ReadChar();
                    continue;
                }
                }
                break;
            }
            return(int.Parse(cb.ToString()));
        }
Beispiel #3
0
        public string ReadString()
        {
            CharBuilder cb = new CharBuilder();

            for (; c != '`'; c = ReadChar())
            {
                cb.Append(c);
            }
            return(cb.ToString());
        }
Beispiel #4
0
        public string ReadVariableName()
        {
            CharBuilder cb = new CharBuilder();

            for (; char.IsLetterOrDigit(c) || c == '_'; c = ReadChar())
            {
                cb.Append(c);
            }
            c = FallBack();
            return(cb.ToString());
        }
Beispiel #5
0
        public string ReadTypeName()
        {
            CharBuilder cb = new CharBuilder();

            //todo use do while
            for (; char.IsLetterOrDigit(c) || c == '_' || c == '.'; c = ReadChar())
            {
                cb.Append(c);
            }
            c = FallBack();
            return(cb.ToString());
        }
Beispiel #6
0
        private object ReadNumber(char first)
        {
            CharBuilder builder = new CharBuilder();

            builder.Append(first);
            int dot = 0;
            int exp = 0;

            while (CanAdvance)
            {
                char next = PeekChar();
                switch (next)
                {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                {
                    builder.Append(next);
                    ReadChar();
                    continue;
                }

                case '.':
                    //skip .
                    ReadChar();
                    next = PeekChar();
                    if (char.IsDigit(next))
                    {
                        dot++;
                        //add .
                        builder.Append('.');
                        builder.Append(next);
                        //skip digit
                        ReadChar();
                        if (dot > 1)
                        {
                            break;
                        }
                        continue;
                    }
                    FallBack();
                    break;

                case 'e':
                case 'E':
                {
                    builder.Append(next);
                    c = ReadChar();
                    exp++;
                    if (exp > 1)
                    {
                        break;
                    }
                    next = PeekChar();
                    if (next == '+' || next == '-')
                    {
                        builder.Append(next);
                        ReadChar();
                    }
                    continue;
                }
                }
                break;
            }
            if (dot > 0)
            {
                return(double.Parse(builder.ToString()));
            }
            else
            {
                return(int.Parse(builder.ToString()));
            }
        }