Ejemplo n.º 1
0
        /// <summary>
        /// Visit FuncBindAssignment
        /// </summary>
        /// <param name="funcBindAssignment">FuncBindAssignment to visit</param>
        public void VisitFuncBindAssignment(Node funcBindAssignment)
        {
            //Convert FuncBind in a FunctionDef node
            NodeGraphBuilder graphBuilder = new NodeGraphBuilder();

            //Create functionDef node
            Node functionDef = (Node)graphBuilder.DefineNode("FunctionDef");

            //Add identifier of function
            functionDef.Add(funcBindAssignment.ViewAllNodes().ElementAt(0));

            //Add formals
            functionDef.Add(funcBindAssignment.ViewAllNodes().ElementAt(1));

            //Create StatementList to store the single statement in
            Node statementList = (Node)graphBuilder.DefineNode("StatementList");

            statementList.Add(funcBindAssignment.ViewAllNodes().ElementAt(2));
            functionDef.Add(statementList);

            //Visit this functionDefinition
            VisitFunctionDef(functionDef);

            //Add function to SymbolTable
            Node identifier = funcBindAssignment.ViewAllNodes().ElementAt(0);

            SymbolTable.AddFunctionDefinition(identifier.AtomicValue.ToString(), functionDef);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Visit EachStatement
        /// </summary>
        /// <param name="eachStatement">EachStatement to visit</param>
        public void VisitEachStatement(Node eachStatement)
        {
            CreateChildSymbolTable();

            //Store variable in eachstatement
            Node identifier = eachStatement.ViewAllNodes().ElementAt(0);
            Node expression = eachStatement.ViewAllNodes().ElementAt(1);

            SymbolTable.AddVariableDefinition(identifier.AtomicValue.ToString(), expression);

            //Place single statement in list to make visiting easier
            NodeGraphBuilder graphBuilder  = new NodeGraphBuilder();
            Node             statementList = (Node)graphBuilder.DefineNode("StatementList");

            statementList.Add(eachStatement.ViewAllNodes().ElementAt(2));

            //Visit statement
            VisitSubNodes(statementList);

            MoveToParentSymbolTable();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Visits an FunctionDef node
        /// </summary>
        /// <param name="functionDef">FunctionDefinition to visit</param>
        public void VisitFunctionDef(Node functionDef)
        {
            CreateChildSymbolTable();

            //Check Formals (always second element of functiondef)
            Node             Formals      = functionDef.ViewAllNodes().ElementAt(1);
            NodeGraphBuilder graphBuilder = new NodeGraphBuilder();

            foreach (Node formal in Formals.ViewAllNodes())
            {
                //Store variable, but without expression
                Node textExpression = (Node)graphBuilder.DefineNode("TextExpression");
                SymbolTable.AddVariableDefinition(formal.AtomicValue.ToString(), textExpression);
            }

            //Check statements. StatementList is always at second position
            Node statementList = functionDef.ViewAllNodes().ElementAt(2);

            VisitSubNodes(statementList);

            MoveToParentSymbolTable();
        }