Exemple #1
0
        public Brackets(ISyntaxNode parent, ref string Input)
            : base(parent)
        {
            Pattern regExPattern =
                "^\\s*" +
                new Group("def", "\\(");

            System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(regExPattern);
            System.Text.RegularExpressions.Match match = regEx.Match(Input);

            if (!match.Success)
            {
                throw new ParseException();
            }

            Input = Input.Remove(0, match.Index + match.Length);

            this.Operand = IRightValue.Parse(this, ref Input);


            Pattern regExClosePattern = "^\\s*\\)";

            regEx = new System.Text.RegularExpressions.Regex(regExClosePattern);
            match = regEx.Match(Input);

            if (!match.Success)
            {
                throw new ParseException();
            }
            Input             = Input.Remove(0, match.Index + match.Length);
            regExClosePattern = "^\\s*\\)";
        }
Exemple #2
0
        public static IBinaryOperator Parse(ISyntaxNode parent, ref string Input, IRightValue firstOperand)
        {
            string temp = Input;

            Pattern regExPattern =
                "^\\s*" +
                new Group("def", "(\\+|\\*|-|/|==|!=|>=|<=|<|>|\\||\\|\\||&|&&|\\^|%|<<|>>)");

            System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(regExPattern);
            System.Text.RegularExpressions.Match match = regEx.Match(Input);

            if (!match.Groups["def"].Success)
            {
                Input = temp;
                return(null);
            }

            Input = Input.Remove(0, match.Index + match.Length);

            string Operator = match.Groups["def"].Value;

            IRightValue secondOperand = IRightValue.Parse(parent, ref Input);

            switch (Operator)
            {
            case "+":
                return(new AdditionOperator(parent, firstOperand, secondOperand));

            case "-":
                return(new SubtractionOperator(parent, firstOperand, secondOperand));

            case "*":
                return(new MultiplicationOperator(parent, firstOperand, secondOperand));

            case "/":
                return(new DivisionOperator(parent, firstOperand, secondOperand));

            case "==":
                return(new EqualOperator(parent, firstOperand, secondOperand));

            case "!=":
                return(new UnequalOperator(parent, firstOperand, secondOperand));

            case ">=":
                return(new GreaterEqualOperator(parent, firstOperand, secondOperand));

            case "<=":
                return(new LessEqualOperator(parent, firstOperand, secondOperand));

            case ">":
                return(new GreaterOperator(parent, firstOperand, secondOperand));

            case "<":
                return(new LessOperator(parent, firstOperand, secondOperand));

            default:
                Input = temp;
                throw new NotImplementedException();
            }
        }