Ejemplo n.º 1
0
        void AddLocalVariables(AST ast, VariableDefinition[] variableDefinitions)
        {
            AST nodeForDefiningGlobalVariables = ast.getChild(0).getChild(0);

            if(variableDefinitions == null) { return; }

            foreach(VariableDefinition vd in variableDefinitions) {

                Token token = new Token(Token.TokenType.VAR_DECLARATION,"<VAR_DECL>", ast.getToken().LineNr, ast.getToken().LinePosition);

                AST_VariableDeclaration declarationTree =
                    new AST_VariableDeclaration(token,
                                                vd.initValue.getReturnValueType(),
                                                vd.variableName);

                if(vd.initValue != null)
                {
                    AST assignmentTree = CreateAssignmentTreeFromInitValue(vd.variableName, vd.initValue);
                    AST declarationAndAssignmentTree = new AST(new Token(Token.TokenType.STATEMENT_LIST, "<DECLARATION_AND_ASSIGNMENT>", declarationTree.getToken().LineNr, declarationTree.getToken().LinePosition));
                    declarationAndAssignmentTree.addChild(declarationTree);
                    declarationAndAssignmentTree.addChild(assignmentTree);
                    nodeForDefiningGlobalVariables.addChild(declarationAndAssignmentTree);
                }
                else
                {
                    nodeForDefiningGlobalVariables.addChild(declarationTree);
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 public SprakRunner(TextReader stream, FunctionDefinition[] functionDefinitions, VariableDefinition[] variableDefinitions)
 {
     construct(stream, functionDefinitions, variableDefinitions);
 }