Пример #1
0
        private ExternalFunctionCreator AddExternalFunctions(FunctionDefinition[] functionDefinitions, AST ast)
        {
            List <FunctionDefinition> allFunctionDefinitions = new List <FunctionDefinition>();

            allFunctionDefinitions.AddRange(builtInFunctions);
            allFunctionDefinitions.AddRange(functionDefinitions);

            // HasFunction requires a reference to the SprakRunner
            FunctionDocumentation functionDoc_HasFunction =
                new FunctionDocumentation("Check if a function exists on the object", new string[] { "The name of the function" });

            allFunctionDefinitions.Add(new FunctionDefinition("bool", "HasFunction", new string[] { "string" }, new string[] { "functionName" }, new ExternalFunctionCreator.OnFunctionCall(API_hasFunction), functionDoc_HasFunction));
            FunctionDocumentation functionDoc_ListFunctions =
                new FunctionDocumentation("List all functions on the object", new string[] { });

            allFunctionDefinitions.Add(new FunctionDefinition("array", "ListFunctions", new string[] {  }, new string[] { }, new ExternalFunctionCreator.OnFunctionCall(API_listFunction), functionDoc_ListFunctions));

            ExternalFunctionCreator externalFunctionCreator = new ExternalFunctionCreator(allFunctionDefinitions.ToArray());
            AST functionList = ast.getChild(1);

            foreach (AST externalFunction in externalFunctionCreator.FunctionASTs)
            {
                functionList.addChild(externalFunction);
            }

            return(externalFunctionCreator);
        }
Пример #2
0
        private void construct(TextReader stream, FunctionDefinition[] functionDefinitions, VariableDefinition[] variableDefinitions)
        {
            Debug.Assert(stream != null);
            Debug.Assert(functionDefinitions != null);

            m_compileTimeErrorHandler = new ErrorHandler();
            m_runtimeErrorHandler     = new ErrorHandler();
            m_tokens = Tokenize(stream);
            m_ast    = Parse(m_tokens);
            if (m_compileTimeErrorHandler.getErrors().Count > 0)
            {
                m_compileTimeErrorHandler.printErrorsToConsole(); return;
            }

            AddLocalVariables(m_ast, variableDefinitions);
            ExternalFunctionCreator externalFunctionCreator = AddExternalFunctions(functionDefinitions, m_ast);
            Scope globalScope = CreateScopeTree(m_ast);

            if (m_compileTimeErrorHandler.getErrors().Count > 0)
            {
                m_compileTimeErrorHandler.printErrorsToConsole(); return;
            }

            m_interpreter = new InterpreterTwo(m_ast, globalScope, m_runtimeErrorHandler, externalFunctionCreator);
            m_started     = false;

            //PaintAST(m_ast);
        }
Пример #3
0
 public Interpreter(AST ast, Scope globalScope, ErrorHandler errorHandler, ExternalFunctionCreator externalFunctionCreator)
 {
     m_ast = ast;
     m_errorHandler = errorHandler;
     m_globalScope = globalScope;
     m_currentScope = m_globalScope;
     m_externalFunctionCreator = externalFunctionCreator;
 }
Пример #4
0
 public Interpreter(AST ast, Scope globalScope, ErrorHandler errorHandler, ExternalFunctionCreator externalFunctionCreator)
 {
     m_ast                     = ast;
     m_errorHandler            = errorHandler;
     m_globalScope             = globalScope;
     m_currentScope            = m_globalScope;
     m_externalFunctionCreator = externalFunctionCreator;
 }
Пример #5
0
 public FunctionDefinition(string pReturnType, string pFunctionName, string[] pParameterTypes, string[] pParameterNames, ExternalFunctionCreator.OnFunctionCall pCallback, FunctionDocumentation pFunctionDocumentation)
 {
     returnType = pReturnType;
     functionName = pFunctionName;
     parameterTypes = pParameterTypes;
     parameterNames = pParameterNames;
     callback = pCallback;
     functionDocumentation = pFunctionDocumentation;
 }
