예제 #1
0
        private Token GetToken(string symbol)
        {
            TokenType type = TokenDictionary.GetTokenType(symbol[0]);
            string    text = String.Copy(symbol);

            if (type == TokenType.Unknown)
            {
                if (Char.IsDigit(symbol, 0))
                {
                    type = TokenType.Double;
                    text = GetDouble();
                }
                else if (Char.IsLetter(symbol, 0) || symbol[0] == '_')
                {
                    type = TokenType.Word;
                    text = GetWord();
                }
            }

            string temp = Peek(1);

            if (type == TokenType.Quotes)
            {
                type = TokenType.String;
                text = GetString();
            }
            else if (type == TokenType.Not && temp != "" && temp[0] == '=')
            {
                type = TokenType.NotEqual;
                text = "!=";
                ++position;
            }
            else if (temp != "" && temp[0] == '=')
            {
                if (type == TokenType.Equal)
                {
                    type = TokenType.DoubleEqual; text = "=="; position++;
                }
                else if (type == TokenType.Bigger)
                {
                    type = TokenType.BiggerEqual; text = ">="; position++;
                }
                else if (type == TokenType.Smaller)
                {
                    type = TokenType.SmallerEqual; text = "<="; position++;
                }
            }
            FindKeyWords();

            return(new Token(text, type));
        }
예제 #2
0
 private void FindKeyWords()
 {
     for (int i = 0; i < tokens.Count; ++i)
     {
         if (tokens[i].Type == TokenType.Word)
         {
             tokens[i].Type = TokenDictionary.GetWordType(tokens[i].Text);
         }
         if (tokens[i].Type == TokenType.Word && i != tokens.Count - 1 && tokens[i + 1].Type == TokenType.LParam)
         {
             tokens[i].Type = TokenType.Function;
         }
     }
 }