Beispiel #1
0
        public void IntegralTests()
        {
            int testValue = 10;

            mysSymbol x = new mysSymbol( "x" );

            mysharp.mysREPL REPL = new mysREPL();
            REPL.State.Global.Define( x, new mysToken( testValue ) );

            mysSymbol x2 = new mysSymbol( "x" );

            Debug.Assert(
                REPL.State.Global.Defined( x ),
                "Symbol \"x\" not defined."
            );

            Debug.Assert(
                REPL.State.Global.GetValue( x ).Type == typeof(int),
                "\"x\" not reported as integral-type."
            );

            mysToken i = REPL.State.Global.GetValue( x );

            Debug.Assert(
                i != null,
                "\"x\" reported as but not actually integral-type."
            );

            Debug.Assert(
                (int)i.Value == testValue,
                "Value of \"x\" doesn't match testValue."
            );
        }
Beispiel #2
0
        public mysSymbol Create( string symbolString )
        {
            if ( symbols.ContainsKey( symbolString ) ) {
                throw new ArgumentException("Symbol already exists.");
            }

            mysSymbol newSymbol = new mysSymbol( symbolString );
            symbols.Add( symbolString, newSymbol );

            return newSymbol;
        }
Beispiel #3
0
        public static mysToken EvaluateSymbol(
			mysSymbol symbol,
			Stack<mysSymbolSpace> spaceStack
		)
        {
            Stack<mysSymbolSpace> evaluationStack = spaceStack.Clone();

            while ( evaluationStack.Count > 0 ) {
                mysSymbolSpace space = evaluationStack.Pop();

                if ( space.Defined( symbol ) ) {
                    return space.GetValue( symbol );
                }
            }

            throw new ArgumentException( "Symbol isn't defined." );
        }
Beispiel #4
0
        public void Step()
        {
            // we use this to keep track of the original symbol (if the current
            // token is one), so we can refer back to the symbol given in the
            // code, even after dereferencing it internally.
            symbolic = null;

            // where is our quote check right now..?

            if ( tokens[ current ].Type == typeof(mysSymbol) ) {
                preprocessSymbol();
            }

            if (
                tokens[ current ].Type == typeof(mysFunctionGroup) &&
                !tokens[ current ].Quoted
            ) {
                resolveFunctionGroup();
            }

            if (
                tokens[ current ].Type == typeof(clrFunctionGroup) &&
                !tokens[ current ].Quoted
            ) {
                resolveClrFunctionGroup();
            }

            if (
                tokens[ current ].Type == typeof(mysFunction) ||
                tokens[ current ].Type == typeof(mysBuiltin)
            ) {
                handleFunction();
            }
            else if ( tokens[ current ].Type == typeof(clrFunction ) ) {
                handleClrFunction();
            }

            current++;
        }
Beispiel #5
0
        public static void AddVariant(
			string name,
			mysFunction variant,
			mysSymbolSpace global
		)
        {
            mysSymbol symbol = new mysSymbol( name );
            mysFunctionGroup fg;

            if ( !global.Defined( symbol ) ) {
                global.Define(
                    symbol,
                    new mysToken( new mysFunctionGroup() )
                );
            }

            fg = global
                .GetValue( new mysSymbol( name ) )
                .Value as mysFunctionGroup
            ;

            fg.Variants.Add( variant );
        }
Beispiel #6
0
 public bool Defined( mysSymbol symbol )
 {
     return Values.ContainsKey( symbol );
 }
Beispiel #7
0
 public void Define( mysSymbol symbol, mysToken value )
 {
     Values[ symbol ] = value;
 }
Beispiel #8
0
 public void Undefine( mysSymbol symbol )
 {
     Values.Remove( symbol );
 }
Beispiel #9
0
 public mysToken GetValue( mysSymbol symbol )
 {
     return Values[ symbol ];
 }
Beispiel #10
0
        void preprocessSymbol()
        {
            symbolic = tokens[ current ].Value as mysSymbol;

            if ( !tokens[ current ].Quoted ) {
                tokens[ current ] =
                    (tokens[ current ].Value as mysSymbol)
                    .Value( spaceStack )
                ;
            }
        }