Пример #6
0
        public InterpreterTwo(AST ast, Scope globalScope, ErrorHandler errorHandler, ExternalFunctionCreator externalFunctionCreator)
        {
                        #if WRITE_DEBUG_INFO
            Console.WriteLine("\nCreated Interpreter!!");
                        #endif

            m_ast                     = ast;
            m_errorHandler            = errorHandler;
            m_globalScope             = globalScope;
            m_currentScope            = m_globalScope;
            m_externalFunctionCreator = externalFunctionCreator;
            Reset();
        }
Пример #7
0
        private ExternalFunctionCreator AddExternalFunctions(FunctionDefinition[] functionDefinitions, AST ast)
        {
            List <FunctionDefinition> allFunctionDefinitions = new List <FunctionDefinition>();

            allFunctionDefinitions.AddRange(builtInFunctions);
            allFunctionDefinitions.AddRange(functionDefinitions);


            ExternalFunctionCreator externalFunctionCreator = new ExternalFunctionCreator(allFunctionDefinitions.ToArray());
            AST functionList = ast.getChild(1);

            foreach (AST externalFunction in externalFunctionCreator.FunctionASTs)
            {
                functionList.addChild(externalFunction);
            }
            return(externalFunctionCreator);
        }
Пример #8
0
        private void evaluateFunctionScope(AST tree)
        {
            // Define function name
            ReturnValueType returnType   = ExternalFunctionCreator.GetReturnTypeFromString(tree.getChild(0).getTokenString());
            string          functionName = tree.getChild(1).getTokenString();

            Symbol functionScope = new FunctionSymbol(m_currentScope, functionName, returnType, tree);

            m_globalScope.define(functionScope); // all functions are saved in the global scope

            m_currentScope = (Scope)functionScope;
            AST_FunctionDefinitionNode functionCallNode = (AST_FunctionDefinitionNode)(tree);

            functionCallNode.setScope((Scope)functionScope);

            #if WRITE_DEBUG_INFO
            Console.WriteLine("\nDefined function with name " + functionName + " and return type " + returnType);
            #endif

            // Process the body of the function
            evaluateScopeDeclarations(tree.getChild(3));

            m_currentScope = m_currentScope.getEnclosingScope(); // pop scope
        }
Пример #9
0
        private ExternalFunctionCreator AddExternalFunctions(FunctionDefinition[] functionDefinitions, AST ast)
        {
            List<FunctionDefinition> allFunctionDefinitions = new List<FunctionDefinition>();
            allFunctionDefinitions.AddRange(builtInFunctions);
            allFunctionDefinitions.AddRange(functionDefinitions);

            ExternalFunctionCreator externalFunctionCreator = new ExternalFunctionCreator(allFunctionDefinitions.ToArray());
            AST functionList = ast.getChild(1);
            foreach (AST externalFunction in externalFunctionCreator.FunctionASTs)
            {
                functionList.addChild(externalFunction);
            }
            return externalFunctionCreator;
        }
Пример #10
0
        private ExternalFunctionCreator AddExternalFunctions(FunctionDefinition[] functionDefinitions, AST ast)
        {
			List<FunctionDefinition> allFunctionDefinitions = new List<FunctionDefinition>();
            allFunctionDefinitions.AddRange(builtInFunctions);
            allFunctionDefinitions.AddRange(functionDefinitions);
            
			// HasFunction requires a reference to the SprakRunner
			FunctionDocumentation functionDoc_HasFunction =
				new FunctionDocumentation("Check if a function exists on the object", new string[] { "The name of the function" });
			allFunctionDefinitions.Add(new FunctionDefinition("bool", "HasFunction", new string[] { "string" }, new string[] { "functionName" }, new ExternalFunctionCreator.OnFunctionCall(API_hasFunction), functionDoc_HasFunction));

			ExternalFunctionCreator externalFunctionCreator = new ExternalFunctionCreator(allFunctionDefinitions.ToArray());
            AST functionList = ast.getChild(1);

            foreach (AST externalFunction in externalFunctionCreator.FunctionASTs)
            {
                functionList.addChild(externalFunction);
            }

            return externalFunctionCreator;
        }