예제 #1
0
        public override Value Invoke( List Arguments )
        {
            var list = Arguments.GetValues();
            if ( list[ 0 ] is Boolean )
            {
                var temp = new List<float>();
                for ( int i = 1 ; i < list.Count ; ++i )
                {
                    if ( list[ i ] is Number ) temp.Add( (float)( (Number)list[ i ] ).Val );
                }
                Polygon = new Polygon( ( (Boolean)list[ 0 ] ).Val, temp.ToArray() );
            } else throw new Exception( "First argument of the polygon constructor must be a boolean" );

            return this;
        }
예제 #2
0
        public override List<Token> Tokenize()
        {
            var rpn = new List<Token>();
            if ( op is DotOperator ) //Special case for the dot operator which needs to be arranged like a sufix unary
            {
                if ( first is Expression || first is ExpressionSequence ) rpn.AddRange( first.Tokenize() );
                else rpn.Add( first );
                rpn.Add( op );
                if ( second is Expression || second is ExpressionSequence ) rpn.AddRange( second.Tokenize() );
                else if ( !( second is NoValue ) ) rpn.Add( second );
            } else
            {
                if ( first is Expression || first is ExpressionSequence ) rpn.AddRange( first.Tokenize() );
                else rpn.Add( first );
                if ( second is Expression || second is ExpressionSequence ) rpn.AddRange( second.Tokenize() );
                else if ( !( second is NoValue ) ) rpn.Add( second );
                rpn.Add( op );
            }

            return rpn;
        }
예제 #3
0
        private static IEnumerable<string> SplitString( string Exp )
        {
            int commentStart;
            while ( ( commentStart = Exp.IndexOf( "//" ) ) != -1 )
            {
                int end = Exp.IndexOf( '\n', commentStart );
                if ( end != -1 )
                {
                    Exp = Exp.Remove( commentStart, end - commentStart );
                } else Exp = Exp.Remove( commentStart );
            }
            var expression = new StringBuilder( Exp );
            expression.Replace( '\n', ' ' );
            expression.Replace( '\t', ' ' );
            expression.Replace( '\r', ' ' );
            expression.Replace( @"\n", '\n' + "" );
            expression.Replace( @"\r", '\r' + "" );
            expression.Replace( @"\t", '\t' + "" );
            var alreadyDone = new List<bool>();
            //Stores the already processed operators so the ones like ++ and + don't get processed twice
            bool inQuote = false;
            for ( int i = 0 ; i < expression.Length ; ++i ) //Quotation pass
            {
                if ( expression[ i ] == '"' ) inQuote = inQuote ? false : true;
                if ( inQuote && expression[ i ] == ' ' ) expression[ i ] = (char)7;
                alreadyDone.Add( inQuote );
            }
            for ( int i = 0 ; i < expression.Length ; ++i ) //Decimal number pass
            {
                if ( expression[ i ] == '.' && GetCharType( expression[ i - 1 ] ) == ParseState.Numbers &&
                    GetCharType( expression[ i + 1 ] ) == ParseState.Numbers )
                {
                    alreadyDone[ i ] = true;
                }
            }

            List<string> operatorList = Operators.RepresentationDictionary.Values.ToList();
            operatorList.Sort( new Comparison<string>( ( X, Y ) => Y.Length - X.Length ) );
            foreach ( var t in operatorList )
            {
                for ( int j = 0 ; j <= expression.Length - t.Length ; j++ )
                {
                    if ( !alreadyDone[ j ] && expression.ToString( j, t.Length ) == t )
                    {
                        for ( int k = 0 ; k < t.Length ; ++k )
                        {
                            alreadyDone[ j + k ] = true;
                        }
                        alreadyDone.Insert( j + t.Length, true );
                        alreadyDone.Insert( j, true );
                        expression = expression.Insert( j + t.Length, " " );
                        expression = expression.Insert( j, " " );
                    }
                }
            }

            var temp = new LinkedList<string>( expression.ToString().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries ) );
            for ( LinkedListNode<string> node = temp.First ; node != null ; node = node.Next )
            {
                node.Value = node.Value.Replace( '\a', ' ' );
            }
            return temp;
        }