Inheritance: Value
Exemplo n.º 1
0
 public override Value Invoke( List Arguments )
 {
     var list = Arguments.GetValues();
     if ( list[ 0 ] is Function ) onLoad = list[ 0 ] as Function;
     if ( list[ 1 ] is Function ) onUpdate = list[ 1 ] as Function;
     Firefly.Initialize( 800, 500, "Firefly Window", LoadEventInterface, true );
     return this;
 }
Exemplo n.º 2
0
 public override List<Token> Tokenize()
 {
     var returnList = new List<Token>();
     for (TokenListNode node = list.First; node != null; node = node.Next)
     {
         returnList.AddRange(((Value) node.Value).Tokenize());
     }
     return returnList;
 }
Exemplo n.º 3
0
 public Value Output( List Arguments )
 {
     foreach ( var val in Arguments.GetValues() )
     {
         Console.Write( val );
     }
     Console.WriteLine();
     return NoValue.Value;
 }
Exemplo n.º 4
0
        public Value SetPolygons( List Arguments )
        {
            var fillPolys = FilledPoly.ToArray<SLPolygon>();
            var outlinePolys = OutlinePoly.ToArray<SLPolygon>();

            Shape.FilledPolygons = new LinkedList<Polygon>( fillPolys.Select( X => X.Polygon ) );
            Shape.OutlinePolygons = new LinkedList<Polygon>( outlinePolys.Select( X => X.Polygon ) );
            Shape.SetPolygons();

            return NoValue.Value;
        }
Exemplo n.º 5
0
 public virtual Value Invoke( List Arguments )
 {
     if ( Identifiers.ContainsKey( "Constructor" ) )
     {
         Value constructor = Identifiers[ "Constructor" ].ReferencingValue;
         if ( constructor is IInvokable )
         {
             ( constructor as IInvokable ).Invoke( Arguments );
         }
     }
     return this;
 }
