Exemplo n.º 1
0
            public void Parse(ref string[] program)
            {
                string ifstring = ParseUtils.GetToken(ref program);

                if (!ifstring.Equals("if", StringComparison.Ordinal))
                {
                    throw new ParseException("If Statement should always start with if, found " + ifstring + " instead.");
                }

                string openbracket = ParseUtils.GetToken(ref program);

                if (!openbracket.Equals("(", StringComparison.Ordinal))
                {
                    throw new ParseException("if statement must be followed by a condition in brackets, found " + openbracket + " instead.");
                }
                _Condition = ConditionBuilder.Parse(ref program);
                string closebracket = ParseUtils.GetToken(ref program);

                if (!closebracket.Equals(")", StringComparison.Ordinal))
                {
                    throw new ParseException("if statement found a conditional expression without a closing bracket, found " + closebracket + " instead.");
                }

                _Block = new RuleBlock();
                _Block.Parse(ref program);
            }
Exemplo n.º 2
0
 public void Parse(ref string[] program)
 {
     _Arg1 = ConditionBuilder.Parse(ref program);
 }
Exemplo n.º 3
0
        public static ConditionalExpression Parse(ref string[] program)
        {
            ConditionalExpression ret  = null;
            Expression            expr = null;

            string    token1 = ParseUtils.PeekToken(program);
            TokenType type1  = WooScript.GetTokenType(token1);

            if (token1.Equals("(", StringComparison.Ordinal))
            {
                ret = new ConditionalBrackets();
                (ret as ConditionalBrackets).Parse(ref program);
            }
            else if (type1 == TokenType.UnaryBooleanOp)
            {
                ret = WooScript.GetUnaryBooleanOp(token1);
                (ret as UnaryBooleanOp).Parse(ref program);
            }
            else if (type1 == TokenType.floatVar ||
                     type1 == TokenType.floatNum ||
                     type1 == TokenType.floatFunction)
            {
                expr = ExpressionBuilder.Parse(ref program);
            }
            else
            {
                throw new ParseException("Unrecognised expression \"" + token1 + "\"");
            }

            string    token2 = ParseUtils.GetToken(ref program);
            TokenType type2  = WooScript.GetTokenType(token2);

            if (type2 == TokenType.ConditionalOp)
            {
                if (type1 != TokenType.floatNum && type1 != TokenType.floatVar && type1 != TokenType.floatFunction)
                {
                    throw new ParseException("Conditional operation only takes floating point parameters");
                }

                ConditionalOp condOp = WooScript.GetConditionalOp(token2);
                condOp._Arg1 = expr;
                Expression arg2 = ExpressionBuilder.Parse(ref program);

                if (arg2.GetExpressionType() != VarType.varFloat)
                {
                    throw new ParseException("Conditional operation only takes floating point parameters");
                }

                condOp._Arg2 = arg2;

                // no need for precedence check on conditional operator
                ret = condOp;

                string    token3 = ParseUtils.PeekToken(program);
                TokenType type3  = WooScript.GetTokenType(token3);
                if (type3 == TokenType.BooleanOp)
                {
                    BooleanOp boolOp = WooScript.GetBooleanOp(token3);
                    boolOp._Arg1 = condOp;

                    ConditionalExpression condArg2 = ConditionBuilder.Parse(ref program);
                    boolOp._Arg2 = condArg2;

                    // operator precedence check
                    if (condArg2 is BooleanOp)
                    {
                        if ((condArg2 as BooleanOp).GetPrecedence() < boolOp.GetPrecedence())
                        {
                            // shuffle args
                            boolOp._Arg2 = (condArg2 as BooleanOp)._Arg1;
                            (condArg2 as BooleanOp)._Arg1 = boolOp;
                            boolOp = (condArg2 as BooleanOp);
                        }
                    }

                    ret = boolOp;
                }
            }

            if (ret == null)
            {
                throw new ParseException("Malformed conditional expression, expected conditional operation");
            }
            return(ret);
        }
Exemplo n.º 4
0
 public void Parse(ref string[] program)
 {
     _ConditionalExpression = ConditionBuilder.Parse(ref program);
 }