Example #1
0
 private bool Check(string pattern, Token token)
 {
     switch (token.type)
     {
         case TokenType.ArithmaticOperator:
             return pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase);
         case TokenType.Generic:
             return HandleGeneric(token, pattern);
         case TokenType.LogicalOperator:
             return pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase);
         case TokenType.RelationalOperator:
             return pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase);
     }
     return false;
 }
Example #2
0
        private bool HandleGeneric (Token token, string pattern)
        {
            var genericToken = (Generic)token;
            switch (genericToken.genericType)
            {
                case GenericType.AnyString:
                    if (tokenList.Where(t => t.type == TokenType.Generic && ((Generic)t).genericType != GenericType.AnyString).Any(t => HandleGeneric(t, pattern)))
                        return false;
                    else
                        return true;
                case GenericType.DecimalPart:
                    return HandleGeneric(tokenList.FirstOrDefault(t => t.type == TokenType.Generic &&
                                        ((Generic)t).genericType == GenericType.DecimalPoint),
                                        pattern.Substring(0, 1)) && 
                                        HandleGeneric(tokenList.FirstOrDefault(t => t.type == TokenType.Generic && 
                                        ((Generic)t).genericType == GenericType.UnsignInteger),
                                        pattern.Substring(1, pattern.Length - 1));
                  

                case GenericType.DecimalPoint:
                    return pattern.Equals(token.identifier);
                case GenericType.Digit:
                    if (pattern.Length > 1)
                        return false;
                    else
                        return Numbers.Where(n => n.ToString().Equals(pattern)).Count() != 0;
                case GenericType.Exponent:
                    return pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase);
                case GenericType.ExponentPart:
                    return HandleGeneric(tokenList.FirstOrDefault(t => t.type == TokenType.Generic &&
                                        ((Generic)t).genericType == GenericType.Exponent),
                                        pattern.Substring(0, 1)) && HandleGeneric(tokenList.FirstOrDefault(t => t.type == TokenType.Generic
                                        && ((Generic)t).genericType == GenericType.Real),
                                        pattern.Substring(1, pattern.Length - 1));
                case GenericType.Integer:
                    int outInteg;
                        return int.TryParse(pattern, out outInteg);
                case GenericType.Letter:
                    if (pattern.Length == token.size)
                    {
                        if (pattern.IndexOfAny(SpecialChars) >= 0 || pattern.IndexOfAny(Numbers) >= 0)
                            return false;
                        else
                            return true;
                    }
                    else
                        return false;
                case GenericType.Number:
                    return (HandleGeneric(tokenList.FirstOrDefault(t => t.type == TokenType.Generic &&
                                            ((Generic)t).genericType == GenericType.Integer), pattern) ||
                                            HandleGeneric(tokenList.FirstOrDefault(t => t.type == TokenType.Generic &&
                                            ((Generic)t).genericType == GenericType.Real), pattern));
                case GenericType.Real:
                    float outFl;
                   return float.TryParse(pattern, out outFl);
               case GenericType.Sign:
                    return pattern.Equals(token.identifier);
                case GenericType.Strng:
                    return (pattern[0].ToString().Equals(token.identifier) && pattern[pattern.Length - 1].ToString().Equals(token.identifier));
                case GenericType.UnsignInteger:
                    int integ;
                    var isInt = int.TryParse(pattern, out integ);
                    return (isInt && integ > -1);
                case GenericType.If:
                    return (pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase));
                case GenericType.Comment:
                    return (pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase));
                case GenericType.Read:
                    return (pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase));
                case GenericType.Then:
                    return (pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase));
                case GenericType.Print:
                    return (pattern.Equals(token.identifier, StringComparison.InvariantCultureIgnoreCase));
                case GenericType.Intvariable:
                    if(AllButKeyWords().Any(t => HandleGeneric(t,pattern)))
                        return false;
                    else
                        return token.identifier.Contains(pattern.Substring(0, 1));
                case GenericType.RealVariable:
                    if (AllButKeyWords().Any(t => HandleGeneric(t, pattern)))
                        return false;
                    else
                        return token.identifier.Contains(pattern.Substring(0, 1));
                case GenericType.StringVariable:
                    if (AllButKeyWords().Any(t => HandleGeneric(t, pattern)))
                        return false;
                    else
                        return token.identifier.Contains(pattern.Substring(0, 1)) && SpecialChars.Any(c => !pattern.Contains(c));
                case GenericType.End:
                    return token.identifier.Equals(pattern);
                case GenericType.Assignment:
                    return token.identifier.Equals(pattern);
            }
            return false;
        }
Example #3
0
 public TokenizedWord(string value, Token[] tokens)
 {
     this.value = value;
     this.tokens = tokens;
 }
Example #4
0
        public void AddToSentenceTokens(string input, Token[] tokens)
        {

            
        }