Exemplo n.º 1
0
        internal static List<SchemeObject> lookupSymbolsFromEnv( ref SchemeAST currentAST, ISchemeEnvironment environment )
        {
            List<SchemeObject> ret = new List<SchemeObject>();
            ret.Add( environment.get( (SchemeSymbol) currentAST.currentObject ) );
             // not nice, but it works
              /*  if( ret[0] == null ) // this holds true if the currentObjcet is NOT in the symbol table. Then it might either be an integer or a float and has not been redefined or the function is unknown
            {
                ret.RemoveAt( 0 );
                int intValue;
                var symbol = ( (SchemeSymbol) currentAST.currentObject ).value;
                if( int.TryParse( symbol, out intValue ) )
                {
                    ret.Add( new SchemeInteger( intValue ) );
                }
                else //TODO extend for floats
                {
                    throw new SchemeUndefinedSymbolException( String.Format( "Undefined Symbol: {0}", symbol ) );
                }
            }   */

            foreach (SchemeAST child in currentAST.children)
            {
                if( child.currentObject.GetType() == typeof( SchemeSymbol ) )
                {
                    var symbol = (SchemeSymbol) child.currentObject;
                    ret.Add( environment.get( symbol ) );

                    if( ret[ret.Count -1]== null )  //objcet is not in symbol list, check for integer and float!
                    {
                            throw new SchemeUndefinedSymbolException( String.Format( "Undefined Symbol: {0}", symbol.value ) );
                    }
                }
                else
                {
                    ret.Add( child.currentObject );
                }
            }
            return ret;
        }
Exemplo n.º 2
0
        private bool updateToNextLevelChild(ref SchemeAST currentAst, ISchemeEnvironment environment)
        {
            Type type = currentAst.currentObject.GetType();

            if (type == typeof(SchemeSymbol))
            {
                SchemeType t = environment.get((SchemeSymbol)currentAst.currentObject);
                if (t == null)
                {
                    throw new SchemeUndefinedSymbolException(String.Format("Undefined Symbol: {0}", currentAst.currentObject.ToString()), currentAst.fileName, currentAst.sourceLength, currentAst.sourceOffset);
                }
                Type obj = t.GetType();
                if (obj == typeof(SchemeBuiltInLambda)) // or typeof if. this is needed for parts which should not be evaluated.
                {
                    return false;
                }
                if (obj == typeof(SchemeBuiltInIf))
                {
                    var tmpRoot = new SchemeAST();
                    var condition = currentAst.children[0];
                    var oldParent = condition.parent;

                    tmpRoot.children.Add(condition);
                    condition.parent = tmpRoot;
                    var evaluated = evaluate(ref tmpRoot);    //evaluate the if condition
                    tmpRoot = new SchemeAST(currentAst, evaluated[0]);
                    currentAst.children[0] = tmpRoot;

                    return false;
                }
            }

            foreach (SchemeAST child in currentAst.children)
            {
                if (child.children.Count != 0)
                {
                    currentAst = child;
                    return true;
                }
            }
            return false;
        }
Exemplo n.º 3
0
        private SchemeType getType(ref SchemeAST ast, ISchemeEnvironment environment)
        {
            SchemeObject ret = ast.currentObject;
            if (ast.currentObject.GetType() == typeof(SchemeSymbol))
            {
                ret = environment.get((SchemeSymbol)ret);
            }

            if (!(ret is SchemeType))
            {
                return null;
            }

            return (SchemeType)ret;
        }
Exemplo n.º 4
0
        private ISchemeFunction getFunction(ref SchemeAST ast, ISchemeEnvironment environment)
        {
            SchemeObject ret = ast.currentObject;
            if (ast.currentObject.GetType() == typeof(SchemeSymbol))
            {
                ret = environment.get((SchemeSymbol)ret);
            }

            if (!(ret is ISchemeFunction))
            {
                return null;
            }

            return (ISchemeFunction)ret;
        }