示例#1
0
文件: Parser.cs 项目: bolsson/Spider
 private void _andTerm()
 {
     _orTerm();
     if (next.GetType() == typeof(AndToken))
     {
         newSimpleTree(new Node(_tokens.getNextToken()), branchesStack.Pop());
         next = _tokens.PeekToken();
         _andTerm();
     }
     else
         return;
 }
示例#2
0
文件: Parser.cs 项目: bolsson/Spider
        public Parser(Tokens tokens)
        {
            branchesStack = new Stack<Node>();
            BinaryTree = new BinaryTreeImp();
            _tokens = tokens;

            next = _tokens.PeekToken();
            if (next.ToString() == "(")
                _query();
            else //NOTE: if the first token is not a parenthesis then all tokens are treated as word tokens, not logic tokens or others
                _buildTreeWordsOnly();
        }
示例#3
0
 //the evaluater uses Reverse Polish Notation
 public void evaluate(Token token)
 {
     IEnumerable<string> newLinkSet = null;
     if (stack.Count >= 2)
     {
         if (token.GetType() == typeof(AndToken))
         {
             newLinkSet = stack.Pop().Intersect(stack.Pop());
         }
         if (token.GetType() == typeof(OrToken))
         {
             newLinkSet = stack.Pop().Union(stack.Pop());
         }
         if (token.GetType() == typeof(AndNotToken))
         {
             var excluded = stack.Pop();
             var included = stack.Pop();
             newLinkSet = included.Except(excluded);
         }
         stack.Push(newLinkSet);
     }
 }
示例#4
0
 public Node(Token token)
 {
     this.token = token;
     left = null;
     right = null;
 }
示例#5
0
文件: Parser.cs 项目: bolsson/Spider
 private void _term()
 {
     if (next.GetType() == typeof(ParenthesisBeginToken) && (!_tokens.isEmpty()))
     {
         Token token = _tokens.getNextToken();
         BinaryTree = new BinaryTreeImp(); //reset the binary tree to ready for a new branch build
         next = _tokens.PeekToken();
         _term();
     }
     if (next.GetType() == typeof(ParenthesisEndToken) && (!_tokens.isEmpty()))
     {
         Token token = _tokens.getNextToken();
         _buildTreeFromAllRemainingBranches();
         if (_tokens.isEmpty())
             return;
         next = _tokens.PeekToken();
         _term();
     }
     if (next.GetType() == typeof(WordToken) && (!_tokens.isEmpty()))
     {
         Token wordToken = _tokens.getNextToken();
         branchesStack.Push(new Node(wordToken));
         next = _tokens.PeekToken();
         _term();
     }
     if (_tokens.isEmpty())
         return;
 }
示例#6
0
 public void AddToken(Token token)
 {
     _tokenQueue.Enqueue(token);
 }