コード例 #1
0
ファイル: BasicTests.cs プロジェクト: Koneke/Yukkuri
        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."
            );
        }
コード例 #2
0
ファイル: mysSymbolSpace.cs プロジェクト: Koneke/Yukkuri
        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;
        }
コード例 #3
0
ファイル: mysSymbolSpace.cs プロジェクト: Koneke/Yukkuri
        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." );
        }
コード例 #4
0
ファイル: EvaluationState.cs プロジェクト: Koneke/Yukkuri
        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++;
        }
コード例 #5
0
ファイル: mysBuiltin.cs プロジェクト: Koneke/Yukkuri
        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 );
        }
コード例 #6
0
ファイル: mysSymbolSpace.cs プロジェクト: Koneke/Yukkuri
 public bool Defined( mysSymbol symbol )
 {
     return Values.ContainsKey( symbol );
 }
コード例 #7
0
ファイル: mysSymbolSpace.cs プロジェクト: Koneke/Yukkuri
 public void Define( mysSymbol symbol, mysToken value )
 {
     Values[ symbol ] = value;
 }
コード例 #8
0
ファイル: mysSymbolSpace.cs プロジェクト: Koneke/Yukkuri
 public void Undefine( mysSymbol symbol )
 {
     Values.Remove( symbol );
 }
コード例 #9
0
ファイル: mysSymbolSpace.cs プロジェクト: Koneke/Yukkuri
 public mysToken GetValue( mysSymbol symbol )
 {
     return Values[ symbol ];
 }
コード例 #10
0
ファイル: EvaluationState.cs プロジェクト: Koneke/Yukkuri
        void preprocessSymbol()
        {
            symbolic = tokens[ current ].Value as mysSymbol;

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