Example #1
0
        private static void build_function_calls()
        {
            bool definition = false;

            Visitor.Function_Call current_function_call = null;

            foreach (Visitor.Function_Define function in list_of_functions)
            {
                List <Main> new_list_of_instructions = new List <Main>();
                foreach (Main visitor in function.list_of_instructions)
                {
                    Visitor.Function_Call function_call = visitor as Visitor.Function_Call;
                    if (function_call != null)
                    {
                        definition            = true;
                        current_function_call = function_call;
                    }
                    else
                    {
                        if (definition)
                        {
                            Visitor.Braces_Right braces_right = visitor as Visitor.Braces_Right;
                            if (braces_right == null)
                            {
                                if (visitor.has_value || visitor.GetType() == typeof(Visitor.Variable) || visitor.visitor_type == Main.Visitor_Type.OPERATOR)
                                {
                                    current_function_call.list_of_params.Add(visitor);
                                    continue;
                                }
                                else
                                {
                                    throw new Exception.Assembler(Exception.MainException.Level.ERROR, "Error in function-call: " + visitor.GetType().Name + " does not have any value.", visitor.file_name, visitor.index);
                                }
                            }
                            else
                            {
                                definition = false;
                            }
                        }
                    }

                    new_list_of_instructions.Add(visitor);
                }
                function.list_of_instructions = new_list_of_instructions;
            }
        }
Example #2
0
        private static void build_function_defines(List <Main> list_of_visitors)
        {
            bool definition      = false;
            int  parameter_index = 0;

            list_of_functions = new List <Visitor.Function_Define>();
            Visitor.Function_Define current_function = null;
            foreach (Main visitor in list_of_visitors)
            {
                Visitor.Function_Define function = visitor as Visitor.Function_Define;
                if (function != null)
                {
                    definition      = true;
                    parameter_index = 0;

                    current_function = function;
                    list_of_functions.Add(function);
                }
                else
                {
                    if (definition)
                    {
                        Visitor.Braces_Right braces_right = visitor as Visitor.Braces_Right;
                        if (braces_right == null)
                        {
                            // Ignore left-braces
                            Visitor.Braces_Left braces_left = visitor as Visitor.Braces_Left;
                            if (braces_left == null)
                            {
                                // We only want variables as parameters
                                Visitor.Variable variable = visitor as Visitor.Variable;
                                if (variable != null)
                                {
                                    variable.parameter_index = parameter_index;
                                    parameter_index++;
                                    current_function.list_of_params.Add(variable);
                                }
                                else
                                {
                                    throw new Exception.Assembler(Exception.MainException.Level.ERROR, "Error in function-head: " + visitor.GetType().Name + " should not be in the head.", visitor.file_name, visitor.index);
                                }
                            }
                        }
                        else
                        {
                            definition = false;
                        }
                    }
                    else
                    {
                        bool             found    = false;
                        Visitor.Variable variable = visitor as Visitor.Variable;
                        if (variable != null)
                        {
                            foreach (Visitor.Variable parameter in current_function.list_of_params)
                            {
                                if (variable.name == parameter.name)
                                {
                                    current_function.list_of_instructions.Add(parameter);
                                    found = true;
                                    break;
                                }
                            }
                        }

                        if (!found)
                        {
                            current_function.list_of_instructions.Add(visitor);
                        }
                    }
                }
            }
        }