コード例 #1
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        private static IExpression  ParseMultExpression()
        {
            if (Check(FirstExpExp))
            {
                IExpression exp = ParseExpExpression();

                while (Check(new TokenSet(TokenType.Multiply | TokenType.Divide)))
                {
                    TokenType opType = CurrentToken.type;
                    Eat(opType);
                    if (!Check(FirstExpExp))
                    {
                        throw new InvalidSyntaxException("Expected an expression after * or / operator");
                    }
                    IExpression right = ParseExpExpression();

                    switch (opType)
                    {
                    case TokenType.Multiply:
                        exp = new MultExpression(exp, right);
                        break;

                    case TokenType.Divide:
                        exp = new DivExpression(exp, right);
                        break;

                    default:
                        throw new UnexpectedBehaviorException("Expected mult or divide, got: " + opType);
                    }
                }

                return(exp);
            }
            else
            {
                throw new InvalidSyntaxException("Invalid expression");
            }
        }
コード例 #2
0
ファイル: Functions.cs プロジェクト: stantoxt/PipelineBuilder
        public Cone(double radius, double height)
        {
            IExpression fx = new MultExpression(
                new MultExpression(
                    new SubExpression(
                        new ConstantExpression(height),
                        new VariableExpression("v")),
                    new ConstantExpression(radius / height)),
                new CosineExpression(
                    new VariableExpression("u")));
            IExpression fy = new VariableExpression("v");
            IExpression fz = new MultExpression(
                new MultExpression(
                    new SubExpression(
                        new ConstantExpression(height),
                        new VariableExpression("v")),
                    new ConstantExpression(radius / height)),
                new SineExpression(
                    new NegateExpression(
                        new VariableExpression("u"))));

            Init(fx, fy, fz, -Math.PI, Math.PI, 0.0, height);
        }
コード例 #3
0
ファイル: Functions.cs プロジェクト: HK-Zhang/Grains
        public Cone( double radius, double height )
        {
            IExpression fx = new MultExpression(
                                    new MultExpression(
                                        new SubExpression(
                                            new ConstantExpression( height ),
                                            new VariableExpression( "v" ) ),
                                        new ConstantExpression( radius/height ) ),
                                    new CosineExpression(
                                        new VariableExpression( "u" ) ) );
            IExpression fy = new VariableExpression( "v" );
            IExpression fz = new MultExpression(
                                    new MultExpression(
                                        new SubExpression(
                                            new ConstantExpression( height ),
                                            new VariableExpression( "v" ) ),
                                        new ConstantExpression( radius/height ) ),
                                    new SineExpression(
                                        new NegateExpression(
                                            new VariableExpression( "u" ) ) ) );

            Init( fx, fy, fz, -Math.PI, Math.PI, 0.0, height );
        }
コード例 #4
0
ファイル: FunctionParser.cs プロジェクト: HK-Zhang/Grains
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        private static IExpression ParseMultExpression()
        {
            if ( Check( FirstExpExp ) )
            {
                IExpression exp = ParseExpExpression();

                while ( Check( new TokenSet( TokenType.Multiply | TokenType.Divide ) ) )
                {
                    TokenType opType = CurrentToken.type;
                    Eat( opType );
                    if ( !Check( FirstExpExp ) )
                    {
                        throw new InvalidSyntaxException( "Expected an expression after * or / operator" );
                    }
                    IExpression right = ParseExpExpression();

                    switch ( opType )
                    {
                    case TokenType.Multiply:
                        exp = new MultExpression( exp, right );
                        break;

                    case TokenType.Divide:
                        exp = new DivExpression( exp, right );
                        break;

                    default:
                        throw new UnexpectedBehaviorException( "Expected mult or divide, got: " + opType );
                    }
                }

                return exp;
            }
            else
            {
                throw new InvalidSyntaxException( "Invalid expression" );
            }
        }