Example #1
0
        /// <summary>
        /// Checks syntax errors on input expression,
        /// as well as performing disambiguation for identifiers.
        /// </summary>
        /// <param name="tokenList">
        /// A list of tokenized input.
        /// </param>
        private void CheckSyntaxError(List <Token> tokenList)
        {
            // Initialize, assuming preceded by OR
            TokenKind previous = TokenKind.Or;

            for (int i = 0; i < tokenList.Count; i++)
            {
                Token token = tokenList[i];
                // Not allowed: ... AND/OR AND/OR ...
                // Allowed: ... AND/OR NOT/ID ...
                if (previous == TokenKind.Or || previous == TokenKind.And)
                {
                    if ((token.Kind == TokenKind.Or) || (token.Kind == TokenKind.And))
                    {
                        throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException),
                                                                       null, "SyntaxErrorUnexpectedBinaryOperator", EnumExpressionEvaluatorStrings.SyntaxErrorUnexpectedBinaryOperator);
                    }
                }
                // Not allowed: ... NOT AND/OR/NOT ...
                // Allowed: ... NOT ID ...
                else if (previous == TokenKind.Not)
                {
                    if (token.Kind != TokenKind.Identifier)
                    {
                        throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException),
                                                                       null, "SyntaxErrorIdentifierExpected", EnumExpressionEvaluatorStrings.SyntaxErrorIdentifierExpected);
                    }
                }
                // Not allowed: ... ID NOT/ID ...
                // Allowed: ... ID AND/OR ...
                else if (previous == TokenKind.Identifier)
                {
                    if ((token.Kind == TokenKind.Identifier) || (token.Kind == TokenKind.Not))
                    {
                        throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException),
                                                                       null, "SyntaxErrorBinaryOperatorExpected", EnumExpressionEvaluatorStrings.SyntaxErrorBinaryOperatorExpected);
                    }
                }

                if (token.Kind == TokenKind.Identifier)
                {
                    string text = token.Text;
                    token.Text = EnumMinimumDisambiguation.EnumDisambiguate(text, typeof(T));
                }

                previous = token.Kind;
            }
        }
Example #2
0
        private void CheckSyntaxError(List <Token> tokenList)
        {
            TokenKind or = TokenKind.Or;

            for (int i = 0; i < tokenList.Count; i++)
            {
                Token token = tokenList[i];
                switch (or)
                {
                case TokenKind.Or:
                case TokenKind.And:
                    if ((token.Kind == TokenKind.Or) || (token.Kind == TokenKind.And))
                    {
                        throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "SyntaxErrorUnexpectedBinaryOperator", EnumExpressionEvaluatorStrings.SyntaxErrorUnexpectedBinaryOperator, new object[0]);
                    }
                    break;

                default:
                    if (or == TokenKind.Not)
                    {
                        if (token.Kind != TokenKind.Identifier)
                        {
                            throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "SyntaxErrorIdentifierExpected", EnumExpressionEvaluatorStrings.SyntaxErrorIdentifierExpected, new object[0]);
                        }
                    }
                    else if ((or == TokenKind.Identifier) && ((token.Kind == TokenKind.Identifier) || (token.Kind == TokenKind.Not)))
                    {
                        throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "SyntaxErrorBinaryOperatorExpected", EnumExpressionEvaluatorStrings.SyntaxErrorBinaryOperatorExpected, new object[0]);
                    }
                    break;
                }
                if (token.Kind == TokenKind.Identifier)
                {
                    string text = token.Text;
                    CompareInfo.GetCompareInfo(CultureInfo.InvariantCulture.LCID);
                    token.Text = EnumMinimumDisambiguation.EnumDisambiguate(text, typeof(T));
                }
                or = token.Kind;
            }
        }