Esempio n. 1
0
        static bool IsHexNumber(TokenStringReader reader)
        {
            if (!reader.HasNext(3))
            {
                return(false);
            }
            int c = reader.PeekForward(2);

            return(reader.PeekForward() == '0' && reader.PeekForward(1) == 'x' && ((c >= '0' && c <= '7') || (c >= 'A' && c <= 'F')));
        }
Esempio n. 2
0
        static bool IsOctalNumber(TokenStringReader reader)
        {
            if (!reader.HasNext(3))
            {
                return(false);
            }
            int c = reader.PeekForward(2);

            return(reader.PeekForward() == '0' && reader.PeekForward(1) == 'o' && (c >= '0' && c <= '7'));
        }
Esempio n. 3
0
        static bool IsBinaryNumber(TokenStringReader reader)
        {
            if (!reader.HasNext(3))
            {
                return(false);
            }
            int c = reader.PeekForward(2);

            return(reader.PeekForward() == '0' && reader.PeekForward(1) == 'b' && (c == '0' || c == '1'));
        }
Esempio n. 4
0
        /****************************/

        static bool IsNumber(TokenStringReader reader)
        {
            if (!reader.HasNext())
            {
                return(false);
            }
            int c = reader.PeekForward();

            return(c >= 48 && c <= 57);
        }
Esempio n. 5
0
        static bool IsIdentifier(TokenStringReader reader)
        {
            if (!reader.HasNext())
            {
                return(false);
            }

            int c = reader.PeekForward();

            return(!(c >= 48 && c <= 57) && (c == '_' || (c >= 65 && c <= 90) || (c >= 97 && c <= 122)));
        }
Esempio n. 6
0
        /// <summary>
        /// Get string tokens.
        /// </summary>
        /// <returns></returns>
        public TokensContainer Tokenize()
        {
            TokensContainer tokens = new TokensContainer();

            while (reader.HasNext())
            {
                (TokenIdentifier.TokenType type, int advance) = TokenIdentifier.Identify(reader);

                if (reader.PeekForward() == ' ')
                {
                    reader.Forward();
                }
                else
                {
                    for (int i = 0; i < advance; i++)
                    {
                        reader.Forward();
                    }

                    switch (type)
                    {
                    case TokenIdentifier.TokenType.AndOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.AndOperator));
                        break;

                    case TokenIdentifier.TokenType.DivisionOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.DivisionOperator));
                        break;

                    case TokenIdentifier.TokenType.Identifier:
                        tokens.AddToken(IdentifierToken.Parse(reader));
                        break;

                    case TokenIdentifier.TokenType.LeftParenthesis:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.LeftParenthesis));
                        break;

                    case TokenIdentifier.TokenType.MinusOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.MinusOperator));
                        break;

                    case TokenIdentifier.TokenType.ModuloOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.ModuloOperator));
                        break;

                    case TokenIdentifier.TokenType.MultiplicationOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.MultiplicationOperator));
                        break;

                    case TokenIdentifier.TokenType.NegationOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.NegationOperator));
                        break;

                    case TokenIdentifier.TokenType.Number:
                        tokens.AddToken(NumberToken.Parse(reader));
                        break;

                    case TokenIdentifier.TokenType.BinaryNumber:
                        tokens.AddToken(BinaryNumberToken.Parse(reader));
                        break;

                    case TokenIdentifier.TokenType.OctalNumber:
                        tokens.AddToken(OctalNumberToken.Parse(reader));
                        break;

                    case TokenIdentifier.TokenType.HexNumber:
                        tokens.AddToken(HexNumberToken.Parse(reader));
                        break;

                    case TokenIdentifier.TokenType.OrOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.OrOperator));
                        break;

                    case TokenIdentifier.TokenType.PlussOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.PlussOperator));
                        break;

                    case TokenIdentifier.TokenType.PowerOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.PowerOperator));
                        break;

                    case TokenIdentifier.TokenType.RightParenthesis:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.RightParenthesis));
                        break;

                    case TokenIdentifier.TokenType.ShiftLeftOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.ShiftLeftOperator));
                        break;

                    case TokenIdentifier.TokenType.ShiftRightOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.ShiftRightOperator));
                        break;

                    case TokenIdentifier.TokenType.XorOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.XorOperator));
                        break;

                    case TokenIdentifier.TokenType.ParamSeparator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.ParamSeparator));
                        break;

                    case TokenIdentifier.TokenType.FactorialOperator:
                        tokens.AddToken(new Token(TokenIdentifier.TokenType.FactorialOperator));
                        break;

                    default: throw new Exception("Invalid token at " + reader.Position);
                    }
                }
            }

            return(tokens);
        }
Esempio n. 7
0
 static bool IsFactorialOperator(TokenStringReader reader)
 {
     return(reader.HasNext() && reader.PeekForward() == '!');
 }
Esempio n. 8
0
 static bool IsAssignmentOperator(TokenStringReader reader)
 {
     return(reader.HasNext() && reader.PeekForward() == '=');
 }
Esempio n. 9
0
 static bool IsParamSeparator(TokenStringReader reader)
 {
     return(reader.HasNext() && reader.PeekForward() == ',');
 }
Esempio n. 10
0
 static bool IsPlussOperator(TokenStringReader reader)
 {
     return(reader.HasNext() && reader.PeekForward() == '+');
 }
Esempio n. 11
0
 static bool IsNegationOperator(TokenStringReader reader)
 {
     return(reader.HasNext() && reader.PeekForward() == '~');
 }
Esempio n. 12
0
 static bool IsShiftRightOperator(TokenStringReader reader)
 {
     return(reader.HasNext(2) && reader.PeekForward() == '>' && reader.PeekForward(1) == '>');
 }
Esempio n. 13
0
 static bool IsModuloOperator(TokenStringReader reader)
 {
     return(reader.HasNext() && reader.PeekForward() == '%');
 }
Esempio n. 14
0
 static bool IsRightParenthesis(TokenStringReader reader)
 {
     return(reader.HasNext() && reader.PeekForward() == ')');
 }