示例#1
0
        public void Parse(string keyword)
        {
            if (string.IsNullOrEmpty(keyword))
                throw new Exception("Keyword belirtilmemiş.");

            i = -1;
            if (!keyword.Contains("<")) keyword = "<" + keyword + ">";
            this.keyword = keyword;

            currentToken = readNextToken();
            if (!(currentToken.IsWord || currentToken.Value == "("))
                throw new Exception("Keyword <kelime> veya parantez ile başlamalıdır.");

            /*
            Expression currExp = new Word { TheWord = t.Value };
            while (t != null)
            {
                string tValue = t.Value;
                if (!t.IsWord && (tValue == "+" || tValue == "-" || tValue == "^"))
                {
                    t = readNextToken();
                    if (t == null)
                        throw new Exception("Bir keyword +, - ya da ^ ile bitemez.");
                    if (!t.IsWord)
                        throw new Exception("<kelime> gerekli");

                    if (tValue == "+")
                        currExp = new PlusExpression() { Exp1 = currExp, Exp2 = new Word { TheWord = t.Value } };
                    else if (tValue == "-")
                        currExp = new MinusExpression() { Exp1 = currExp, Exp2 = new Word { TheWord = t.Value } };
                    else
                        currExp = new ButNotExpression() { Exp1 = (Word)currExp, Exp2 = new Word { TheWord = t.Value } };
                }
                else if (!t.IsWord && t.Value == "|")
                {
                    list.Add(currExp);
                    t = readNextToken();
                    if (!t.IsWord)
                        throw new Exception("Yeni keyword <kelime> ile başlamalıdır");
                    currExp = new Word { TheWord = t.Value };
                }
                else
                {
                    t = readNextToken();
                    if (t == null)
                        break;
                }
            }
             */

            parsedExpression = parseExpression();
        }
示例#2
0
        Token readNextToken()
        {
            Token res = null;

            i++;

            if (i >= keyword.Length)
            {
                currentToken = null;
                return currentToken;
            }

            char c = keyword[i];
            if (c == '<')
            {
                int wordStart = ++i;
                for (; i < keyword.Length; i++)
                    if (keyword[i] == '>')
                    {
                        res = new Token() { IsWord = true, Value = keyword.Substring(wordStart, i - wordStart) };
                        break;
                    }
            }
            else if (c == '|' || c == '+' || c == '-' || c == '^' || c == '(' || c == ')')
                res = new Token() { IsWord = false, Value = c.ToString() };
            else
                return readNextToken();

            currentToken = res;
            return res;
        }