Exemplo n.º 6
0
        public override Value Invoke( List Arguments )
        {
            Shape = new ColoredShape();
            Firefly.AddToRenderList( Shape );
            FilledPoly = new Array();
            OutlinePoly = new Array();
            Identifiers[ "FilledPolygons" ] = new Reference( FilledPoly );
            Identifiers[ "OutlinePolygons" ] = new Reference( OutlinePoly );
            Identifiers[ "SetPolygons" ] = new Reference( new ExternalFunction( "SetPolygons", false, SetPolygons ) );
            Identifiers[ "X" ] = new Reference( new ExternalProperty( "X", false, XChange, () => new Number( Shape.X ) ) );
            Identifiers[ "Y" ] = new Reference( new ExternalProperty( "Y", false, YChange, () => new Number( Shape.Y ) ) );
            Identifiers[ "Rotation" ] = new Reference( new ExternalProperty( "Rotation", false, X => Shape.Rotation = (float)( (Number)X ).Val, () => new Number( Shape.Rotation ) ) );

            return this;
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
0
 public override Value Invoke( List Arguments )
 {
     if ( Arguments.Arr.Count == 3 )
     {
         var list = Arguments.GetValues();
         Value first = list[ 0 ], second = list[ 1 ], third = list[ 2 ];
         if ( first is Number && second is Number && third is Number )
         {
             red = first as Number;
             green = second as Number;
             blue = third as Number;
             return this;
         }
     }
     throw new Exception( "Color constructor takes 3 numbers" );
 }
Exemplo n.º 9
0
 public Value LocationOf( List Arguments )
 {
     var adresses = Arguments.Arr.OfType<Reference>().Select( Reference => new Number( Reference.Index ) );
     return new Array( adresses.Select( X => new Reference( X ) ).ToList() );
 }
Exemplo n.º 10
0
 public static Value ParseInfixString( string Infix )
 {
     var tokens = new TokenList();
     IEnumerable<string> array = SplitString( Infix );
     foreach ( string str in array )
     {
         switch ( GetCharType( str[ 0 ] ) )
         {
             case ParseState.Letters:
                 if ( str[ 0 ] == '"' )
                 {
                     tokens.Add( new String( str.Substring( 1, str.Length - 2 ) ) );
                 } else
                 {
                     if ( Operators.OperatorDictionary.ContainsKey( str ) )
                     {
                         tokens.Add( (Token)Activator.CreateInstance( Operators.OperatorDictionary[ str ] ) );
                     } else
                     {
                         switch ( str )
                         {
                             case "true":
                                 tokens.Add( new Boolean( true ) );
                                 break;
                             case "false":
                                 tokens.Add( new Boolean( false ) );
                                 break;
                             default:
                                 tokens.Add( new Identifier( str ) );
                                 break;
                         }
                     }
                 }
                 break;
             case ParseState.Numbers:
                 tokens.Add( new Number( double.Parse( str, CultureInfo.InvariantCulture ) ) );
                 break;
             case ParseState.Signs:
                 string str1 = str;
                 Func<BracketType, bool> fn = ( X => Operators.RepresentationDictionary[ X.OpeningBracket ] == str1 );
                 if ( Operators.Brackets.Any( fn ) )
                 {
                     if ( str1 == "[" && !( tokens.Last.Value is Identifier ) && !( tokens.Last.Value is ParenthesisClosed ) ) tokens.Add( new MakeArray() );
                     else tokens.Add( (Token)Activator.CreateInstance( Operators.Brackets.First( fn ).SpecialOperator ) );
                     tokens.Add( new ParenthesisOpen() );
                 } else if ( Operators.Brackets.Any( X => Operators.RepresentationDictionary[ X.ClosingBracket ] == str1 ) )
                 {
                     tokens.Add( new ParenthesisClosed() );
                 } else
                 {
                     if ( tokens.Last.Value is Identifier && str1 == "(" )
                     {
                         tokens.Add( new InvokeOperator() );
                         tokens.Add( new ParenthesisOpen() );
                     } else if ( !( tokens.Last.Value is Number || tokens.Last.Value is ParenthesisClosed || tokens.Last.Value is Identifier ) && str1 == "-" )
                     {
                         tokens.Add( new Number( 0 ) );
                         tokens.Add( new Subtraction() );
                     } else if ( Operators.OperatorDictionary.ContainsKey( str1 ) )
                     {
                         tokens.Add( (Operator)Activator.CreateInstance( Operators.OperatorDictionary[ str1 ] ) );
                     } else
                     {
                         tokens.Add( new Unidentified() );
                     }
                 }
                 break;
         }
     }
     originalTokenOrder = tokens.ToLinkedList().ToList();
     Value test = Expression.CreateValueFromExpression( tokens );
     return test;
 }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
0
 public Value Random( List Arguments )
 {
     return new Number( random.NextDouble() );
 }
Exemplo n.º 13
0
 public CodeBlock( List<Token> Code )
 {
     value = Code;
 }
Exemplo n.º 14
0
 public Value Tan( List Arguments )
 {
     if ( Arguments.GetValue( 0 ) is Number )
         return new Number( Math.Tan( ( (Number)Arguments.GetValue( 0 ) ).Val ) );
     throw new Exception( "Tan function takes only a number" );
 }
Exemplo n.º 15
0
        public static void Run( List<Token> Code )
        {
            StandardLibrary.Load();
            Scope defaultScope = StandardLibrary.Library;
            GlobalScope = defaultScope;
            scopeList.AddLast( defaultScope );

            Runtime = true;
            timer = new Stopwatch();
            timer.Start();

            new CodeBlock( Code ).Run();

            timer.Stop();
        }
Exemplo n.º 16
0
 public Value Clear( List Arguments )
 {
     Console.Clear();
     return NoValue.Value;
 }
Exemplo n.º 17
0
 public Value Input( List Arguments )
 {
     return new String( Console.ReadLine() );
 }
Exemplo n.º 18
0
 public Value Initialize( List Arguments )
 {
     return new SLWindow().Invoke( Arguments );
 }
Exemplo n.º 19
0
 public Type( Type BaseClass, List<Token> Code )
     : base(Code)
 {
     Identifiers = BaseClass.Identifiers.Clone();
     Type = CodeBlockType.Type;
 }
Exemplo n.º 20
0
 public CodeBlock( Expression Code )
 {
     value = Code.Tokenize();
 }
Exemplo n.º 21
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;
        }
Exemplo n.º 22
0
 public List( List<Value> List )
 {
     Arr = List;
 }