public static IBoolable Build(List <Token> tokens) { /// INITIAL CHECKING // check is is empty if (tokens.Count == 0) { throw new SyntaxErrorException("ERROR! Variable declaration is empty."); } // check if contains not allowed tokens Token wwtok = TokenGroups.WrongTokenInExpression(tokens); if (!wwtok.GetTokenType().Equals(TokenType.Null)) { return(null); } // check brackets if (!Brackets.CheckCorrectness(tokens)) { return(null); } // remove first and last bracket if it is there while (tokens[0].GetTokenType().Equals(TokenType.BracketOn) && tokens[tokens.Count - 1].GetTokenType().Equals(TokenType.BracketOff) && !Brackets.ContainsIndependentBracketsPairs(tokens, BracketsType.Normal)) { List <Token> tokensCopy = tokens.Select(t => t.Clone()).ToList(); tokensCopy.RemoveAt(tokens.Count - 1); tokensCopy.RemoveAt(0); tokens = tokensCopy; } // check is is empty again after removing brackets if (tokens.Count == 0) { throw new SyntaxErrorException("ERROR! Variable declaration is empty."); } /// BOOL BUILDING // try to build simple one-element Boolable if (tokens.Count == 1) { if (tokens[0].GetTokenType().Equals(TokenType.Variable)) { string str = tokens[0].GetContent(); if (InterVariables.GetInstance().Contains(str, InterVarType.Bool)) { return(new BoolVariableRefer(str)); } else { return(null); } } if (tokens[0].GetTokenType().Equals(TokenType.BoolConstant)) { if (tokens[0].GetContent().Equals("true")) { return(new BoolConstant(true)); } else { return(new BoolConstant(false)); } } } // try to build IN function if (TokenGroups.ContainsTokenOutsideBrackets(tokens, TokenType.In)) { IBoolable iboo = BuildIn(tokens); if (!iboo.IsNull()) { return(iboo); } } // try to build LIKE function if (TokenGroups.ContainsTokenOutsideBrackets(tokens, TokenType.Like)) { IBoolable iboo = BuildLike(tokens); if (!iboo.IsNull()) { return(iboo); } } // try to build BETWEEN function if (TokenGroups.ContainsTokenOutsideBrackets(tokens, TokenType.And) && TokenGroups.ContainsTokenOutsideBrackets(tokens, TokenType.Between)) { IBoolable iboo = BuildBetween(tokens); if (!iboo.IsNull()) { return(iboo); } } // try to build time comparison IS AFTER/IS BEFORE if (ContainsOneTimeComparingToken(tokens)) { IBoolable iboo = BuildTimeComparison(tokens); if (!iboo.IsNull()) { return(iboo); } } // try to build comparison = != > < >= <= if (ContainsOneComparingToken(tokens)) { IBoolable iboo = BuildComparison(tokens); if (!iboo.IsNull()) { return(iboo); } } // try to build bool ternary if (TernaryBuilder.IsPossibleTernary(tokens)) { IBoolable iboo = TernaryBuilder.BuildBoolTernary(tokens); if (!iboo.IsNull()) { return(iboo); } } // try to build bool function if (Functions.IsPossibleFunction(tokens)) { IBoolable iboo = BoolFunction.Build(tokens); if (!iboo.IsNull()) { return(iboo); } } // try to build expression: many elements with operators or, and, xor, not if (ContainsLogicTokens(tokens)) { return(BuildExpression(tokens)); } else { return(null); } }