Ejemplo n.º 1
0
        public Grammar() : this(true) { } //case sensitive by default

        public Grammar(bool caseSensitive)
        {
            _currentGrammar    = this;
            this.CaseSensitive = caseSensitive;
            bool ignoreCase = !this.CaseSensitive;

            LanguageStringComparer = StringComparer.Create(System.Globalization.CultureInfo.InvariantCulture, ignoreCase);
            StringComparisonMode   = CaseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase;
            KeyTerms = new KeyTermTable(LanguageStringComparer);
            //Initialize console attributes
            ConsoleTitle           = Resources.MsgDefaultConsoleTitle;
            ConsoleGreeting        = string.Format(Resources.MsgDefaultConsoleGreeting, this.GetType().Name);
            ConsolePrompt          = ">";
            ConsolePromptMoreInput = ".";
            OperatorMappings       = OperatorUtility.GetDefaultOperatorMappings(caseSensitive);
        }
Ejemplo n.º 2
0
        public static OperatorInfoDictionary GetDefaultOperatorMappings(bool caseSensitive)
        {
            var dict = new OperatorInfoDictionary(caseSensitive);
            int p    = 0; //precedence

            p += 10;
            dict.Add("=", ExpressionType.Assign, p);
            dict.Add("+=", ExpressionType.AddAssignChecked, p);
            dict.Add("-=", ExpressionType.SubtractAssignChecked, p);
            dict.Add("*=", ExpressionType.MultiplyAssignChecked, p);
            dict.Add("/=", ExpressionType.DivideAssign, p);
            dict.Add("%=", ExpressionType.ModuloAssign, p);
            dict.Add("|=", ExpressionType.OrAssign, p);
            dict.Add("&=", ExpressionType.AndAssign, p);
            dict.Add("^=", ExpressionType.ExclusiveOrAssign, p);

            p += 10;
            dict.Add("==", ExpressionType.Equal, p);
            dict.Add("!=", ExpressionType.NotEqual, p);
            dict.Add("<>", ExpressionType.NotEqual, p);

            p += 10;
            dict.Add("<", ExpressionType.LessThan, p);
            dict.Add("<=", ExpressionType.LessThanOrEqual, p);
            dict.Add(">", ExpressionType.GreaterThan, p);
            dict.Add(">=", ExpressionType.GreaterThanOrEqual, p);

            p += 10;
            dict.Add("|", ExpressionType.Or, p);
            dict.Add("or", ExpressionType.Or, p);
            dict.Add("||", ExpressionType.OrElse, p);
            dict.Add("orelse", ExpressionType.OrElse, p);
            dict.Add("^", ExpressionType.ExclusiveOr, p);
            dict.Add("xor", ExpressionType.ExclusiveOr, p);

            p += 10;
            dict.Add("&", ExpressionType.And, p);
            dict.Add("and", ExpressionType.And, p);
            dict.Add("&&", ExpressionType.AndAlso, p);
            dict.Add("andalso", ExpressionType.AndAlso, p);

            p += 10;
            dict.Add("!", ExpressionType.Not, p);
            dict.Add("not", ExpressionType.Not, p);

            p += 10;
            dict.Add("<<", ExpressionType.LeftShift, p);
            dict.Add(">>", ExpressionType.RightShift, p);

            p += 10;
            dict.Add("+", ExpressionType.AddChecked, p);
            dict.Add("-", ExpressionType.SubtractChecked, p);

            p += 10;
            dict.Add("*", ExpressionType.MultiplyChecked, p);
            dict.Add("/", ExpressionType.Divide, p);
            dict.Add("%", ExpressionType.Modulo, p);
            dict.Add("**", ExpressionType.Power, p);

            p += 10;
            dict.Add("??", ExpressionType.Coalesce, p);
            dict.Add("?", ExpressionType.Conditional, p);

            return(dict);
        }//method