Esempio n. 1
0
        public procedure_header NewProcedureHeader(attribute_list attrlist, procedure_header nprh, procedure_attribute forw, LexLocation loc)
        {
            if (nprh.proc_attributes == null) 
				nprh.proc_attributes = new procedure_attributes_list();
            nprh.proc_attributes.Add(forw, forw.source_context); 
			nprh.attributes = attrlist;
			nprh.source_context = loc;
            return nprh;
        }
Esempio n. 2
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public procedure_definition(procedure_header _proc_header,proc_block _proc_body,SourceContext sc)
		{
			this._proc_header=_proc_header;
			this._proc_body=_proc_body;
			source_context = sc;
		}
		public void visit(procedure_header _procedure_header)
		{
			bw.Write((Int16)41);
			write_procedure_header(_procedure_header);
		}
        public override void visit(SyntaxTree.function_header _function_header)
        {
            current_function_header = _function_header;
            hard_node_test_and_visit(_function_header.name);
            current_function_header = null;
            if (context.converted_template_type != null)
            {
                return;
            }
            if (_function_header.template_args != null)
            {
                visit_generic_params(context.top_function, _function_header.template_args.idents);
            }
            SymbolInfo si = context.create_special_names();
            weak_node_test_and_visit(_function_header.parameters);
			type_node tn = null;
            if (_function_header.return_type == null)
            {
            	if (context.top_function.IsOperator)
                    AddError(get_location(_function_header), "FUNCTION_NEED_RETURN_TYPE");
            }
            if (_function_header.return_type != null)
            {
            	check_parameter_on_complex_type(_function_header.return_type);
            	tn = convert_strong(_function_header.return_type);
            	check_for_type_allowed(tn,get_location(_function_header.return_type));
                if (_function_header.return_type is function_header || _function_header.return_type is procedure_header)
                    check_delegate_on_generic_parameters(tn as common_type_node, get_location(_function_header.return_type));
            }
            //(ssyy) moved up, так как при проверке аттрибута override надо знать тип возвращаемого значения
            context.top_function.return_value_type = tn;
            assign_doc_info(context.top_function,_function_header);
            if (_function_header.attributes != null)
            {
            	make_attributes_for_declaration(_function_header, context.top_function);
            }
            if (context.converted_type != null && has_dll_import_attribute(context.top_function))
                AddError(get_dll_import_attribute(context.top_function).location, "DLLIMPORT_ATTRIBUTE_CANNOT_BE_APPLIED_TO_METHOD");
            if (_function_header.name.class_name != null) 
            	with_class_name = true;
            if (_function_header.class_keyword && !has_static_attr(_function_header.proc_attributes.proc_attributes))
            {
                SyntaxTree.procedure_attribute pa = new SyntaxTree.procedure_attribute(PascalABCCompiler.SyntaxTree.proc_attribute.attr_static);
                pa.source_context = _function_header.source_context;
                _function_header.proc_attributes.proc_attributes.Add(pa);
            }
            weak_node_test_and_visit(_function_header.proc_attributes);
            if (context.top_function.IsOperator)
            {
                //if (cmmn == null)
                //{
                //    throw new OverloadOperatorMustBeStaticFunction(get_location(_function_header), context.top_function);
                //}
                if (context.top_function is common_method_node)
                {
                    common_method_node cmmn = context.top_function as common_method_node;
                    if (cmmn.polymorphic_state != SemanticTree.polymorphic_state.ps_static)
                    {
                        AddError(get_location(_function_header), "OVERLOADED_OPERATOR_MUST_BE_STATIC_FUNCTION");
                    }

                    if ((cmmn.name == compiler_string_consts.implicit_operator_name || cmmn.name == compiler_string_consts.explicit_operator_name))
                    {
                        if (!convertion_data_and_alghoritms.eq_type_nodes(tn, cmmn.comperehensive_type as type_node) && !convertion_data_and_alghoritms.eq_type_nodes(cmmn.comperehensive_type as type_node, cmmn.parameters[0].type))
                        {
                            AddError(get_location(_function_header.return_type), "RETURN_VALUE_SHOULD_HAVE_TYPE_{0}", (cmmn.comperehensive_type as type_node).PrintableName);
                        }
                        else if (convertion_data_and_alghoritms.eq_type_nodes(tn, cmmn.parameters[0].type))
                        {
                            AddError(get_location(_function_header), "CIRCURAL_TYPE_CONVERSION_DEFINITION");
                        }
                    }
                    else
                    {
                        int expected_params = 2;
                        if (cmmn.name == "not")
                            expected_params = 1;
                        if ((cmmn.name == "+" || cmmn.name == "-"))
                        {
                            if (cmmn.parameters.Count != 2 && cmmn.parameters.Count != 1)
                                AddError(new SimpleSemanticError(cmmn.loc, "OPERATORS_SHOULD_HAVE_1_OR_2_PARAMETERS"));
                        }
                        else if (cmmn.parameters.Count != expected_params)
                        {
                            if (expected_params==1)
                                AddError(new SimpleSemanticError(cmmn.loc, "OPERATOR_SHOULD_HAVE_1_PARAMETER"));
                            else AddError(new SimpleSemanticError(cmmn.loc, "OPERATOR_SHOULD_HAVE_2_PARAMETERS"));
                        }
                        bool has_types = false;
                        foreach (parameter p in cmmn.parameters)
                        {
                            type_node ptn = p.type;
                            if (ptn.is_generic_type_instance)
                                ptn = ptn.original_generic;
                            if (ptn == cmmn.cont_type)
                                has_types = true;
                        }
                        if (!has_types)
                            AddError(new SimpleSemanticError(cmmn.loc, "LEAST_ONE_PARAMETER_TYPE_SHOULD_EQ_DECLARING_TYPE_{0}",cmmn.cont_type.name));
                    }
                }
                else if (context.top_function is common_namespace_function_node)
                {
                    common_namespace_function_node cnfn = context.top_function as common_namespace_function_node;

                    if ((cnfn.name == compiler_string_consts.implicit_operator_name || cnfn.name == compiler_string_consts.explicit_operator_name))
                    {
                        if (cnfn.parameters.Count != 1)
                            AddError(new SimpleSemanticError(cnfn.loc,"EXTENSION_METHODS_MUST_HAVE_LEAST_ONE_PARAMETER"));
                        if (cnfn.ConnectedToType == null)
                            AddError(new SimpleSemanticError(cnfn.loc, "OPERATOR_SHOULD_BE_EXTENSION_METHOD"));
                        if (!convertion_data_and_alghoritms.eq_type_nodes(tn, cnfn.ConnectedToType) && !convertion_data_and_alghoritms.eq_type_nodes(cnfn.ConnectedToType as type_node, cnfn.parameters[0].type))
                        {
                            AddError(get_location(_function_header.return_type), "RETURN_VALUE_SHOULD_HAVE_TYPE_{0}", (cnfn.ConnectedToType as type_node).PrintableName);
                        }
                        else if (convertion_data_and_alghoritms.eq_type_nodes(tn, cnfn.parameters[0].type))
                        {
                            AddError(get_location(_function_header), "CIRCURAL_TYPE_CONVERSION_DEFINITION");
                        }
                    }
                    else
                    {
                        int expected_params = 2;
                        if (cnfn.name == "not")
                            expected_params = 1;
                        if (cnfn.name == "+" || cnfn.name == "-")
                        {
                            if (cnfn.parameters.Count != 2 && cnfn.parameters.Count != 1)
                                AddError(new SimpleSemanticError(cnfn.loc, "OPERATORS_SHOULD_HAVE_1_OR_2_PARAMETERS"));
                        }
                        else if (cnfn.parameters.Count != expected_params)
                        {
                            if (expected_params == 1)
                                AddError(new SimpleSemanticError(cnfn.loc, "OPERATOR_SHOULD_HAVE_1_PARAMETER"));
                            else AddError(new SimpleSemanticError(cnfn.loc, "OPERATOR_SHOULD_HAVE_2_PARAMETERS"));
                        }
                        bool has_types = false;
                        foreach (parameter p in cnfn.parameters)
                        {
                            type_node ptn = p.type;
                            if (ptn.is_generic_type_instance)
                                ptn = ptn.original_generic;
                            if (cnfn.ConnectedToType != null && (ptn == cnfn.ConnectedToType || ptn == cnfn.ConnectedToType.original_generic))
                                has_types = true;
                        }
                        if (cnfn.ConnectedToType == null)
                            AddError(new SimpleSemanticError(cnfn.loc, "OPERATOR_SHOULD_BE_EXTENSION_METHOD"));
                        if (!has_types)
                            AddError(new SimpleSemanticError(cnfn.loc, "LEAST_ONE_PARAMETER_TYPE_SHOULD_EQ_DECLARING_TYPE_{0}",cnfn.ConnectedToType.name));
                    }
                }
            }
			with_class_name = false;
			if (context.top_function != null && context.top_function is common_namespace_function_node && (context.top_function as common_namespace_function_node).ConnectedToType != null && !context.top_function.IsOperator)
            {
                concrete_parameter_type cpt = concrete_parameter_type.cpt_none;
                SemanticTree.parameter_type pt = PascalABCCompiler.SemanticTree.parameter_type.value;
                if ((context.top_function as common_namespace_function_node).ConnectedToType.is_value_type)
                {
                    cpt = concrete_parameter_type.cpt_var;
                    pt = PascalABCCompiler.SemanticTree.parameter_type.var;
                }
                
                type_node cur_tn = (context.top_function as common_namespace_function_node).ConnectedToType;
                /*if (cur_tn.is_generic_type_definition && cur_tn is compiled_type_node)
                {
                    List<type_node> instance_params = new List<type_node>();
                    compiled_type_node cur_ctn = cur_tn as compiled_type_node;
                    for (int i = 0; i < cur_ctn.instance_params.Count; i++)
                    {
                        instance_params.Add(find_type(cur_ctn.instance_params[i].name, null));
                    }
                    cur_tn = cur_tn.get_instance(instance_params);
                }*/
                type_node self_type = cur_tn;
                if (context.top_function.generic_params != null && self_type.is_generic_type_definition)
                {
                    self_type = self_type.get_instance(context.top_function.get_generic_params_list());
                }
                if (!has_extensionmethod_attr(_function_header.proc_attributes.proc_attributes))
                {
                    common_parameter cp = new common_parameter(compiler_string_consts.self_word, self_type, pt,
                                                                                context.top_function, cpt, null, null);
                    context.top_function.parameters.AddElementFirst(cp);
                    context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(cp));
                }
            }
            CheckOverrideOrReintroduceExpectedWarning(get_location(_function_header));
            common_type_node common_converted_type_tmp = context.converted_type;
            compiled_type_node compiled_converted_type_tmp = context.converted_compiled_type;
            common_namespace_function_node cnfn2 = context.top_function as common_namespace_function_node;
            if (cnfn2 != null && cnfn2.ConnectedToType != null)
            {
                if (cnfn2.ConnectedToType is compiled_type_node)
                    context.converted_compiled_type = cnfn2.ConnectedToType as compiled_type_node;
                else if (cnfn2.ConnectedToType is common_type_node)
                    context.converted_type = cnfn2.ConnectedToType as common_type_node;
            }
                
            bool unique = context.close_function_params(body_exists);
            context.converted_type = common_converted_type_tmp;
            context.converted_compiled_type = compiled_converted_type_tmp;
            if (context.top_function.return_value_type == null)
                AddError(get_location(_function_header), "FUNCTION_NEED_RETURN_TYPE");
            if (_function_header.where_defs != null)
            {
                if (unique)
                {
                    visit_where_list(_function_header.where_defs);
                }
                else
                {
                    AddError(get_location(_function_header.where_defs), "WHERE_SECTION_MUST_BE_ONLY_IN_FIRST_DECLARATION");
                }
            }
            if (context.converted_type != null && context.converted_type.IsInterface)
            {
                if (body_exists)
                {
                    AddError(new InterfaceFunctionWithBody(get_location(_function_header)));
                }
                common_method_node cmnode = context.top_function as common_method_node;
                context.set_virtual_abstract(cmnode);
            }
            convertion_data_and_alghoritms.create_function_return_variable(context.top_function, si);

            /*if (_function_header.name != null && context.converted_compiled_type != null && context.top_function is common_namespace_function_node)
            {
                if (context.FindMethodToOverride(context.top_function as common_namespace_function_node) != null)
                    AddError(new CanNotDeclareExtensionMethodAsOverrided(get_location(_function_header)));
            }*/
            //TODO: Разобрать подробнее.
            if (!body_exists)
            {
                if (_function_header.name.class_name != null && context.converted_explicit_interface_type != null)
                {
                    AddError(get_location(_function_header), "EXPLICIT_IMPLEMENTATION_EXPECTED");
                }
                if ((context.top_function.semantic_node_type == semantic_node_type.common_method_node)
                    || ((context.func_stack_size_is_one()) && (_is_interface_part)))
                {
                    context.leave_block();
                }
                
            }
            body_exists = false;
        }
Esempio n. 5
0
        public procedure_header NewProcfuncHeading(procedure_header ph)
        {
            ph.name.explicit_interface_name = ph.name.class_name;
			ph.name.class_name = null;
            return ph;
        }
Esempio n. 6
0
 public static procedure_definition BuildShortProcDefinition(formal_parameters fp, procedure_attributes_list att, method_name name, statement st, SourceContext headsc)
 {
     var ff = new procedure_header(fp, att, name, null, headsc);
     return BuildShortProcFuncDefinition(ff, st);
 }
Esempio n. 7
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public procedure_definition(procedure_header _proc_header,proc_block _proc_body,bool _is_short_definition)
		{
			this._proc_header=_proc_header;
			this._proc_body=_proc_body;
			this._is_short_definition=_is_short_definition;
		}
Esempio n. 8
0
            public static procedure_definition CreateProcedureDefinitionNode(method_name methName, formal_parameters formalPars, bool ofObject, bool classKeyword, statement procBody, SourceContext sc)
            {
                procedure_definition procDef = new procedure_definition();

                procedure_header procHeader = new procedure_header();
                procHeader.name = methName;
                procHeader.source_context = sc;
                if (procHeader.name.meth_name is template_type_name)
                {
                    procHeader.template_args = (procHeader.name.meth_name as template_type_name).template_args;
                    ident id = new ident(procHeader.name.meth_name.name);
                    procHeader.name.meth_name = id;
                }
                procHeader.parameters = formalPars;
                procHeader.of_object = ofObject;
                procHeader.class_keyword = classKeyword;

                statement_list stmtList = new statement_list();
                stmtList.subnodes.Add(procBody);

                block bl = new block(null, null);
                bl.program_code = stmtList;

                procDef.proc_header = procHeader;
                procDef.proc_body = (proc_block)bl;

                return procDef;
            }
Esempio n. 9
0
		public override void visit(procedure_header _procedure_header)
		{
			prepare_node(_procedure_header.name,"name");
			prepare_node(_procedure_header.parameters,"parameters");
			prepare_node(_procedure_header.proc_attributes,"attributes");
            prepare_node(_procedure_header.template_args, "template_params");
            prepare_node(_procedure_header.where_defs, "where_defs");
		}
 private bool is_forward(procedure_header ph)
 {
     if (ph.proc_attributes == null)
         return false;
     foreach (procedure_attribute pa in ph.proc_attributes.proc_attributes)
         if (pa.attribute_type == proc_attribute.attr_forward)
             return true;
     return false;
 }
 public override void visit(procedure_header _procedure_header)
 {
     multiline_stack_push(_procedure_header);
     sb.Append("procedure");
     SetKeywordOffset("procedure");
     if (_procedure_header.name != null)
         visit_node(_procedure_header.name);
     else
         add_space_before = false;
     if (_procedure_header.template_args != null && !(_procedure_header.name.meth_name is operator_name_ident))
     {
         sb.Append("<");
         visit_node(_procedure_header.template_args);
         //sb.Append(">");
     }
     if (_procedure_header.parameters != null)
     {
         visit_node(_procedure_header.parameters);
     }
     if (_procedure_header.where_defs != null)
         visit_node(_procedure_header.where_defs);
     if (_procedure_header.proc_attributes != null && has_attributes(_procedure_header.proc_attributes))
     {
         if (is_forward(_procedure_header))
             _procedure_header.source_context = new SourceContext(_procedure_header.source_context.begin_position.line_num, _procedure_header.source_context.begin_position.column_num, _procedure_header.proc_attributes.source_context.end_position.line_num, _procedure_header.proc_attributes.source_context.end_position.column_num);
         visit_node(_procedure_header.proc_attributes);
     }
     keyword_offset = 0;
     read_from_beg_pos = false;
     multiline_stack_pop(_procedure_header);
     //add_newline_before = true;
 }
 public override void visit(procedure_header pd)
 {
     // DO NOTHING
 }
Esempio n. 13
0
 public void CompareInternal(procedure_header left, procedure_header right)
 {
     if (left == null && right != null || left != null && right == null)
         throw_not_equal(left, right);
     if (left != null && right != null)
     {
         if (left.GetType() != right.GetType())
             throw_not_equal(left, right);
         Type t = left.GetType();
         if (t != typeof(procedure_header))
         {
             /*MethodInfo mi = t.GetMethod("CompareInternal", new Type[] { t, t });
             mi.Invoke(this, new object[] { left, right });
             return;*/
             if (left is function_header)
             {
                 CompareInternal(left as function_header, right as function_header);
                 return;
             }
             else if (left is constructor)
             {
                 CompareInternal(left as constructor, right as constructor);
                 return;
             }
             else if (left is destructor)
             {
                 CompareInternal(left as destructor, right as destructor);
                 return;
             }
             else
                 throw new NotSupportedException(left.GetType().ToString());
         }
         if (left.class_keyword != right.class_keyword)
             throw_not_equal(left, right);
         CompareInternal(left.attributes, right.attributes);
         CompareInternal(left.name, right.name);
         CompareInternal(left.template_args, right.template_args);
         CompareInternal(left.parameters, right.parameters);
         CompareInternal(left.where_defs, right.where_defs);
         CompareInternal(left.proc_attributes, right.proc_attributes);
     }
 }
        private void get_procedure_template(procedure_header header, StringBuilder res, int col)
        {
        	if (header.parameters != null)
        		for (int i=0; i<header.parameters.params_list.Count; i++)
        		for (int j=0; j<header.parameters.params_list[i].idents.idents.Count; j++)
        		{
        			res.AppendLine();
        			for (int k=0;k<col-3; k++)
						res.Append(' ');
        			res.Append("/// <param name=\""+header.parameters.params_list[i].idents.idents[j].name+"\"></param>");
        		}
        		if (header is function_header)
        		{
        			res.AppendLine();
        			for (int k=0;k<col-3; k++)
						res.Append(' ');
        			res.Append("/// <returns></returns>");
        		}
        }
 public override void visit(procedure_header _procedure_header)
 {
     connect(_procedure_header);
 }
        public override void visit(procedure_header _procedure_header)
        {
            //throw new Exception("The method or operation is not implemented.");
            SymScope topScope;
            ProcScope ps = null;
            bool not_def = false;
            ProcRealization pr = null;
            bool is_realization = false;
            location loc = get_location(_procedure_header);
            if (_procedure_header.name != null)
            {
                _procedure_header.name.visit(this);

                if (_procedure_header.name.class_name != null)
                {
                    topScope = null;
                    if (_procedure_header.name.ln != null && _procedure_header.name.ln.Count > 0)
                    {
                        SymScope tmp_scope = cur_scope;
                        for (int i = 0; i < _procedure_header.name.ln.Count; i++)
                        {
                            tmp_scope = tmp_scope.FindName(_procedure_header.name.ln[i].name);
                            if (tmp_scope == null)
                                break;
                        }
                        topScope = tmp_scope;
                    }
                    else
                        topScope = cur_scope.FindName(_procedure_header.name.class_name.name);
                    if (topScope != null)
                    {
                        ps = topScope.FindNameOnlyInThisType(meth_name) as ProcScope;
                        if (ps != null && ps is CompiledMethodScope)
                            ps = null;
                        if (ps == null)
                        {
                            ps = new ProcScope(meth_name, topScope);
                            ps.head_loc = loc;
                            bool ext = false;
                            if (topScope is CompiledScope || topScope is ArrayScope || topScope is TypeSynonim && ((topScope as TypeSynonim).actType is CompiledScope || (topScope as TypeSynonim).actType is ArrayScope || (topScope as TypeSynonim).actType is DiapasonScope))
                                ext = true;
                            else if (!(topScope is TypeSynonim) && !(topScope is PointerScope) && !(topScope is SetScope) && !(topScope is FileScope))
                                ext = true;
                            if (ext)
                            {
                                not_def = true;
                                ps.is_extension = true;
                                ps.AddName("self", new ElementScope(new SymInfo("self", SymbolKind.Parameter, "self"), topScope, cur_scope));
                                ps.declaringType = topScope as TypeScope;
                                TypeScope ts = topScope as TypeScope;
                                if (topScope is TypeSynonim)
                                    ts = (ts as TypeSynonim).actType;
                                this.entry_scope.AddExtensionMethod(meth_name, ps, ts);
                                topScope.AddExtensionMethod(meth_name, ps, ts);
                            }
                        }
                        //while (ps != null && ps.already_defined) ps = ps.nextProc;
                        else ps = select_function_definition(ps, _procedure_header.parameters, null, topScope as TypeScope);
                        if (ps == null)
                        {
                            ps = new ProcScope(meth_name, cur_scope);
                            ps.head_loc = loc;
                        }
                        if (ps.parameters.Count != 0 && _procedure_header.parameters != null && is_proc_realization)
                        {
                            ps.parameters.Clear();
                            ps.already_defined = true;
                        }
                        if (impl_scope == null)
                        {
                            pr = new ProcRealization(ps, cur_scope);
                            pr.already_defined = true;
                            ps.proc_realization = pr;
                            pr.loc = cur_loc;
                            pr.head_loc = loc;
                            is_realization = true;
                            entry_scope.AddName("$method", pr);
                        }
                        else
                        {
                            pr = new ProcRealization(ps, impl_scope);
                            pr.already_defined = true;
                            ps.proc_realization = pr;
                            pr.loc = cur_loc;
                            is_realization = true;
                            pr.head_loc = loc;
                            impl_scope.AddName("$method", pr);
                        }
                    }
                    else
                    {
                        ps = new ProcScope(meth_name, cur_scope);
                        ps.head_loc = loc;
                    }
                }
                else
                {
                    ps = new ProcScope(meth_name, cur_scope);
                    if (has_extensionmethod_attr(_procedure_header.proc_attributes.proc_attributes) && _procedure_header.parameters.params_list.Count > 0)
                    {
                        ps.is_extension = true;
                        _procedure_header.parameters.params_list[0].vars_type.visit(this);
                        topScope = returned_scope;
                        ps.declaringType = topScope as TypeScope;
                        TypeScope ts = topScope as TypeScope;
                        if (topScope is TypeSynonim)
                            ts = (ts as TypeSynonim).actType;
                        if (ts.original_type != null && ts.instances != null)
                        {
                            bool pure_instance = true;
                            foreach (TypeScope gen_arg in ts.instances)
                            {
                                if (!(gen_arg is TemplateParameterScope))
                                    pure_instance = false;
                            }
                            if (pure_instance)
                                ts = ts.original_type;
                        }
                        this.entry_scope.AddExtensionMethod(meth_name, ps, ts);
                        topScope.AddExtensionMethod(meth_name, ps, ts);
                        pr = new ProcRealization(ps, cur_scope);
                        pr.already_defined = true;
                        ps.proc_realization = pr;
                        pr.loc = cur_loc;
                        pr.head_loc = loc;
                        if (impl_scope != null)
                            impl_scope.AddName("$method", pr);
                        else
                            this.entry_scope.AddName("$method", pr);
                    }
                    ps.head_loc = loc;
                    if (!ps.is_extension)
                    {
                        if (IsForward(_procedure_header))
                        {
                            cur_scope.AddName(meth_name, ps);
                            ps.is_forward = true;
                        }
                        else
                        {
                            bool found_in_top = false;
                            SymScope ss = null;
                            if (cur_scope is ImplementationUnitScope)
                            {
                                ss = (cur_scope as ImplementationUnitScope).topScope.FindNameOnlyInThisType(meth_name);
                                if (ss != null && ss is ProcScope)
                                {
                                    //ps = ss as ProcScope;
                                    //while ((ss as ProcScope).already_defined && (ss as ProcScope).nextProc != null)
                                    //	ss = (ss as ProcScope).nextProc;
                                    ps = select_function_definition(ss as ProcScope, _procedure_header.parameters, null, null);
                                    if (ps == null)
                                    {
                                        ps = new ProcScope(meth_name, cur_scope);
                                        ps.head_loc = loc;
                                    }
                                    //ps = ss as ProcScope;
                                    if (ps.parameters.Count != 0 && _procedure_header.parameters != null)
                                    {
                                        ps.parameters.Clear();
                                        ps.already_defined = true;
                                    }
                                    pr = new ProcRealization(ps, cur_scope);
                                    pr.already_defined = true;
                                    pr.loc = cur_loc;
                                    ps.proc_realization = pr;
                                    pr.head_loc = loc;
                                    is_realization = true;
                                    cur_scope.AddName("$method", pr);
                                    found_in_top = true;
                                }
                            }
                            if (!found_in_top) //ne nashli opisanie v interface chasti modilja
                            {
                                //ss = cur_scope.FindNameOnlyInType(meth_name);
                                ss = cur_scope.FindName(meth_name);
                                if (ss != null && ss is ProcScope)
                                {
                                    if ((ss as ProcScope).is_forward)
                                    {
                                        //if ((ss as ProcScope).parameters.Count != 0 && _procedure_header.parameters != null) (ss as ProcScope).parameters.Clear();
                                        pr = new ProcRealization(ss as ProcScope, cur_scope);
                                        pr.already_defined = true;
                                        pr.loc = cur_loc;
                                        cur_scope.AddName("$method", pr);
                                        returned_scope = pr;
                                        pr.head_loc = loc;
                                        return;
                                    }
                                    else
                                    {
                                        ps = new ProcScope(meth_name, cur_scope);
                                        ps.head_loc = loc;
                                        if (ps.topScope == ss.topScope)
                                        {
                                            while ((ss as ProcScope).nextProc != null && (ss as ProcScope).nextProc.topScope == ps.topScope) ss = (ss as ProcScope).nextProc;
                                            ProcScope tmp_ps = (ss as ProcScope).nextProc;
                                            (ss as ProcScope).nextProc = ps;
                                            ps.nextProc = tmp_ps;
                                            cur_scope.AddName(meth_name, ps);
                                            ps.si.name = meth_name;
                                        }
                                        else
                                        {
                                            ps.nextProc = ss as ProcScope;
                                            cur_scope.AddName(meth_name, ps);
                                        }
                                        //ps = select_function_definition(ss as ProcScope,_procedure_header.parameters);
                                    }
                                }
                                else
                                {
                                    cur_scope.AddName(meth_name, ps);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                ps = new ProcScope("", cur_scope);
                ps.head_loc = loc;
            }
            if ((!is_realization || not_def) && ps.loc == null)
                ps.loc = cur_loc;
            //ps.head_loc = loc;
            ps.declaringUnit = entry_scope;
            if (_procedure_header.template_args != null && !ps.IsGeneric())
            {
                foreach (ident s in _procedure_header.template_args.idents)
                {
                    ps.AddTemplateParameter(s.name);
                    TemplateParameterScope tps = new TemplateParameterScope(s.name, TypeTable.obj_type, ps);
                    tps.loc = get_location(s);
                    ps.AddName(s.name, tps);
                }
            }
            SetAttributes(ps, _procedure_header.proc_attributes);
            ps.is_static = _procedure_header.class_keyword;
            if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_procedure_header))
                ps.AddDocumentation(this.converter.controller.docs[_procedure_header]);

            if (is_proc_realization) ps.already_defined = true;
            else
            {
                ps.loc = loc;
            }
            if (_procedure_header.name == null || _procedure_header.name.class_name == null)
            {
                ps.acc_mod = cur_access_mod;
                ps.si.acc_mod = cur_access_mod;
            }
            SymScope tmp = cur_scope;
            cur_scope = ps;
            if (_procedure_header.parameters != null)
                foreach (typed_parameters pars in _procedure_header.parameters.params_list)
                {
                    pars.vars_type.visit(this);

                    if (returned_scope != null)
                    {
                        if (returned_scope is ProcScope)
                            returned_scope = new ProcType(returned_scope as ProcScope);
                        foreach (ident id in pars.idents.idents)
                        {
                            ElementScope si = new ElementScope(new SymInfo(id.name, SymbolKind.Parameter, id.name), returned_scope, ps);
                            si.loc = get_location(id);
                            si.param_kind = pars.param_kind;
                            if (pars.inital_value != null)
                            {
                                pars.inital_value.visit(this);
                                si.cnst_val = cnst_val.prim_val;
                            }
                            si.MakeDescription();
                            ps.AddName(id.name, si);
                            ps.AddParameter(si);
                        }
                    }
                }
            cur_scope = tmp;
            if (cur_scope is TypeScope && !ps.is_static)
                ps.AddName("self", new ElementScope(new SymInfo("self", SymbolKind.Parameter, "self"), cur_scope, ps));
            //cur_scope = ps;
            returned_scope = ps;
            ps.Complete();
            if (pr != null && not_def)
                pr.Complete();
        }
Esempio n. 17
0
 public override void visit(procedure_header _procedure_header)
 {
     if (for_refactoring)
     {
         IBaseScope sc = null;
         if (_procedure_header.name != null)
         {
             if (_procedure_header.name.meth_name != null)
             {
                 if (with_body)
                 {
                     if (cur_scope != null && cur_scope.IsEqual(founded_scope))
                         pos_list.Add(get_position(_procedure_header.name.meth_name));
                 }
                 else
                 {
                     sc = cur_scope.FindNameOnlyInType(_procedure_header.name.meth_name.name);
                     if (sc != null && sc.IsEqual(founded_scope))
                         pos_list.Add(get_position(_procedure_header.name.meth_name));
                 }
             }
             if (_procedure_header.name.class_name != null)
             {
                 sc = cur_scope.FindNameInAnyOrder(_procedure_header.name.class_name.name);
                 if (sc != null && sc.IsEqual(founded_scope))
                     pos_list.Add(get_position(_procedure_header.name.class_name));
             }
         }
     }
     if (_procedure_header.parameters != null)
         _procedure_header.parameters.visit(this);
 }
		public void visit(procedure_header _procedure_header)
		{
			read_procedure_header(_procedure_header);
		}
Esempio n. 19
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public short_func_definition(procedure_header _proc_header,proc_block _proc_body,bool _is_short_definition,procedure_definition _procdef)
		{
			this._proc_header=_proc_header;
			this._proc_body=_proc_body;
			this._is_short_definition=_is_short_definition;
			this._procdef=_procdef;
		}
		public void read_procedure_header(procedure_header _procedure_header)
		{
			read_type_definition(_procedure_header);
			_procedure_header.parameters = _read_node() as formal_parameters;
			_procedure_header.proc_attributes = _read_node() as procedure_attributes_list;
			_procedure_header.name = _read_node() as method_name;
			_procedure_header.of_object = br.ReadBoolean();
			_procedure_header.class_keyword = br.ReadBoolean();
			_procedure_header.template_args = _read_node() as ident_list;
			_procedure_header.where_defs = _read_node() as where_definition_list;
		}
Esempio n. 21
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public procedure_definition(procedure_header _proc_header,proc_block _proc_body,bool _is_short_definition,SourceContext sc)
		{
			this._proc_header=_proc_header;
			this._proc_body=_proc_body;
			this._is_short_definition=_is_short_definition;
			source_context = sc;
		}
Esempio n. 22
0
		public override void visit(procedure_header _procedure_header)
		{
			throw new NotImplementedException();
		}
Esempio n. 23
0
        public static procedure_definition BuildShortProcFuncDefinitionNoSC(procedure_header header, statement st)
        {
            var stlist = new statement_list(st, st.source_context);
            var b = new block(null, stlist, st.source_context);

            return new procedure_definition(header, b, true, BuildGenSC);
        }
        ///////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////
        //CreateNonTerminalObject
        ///////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////

        public Object CreateNonTerminalObject(int ReductionRuleIndex)
        {
            switch (ReductionRuleIndex)
            {
                case (int)RuleConstants.RULE_SEPARATOR_TK_SEMICOLON:
                    //<Separator> ::= 'tk_SemiColon'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_SEPARATOR_TK_NEWLINE:
                    //<Separator> ::= 'tk_NewLine'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_SEPARATORS:
                    //<Separators> ::= <Separators> <Separator>
                    return LRParser.GetReductionSyntaxNode(1);

                case (int)RuleConstants.RULE_SEPARATORS2:
                    //<Separators> ::= <Separator>
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_SEPARATORSOPT:
                    //<Separators Opt> ::= <Separator> <Separators Opt>
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_SEPARATORSOPT2:
                    //<Separators Opt> ::= 
                    return null;

                case (int)RuleConstants.RULE_PROGRAM_TK_ALG_TK_IDENTIFIER_TK_BEGIN_TK_END:
                    //<Program> ::= <Separators Opt> <Global_part> 'tk_alg' 'tk_Identifier' <Separators> 'tk_begin' <Statements> 'tk_end' <Sub_declarations>
                    {
                        program_module _program_module;
                        block _block;
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(6));
                        program_name _program_name = new program_name((ident)LRParser.GetReductionSyntaxNode(3));

                        if ((_units[this.unit_number - 1] as unit_data).initialization.subnodes.Count != 0)
                            _statement_list.subnodes.InsertRange(0, (_units[this.unit_number - 1] as unit_data).initialization.subnodes);

                        if ((_units[this.unit_number - 1] as unit_data).sub_progs.defs.Count != 0)
                            _block = new block((_units[this.unit_number - 1] as unit_data).sub_progs, _statement_list);
                        else
                            _block = new block(null, _statement_list);

                        (_units[this.unit_number - 1] as unit_data).used_units.idents.Add(new ident("MathForKumir"));

                        if ((_units[this.unit_number - 1] as unit_data).used_units.idents.Count != 0)
                        {
                            unit_or_namespace _unit_or_namespace;
                            uses_list _uses_list = new uses_list();

                            for (int i = 0; i < (_units[this.unit_number - 1] as unit_data).used_units.idents.Count; i++)
                            {
                                ident_list _ident_list = new ident_list();
                                _ident_list.idents.Add((_units[this.unit_number - 1] as unit_data).used_units.idents[i]);
                                _unit_or_namespace = new unit_or_namespace(_ident_list);
                                _uses_list.units.Add(_unit_or_namespace);
                            }
                            _program_module = new program_module(_program_name, _uses_list, _block, null);

                        }
                        else
                            _program_module = new program_module(_program_name, null, _block, null);
                        declarations _declarations = new declarations();
                        _program_module.Language = LanguageId.PascalABCNET;
                        parsertools.create_source_context(_program_module, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(3)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(8), LRParser.GetReductionSyntaxNode(7), LRParser.GetReductionSyntaxNode(6)));
                        parsertools.create_source_context(_block, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(2)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(8), LRParser.GetReductionSyntaxNode(7)));
                        parsertools.create_source_context(_program_name, LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(3));
                        return _program_module;
                    }

                case (int)RuleConstants.RULE_PROGRAM_TK_ISP_TK_IDENTIFIER_TK_END:
                    //<Program> ::= <Separators Opt> 'tk_isp' 'tk_Identifier' <Separators> <Global_part> <Sub_declarations> 'tk_end'
                    {
                        interface_node _interface_node;
                        (_units[this.unit_number - 1] as unit_data).used_units.idents.Add(new ident("MathForKumir"));
                        if ((_units[this.unit_number - 1] as unit_data).used_units.idents.Count > 0)
                        {
                            unit_or_namespace _unit_or_namespace;
                            uses_list _uses_list = new uses_list();
                            for (int i = 0; i < (_units[this.unit_number - 1] as unit_data).used_units.idents.Count; i++)
                            {
                                ident_list _ident_list = new ident_list();
                                _ident_list.idents.Add((_units[this.unit_number - 1] as unit_data).used_units.idents[i]);
                                _unit_or_namespace = new unit_or_namespace(_ident_list);
                                _uses_list.units.Add(_unit_or_namespace);
                            }
                            _interface_node = new interface_node((_units[this.unit_number - 1] as unit_data).sub_progs, _uses_list, null);
                        }
                        else
                            _interface_node = new interface_node((_units[this.unit_number - 1] as unit_data).sub_progs, null, null);
                        unit_module _unit_module = new unit_module(new unit_name((ident)LRParser.GetReductionSyntaxNode(2), 0), _interface_node, null, (_units[this.unit_number - 1] as unit_data).initialization, null);
                        _unit_module.Language = LanguageId.PascalABCNET;
                        unit_name _unit_name = new unit_name((ident)LRParser.GetReductionSyntaxNode(2), 0);
                        parsertools.create_source_context(_unit_module, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(3)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(6), LRParser.GetReductionSyntaxNode(5)));
                        parsertools.create_source_context(_unit_name, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));

                        return _unit_module;
                    }

                case (int)RuleConstants.RULE_PROCEDURE_TK_ALG_TK_IDENTIFIER_TK_ROUNDOPEN_TK_ROUNDCLOSE_TK_BEGIN_TK_END:
                    //<Procedure> ::= 'tk_alg' 'tk_Identifier' 'tk_RoundOpen' <Formal_list> 'tk_RoundClose' <Separators> 'tk_begin' <Statements> 'tk_end'
                    {
                        method_name _method_name = new method_name(null, (ident)LRParser.GetReductionSyntaxNode(1), null);
                        procedure_header _procedure_header = new procedure_header(GetFormals(LRParser.GetReductionSyntaxNode(3)), null, _method_name, false, false, null,null);
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(7));
                        block _block = new block(null, _statement_list);

                        procedure_definition _procedure_definition = new procedure_definition(_procedure_header, _block);
                        parsertools.create_source_context(_method_name, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_procedure_header, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(4));
                        parsertools.create_source_context(_procedure_definition, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(8));
                        parsertools.create_source_context(_block, LRParser.GetReductionSyntaxNode(6), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(8), LRParser.GetReductionSyntaxNode(7)));
                        (_units[this.unit_number - 1] as unit_data).sub_progs.defs.Add(_procedure_definition);

                        return _procedure_definition;
                    }

                case (int)RuleConstants.RULE_PROCEDURE_TK_ALG_TK_IDENTIFIER_TK_BEGIN_TK_END:
                    //<Procedure> ::= 'tk_alg' 'tk_Identifier' <Separators> 'tk_begin' <Statements> 'tk_end'
                    {
                        method_name _method_name = new method_name(null, (ident)LRParser.GetReductionSyntaxNode(1), null);
                        procedure_header _procedure_header = new procedure_header(null, null, _method_name, false, false, null,null);
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(4));
                        block _block = new block(null, _statement_list);

                        procedure_definition _procedure_definition = new procedure_definition(_procedure_header, _block);

                        parsertools.create_source_context(_method_name, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_procedure_header, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_procedure_definition, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(5));
                        parsertools.create_source_context(_block, LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(5));
                        (_units[this.unit_number - 1] as unit_data).sub_progs.defs.Add(_procedure_definition);
                        declarations _declarations = new declarations();
                        _declarations.defs.Add(_procedure_definition);
                        parsertools.create_source_context(_declarations, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(5), LRParser.GetReductionSyntaxNode(4)));

                        return _procedure_definition;
                    }

                case (int)RuleConstants.RULE_FUNCTION_TK_ALG_TK_IDENTIFIER_TK_ROUNDOPEN_TK_ROUNDCLOSE_TK_BEGIN_TK_END:
                    //<Function> ::= 'tk_alg' <Type> 'tk_Identifier' 'tk_RoundOpen' <Formal_list> 'tk_RoundClose' <Separators> 'tk_begin' <Statements> 'tk_end'
                    {
                        method_name _method_name = new method_name(null, LRParser.GetReductionSyntaxNode(2) as ident, null);
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(1)).text.ToLower());

                        function_header _function_header = new function_header(_named_type_reference);
                        _function_header.of_object = false;
                        _function_header.name = _method_name;
                        _function_header.parameters = GetFormals(LRParser.GetReductionSyntaxNode(4));

                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(8));
                        block _block = new block(null, _statement_list);

                        procedure_definition _procedure_definition = new procedure_definition(_function_header, _block);
                        parsertools.create_source_context(_method_name, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_function_header, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(5));
                        parsertools.create_source_context(_procedure_definition, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(9));
                        parsertools.create_source_context(_block, LRParser.GetReductionSyntaxNode(7), LRParser.GetReductionSyntaxNode(9));
                        (_units[this.unit_number - 1] as unit_data).sub_progs.defs.Add(_procedure_definition);
                        declarations _declarations = new declarations();
                        _declarations.defs.Add(_procedure_definition);
                        parsertools.create_source_context(_declarations, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(9));
                        return _procedure_definition;
                    }

                case (int)RuleConstants.RULE_FUNCTION_TK_ALG_TK_IDENTIFIER_TK_BEGIN_TK_END:
                    //<Function> ::= 'tk_alg' <Type> 'tk_Identifier' <Separators> 'tk_begin' <Statements> 'tk_end'
                    {
                        method_name _method_name = new method_name(null, LRParser.GetReductionSyntaxNode(2) as ident, null);
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(1)).text.ToLower());

                        function_header _function_header = new function_header(_named_type_reference);
                        _function_header.of_object = false;
                        _function_header.name = _method_name;

                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(5));
                        block _block = new block(null, _statement_list);

                        procedure_definition _procedure_definition = new procedure_definition(_function_header, _block);
                        parsertools.create_source_context(_method_name, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_function_header, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_procedure_definition, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(6));
                        parsertools.create_source_context(_block, LRParser.GetReductionSyntaxNode(4), LRParser.GetReductionSyntaxNode(6));
                        (_units[this.unit_number - 1] as unit_data).sub_progs.defs.Add(_procedure_definition);
                        return _procedure_definition;
                    }

                case (int)RuleConstants.RULE_SUB_DECLARATIONS:
                    //<Sub_declarations> ::= 
                    return null;

                case (int)RuleConstants.RULE_SUB_DECLARATIONS2:
                    //<Sub_declarations> ::= <Sub_declarations> <Procedure>
                    {
                        declarations _declarations;
                        if (LRParser.GetReductionSyntaxNode(0) != null)
                        {
                            _declarations = (declarations)LRParser.GetReductionSyntaxNode(0);
                            _declarations.defs.Add((declaration)LRParser.GetReductionSyntaxNode(1));
                        }
                        else
                        {
                            _declarations = new declarations();
                            _declarations.defs.Add((declaration)LRParser.GetReductionSyntaxNode(1));
                        }
                        // 
                        parsertools.create_source_context(_declarations, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1)), LRParser.GetReductionSyntaxNode(1));
                        return _declarations;
                    }

                case (int)RuleConstants.RULE_SUB_DECLARATIONS3:
                    //<Sub_declarations> ::= <Sub_declarations> <Function>
                    {
                        declarations _declarations;
                        if (LRParser.GetReductionSyntaxNode(0) != null)
                        {
                            _declarations = (declarations)LRParser.GetReductionSyntaxNode(0);
                            _declarations.defs.Add((declaration)LRParser.GetReductionSyntaxNode(1));
                        }
                        else
                        {
                            _declarations = new declarations();
                            _declarations.defs.Add((declaration)LRParser.GetReductionSyntaxNode(1));
                        }
                        parsertools.create_source_context(_declarations, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1)), LRParser.GetReductionSyntaxNode(1));
                        return _declarations;
                    }

                case (int)RuleConstants.RULE_SUB_DECLARATIONS4:
                    //<Sub_declarations> ::= <Sub_declarations> <Separators>
                    {
                        declarations _declarations;
                        if (LRParser.GetReductionSyntaxNode(0) != null)
                        {
                            _declarations = (declarations)LRParser.GetReductionSyntaxNode(0);
                        }
                        else
                        {
                            _declarations = new declarations();

                        }
                        parsertools.create_source_context(_declarations, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(0)));
                        return _declarations;
                    }


                case (int)RuleConstants.RULE_TYPE_TK_INTEGER_TYPE:
                    //<Type> ::= 'tk_integer_type'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_TYPE_TK_REAL_TYPE:
                    //<Type> ::= 'tk_real_type'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_TYPE_TK_BOOLEAN_TYPE:
                    //<Type> ::= 'tk_boolean_type'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_TYPE_TK_CHAR_TYPE:
                    //<Type> ::= 'tk_char_type'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_TYPE_TK_STRING_TYPE:
                    //<Type> ::= 'tk_string_type'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_DIAP_TK_COLON:
                    //<Diap> ::= <Expression> 'tk_Colon' <Expression>
                    {
                        diapason _diapason = new diapason(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression);

                        parsertools.create_source_context(_diapason, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _diapason;
                    }

                case (int)RuleConstants.RULE_DIAP_LIST_TK_COMMA:
                    //<Diap_list> ::= <Diap_list> 'tk_Comma' <Diap>
                    {
                        indexers_types _indexers_types = GetIndexers(LRParser.GetReductionSyntaxNode(0));
                        _indexers_types.indexers.Add(LRParser.GetReductionSyntaxNode(2) as diapason);

                        parsertools.create_source_context(_indexers_types, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _indexers_types;
                    }

                case (int)RuleConstants.RULE_DIAP_LIST:
                    //<Diap_list> ::= <Diap>
                    {
                        indexers_types _indexers_types = new indexers_types();
                        _indexers_types.indexers.Add(LRParser.GetReductionSyntaxNode(0) as diapason);

                        parsertools.create_source_context(_indexers_types, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return _indexers_types;
                    }

                case (int)RuleConstants.RULE_LIST_OF_EXPRESSIONS_TK_COMMA:
                    //<List_of_expressions> ::= <List_of_expressions> 'tk_Comma' <Expression>
                    {
                        expression_list _expression_list = GetExpressions(LRParser.GetReductionSyntaxNode(0));
                        _expression_list.expressions.Add(LRParser.GetReductionSyntaxNode(2) as expression);

                        parsertools.create_source_context(_expression_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _expression_list;
                    }

                case (int)RuleConstants.RULE_LIST_OF_EXPRESSIONS:
                    //<List_of_expressions> ::= <Expression>
                    {
                        expression_list _expression_list = new expression_list();
                        _expression_list.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);

                        _expression_list.source_context = ((expression)LRParser.GetReductionSyntaxNode(0)).source_context;
                        return _expression_list;
                    }

                case (int)RuleConstants.RULE_ID_LIST1_TK_IDENTIFIER:
                    //<Id_list1> ::= 'tk_Identifier'
                    {
                        ident_list _ident_list = new ident_list();
                        _ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);

                        _ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
                        return _ident_list;
                    }

                case (int)RuleConstants.RULE_ID_LIST1_TK_IDENTIFIER_TK_COMMA:
                    //<Id_list1> ::= 'tk_Identifier' 'tk_Comma' <Id_list1>
                    {
                        ident_list _ident_list = GetIdents(LRParser.GetReductionSyntaxNode(2));
                        _ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);

                        parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(0)));
                        return _ident_list;
                    }

                case (int)RuleConstants.RULE_ARRAY_LIST1_TK_IDENTIFIER_TK_SQUAREOPEN_TK_SQUARECLOSE:
                    //<Array_list1> ::= 'tk_Identifier' 'tk_SquareOpen' <Diap_list> 'tk_SquareClose'
                    {
                        ident_list _ident_list = new ident_list();
                        _ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);

                        indexers_types _indexers_types = GetIndexers(LRParser.GetReductionSyntaxNode(2));
                        array_type _array_type = new array_type(_indexers_types, null);

                        var_def_statement _var_def_statement = new var_def_statement(_ident_list, _array_type, null, definition_attribute.None, false);
                        variable_definitions _variable_definitions = new variable_definitions();
                        _variable_definitions.var_definitions.Add(_var_def_statement);

                        //_ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
                        parsertools.create_source_context(_array_type, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
                        //parsertools.create_source_context(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        parsertools.create_source_context(_indexers_types, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_var_def_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        return _variable_definitions;
                    }

                case (int)RuleConstants.RULE_ARRAY_LIST1_TK_IDENTIFIER_TK_SQUAREOPEN_TK_SQUARECLOSE_TK_COMMA:
                    //<Array_list1> ::= 'tk_Identifier' 'tk_SquareOpen' <Diap_list> 'tk_SquareClose' 'tk_Comma' <Array_list1>
                    {
                        ident_list _ident_list = new ident_list();
                        _ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);

                        indexers_types _indexers_types = GetIndexers(LRParser.GetReductionSyntaxNode(2));
                        array_type _array_type = new array_type(_indexers_types, null);

                        var_def_statement _var_def_statement = new var_def_statement(_ident_list, _array_type, null, definition_attribute.None, false);
                        variable_definitions _variable_definitions = (LRParser.GetReductionSyntaxNode(5) as variable_definitions);
                        _variable_definitions.var_definitions.Add(_var_def_statement);

                        //_ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
                        parsertools.create_source_context(_array_type, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        //parsertools.create_source_context(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_indexers_types, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(5));
                        parsertools.create_source_context(_var_def_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        return _variable_definitions;
                    }

                case (int)RuleConstants.RULE_ID_LIST2_TK_IDENTIFIER_TK_COMMA:
                    //<Id_list2> ::= 'tk_Identifier' 'tk_Comma'
                    {
                        ident_list _ident_list = new ident_list();
                        _ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);

                        _ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
                        return _ident_list;
                    }

                case (int)RuleConstants.RULE_ID_LIST2_TK_IDENTIFIER_TK_COMMA2:
                    //<Id_list2> ::= 'tk_Identifier' 'tk_Comma' <Id_list2>
                    {
                        ident_list _ident_list = GetIdents(LRParser.GetReductionSyntaxNode(2));
                        _ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);

                        parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(0)));
                        return _ident_list;
                    }

                case (int)RuleConstants.RULE_ARRAY_LIST2_TK_IDENTIFIER_TK_SQUAREOPEN_TK_SQUARECLOSE_TK_COMMA:
                    //<Array_list2> ::= 'tk_Identifier' 'tk_SquareOpen' <Diap_list> 'tk_SquareClose' 'tk_Comma'
                    {
                        ident_list _ident_list = new ident_list();
                        _ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);

                        indexers_types _indexers_types = GetIndexers(LRParser.GetReductionSyntaxNode(2));
                        array_type _array_type = new array_type(_indexers_types, null);

                        var_def_statement _var_def_statement = new var_def_statement(_ident_list, _array_type, null, definition_attribute.None, false);
                        variable_definitions _variable_definitions = new variable_definitions();
                        _variable_definitions.var_definitions.Add(_var_def_statement);

                        //_ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
                        parsertools.create_source_context(_array_type, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        //parsertools.create_source_context(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_indexers_types, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));

                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_var_def_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        return _variable_definitions;
                    }

                case (int)RuleConstants.RULE_ARRAY_LIST2_TK_IDENTIFIER_TK_SQUAREOPEN_TK_SQUARECLOSE_TK_COMMA2:
                    //<Array_list2> ::= 'tk_Identifier' 'tk_SquareOpen' <Diap_list> 'tk_SquareClose' 'tk_Comma' <Array_list2>
                    {
                        ident_list _ident_list = new ident_list();
                        _ident_list.idents.Add(LRParser.GetReductionSyntaxNode(0) as ident);

                        indexers_types _indexers_types = GetIndexers(LRParser.GetReductionSyntaxNode(2));
                        array_type _array_type = new array_type(_indexers_types, null);

                        var_def_statement _var_def_statement = new var_def_statement(_ident_list, _array_type, null, definition_attribute.None, false);
                        variable_definitions _variable_definitions = (LRParser.GetReductionSyntaxNode(5) as variable_definitions);
                        _variable_definitions.var_definitions.Add(_var_def_statement);

                        //_ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
                        parsertools.create_source_context(_array_type, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        //parsertools.create_source_context(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_indexers_types, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));

                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(5));
                        parsertools.create_source_context(_var_def_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        return _variable_definitions;
                    }

                case (int)RuleConstants.RULE_VAR_DECLARATIONS1:
                    //<Var_declarations1> ::= <Type> <Id_list1>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(0)).text.ToLower());

                        var_def_statement _var_def_statement = new var_def_statement(GetIdents(LRParser.GetReductionSyntaxNode(1)), _named_type_reference, null, definition_attribute.None, false);
                        var_statement _var_statement = new var_statement(_var_def_statement);

                        parsertools.create_source_context(_var_def_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_var_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_named_type_reference, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return _var_statement;
                    }

                case (int)RuleConstants.RULE_VAR_DECLARATIONS1_TK_ARRAY:
                    //<Var_declarations1> ::= <Type> 'tk_array' <Array_list1>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(0)).text.ToLower());

                        statement_list var_statement_list = new statement_list();

                        variable_definitions _variable_definitions = LRParser.GetReductionSyntaxNode(2) as variable_definitions;
                        for (int i = 0; i < _variable_definitions.var_definitions.Count; i++)
                        {
                            ((_variable_definitions.var_definitions[i]).vars_type as array_type).elemets_types = _named_type_reference;
                            var_statement _var_statement = new var_statement((var_def_statement)_variable_definitions.var_definitions[i]);
                            var_statement_list.subnodes.Add(_var_statement);

                            parsertools.create_source_context(_var_statement, _variable_definitions.var_definitions[i], _variable_definitions.var_definitions[i]);

                        }
                        parsertools.create_source_context(_named_type_reference.names[0], LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(var_statement_list, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_named_type_reference, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return var_statement_list;
                    }

                case (int)RuleConstants.RULE_VAR_DECLARATIONS2:
                    //<Var_declarations2> ::= <Type> <Id_list2>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(0)).text.ToLower());
                        var_def_statement _var_def_statement = new var_def_statement(GetIdents(LRParser.GetReductionSyntaxNode(1)), _named_type_reference, null, definition_attribute.None, false);
                        var_statement _var_statement = new var_statement(_var_def_statement);

                        parsertools.create_source_context(_var_def_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_var_statement, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_named_type_reference, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return _var_statement;
                    }

                case (int)RuleConstants.RULE_VAR_DECLARATIONS2_TK_ARRAY:
                    //<Var_declarations2> ::= <Type> 'tk_array' <Array_list2>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(0)).text.ToLower());

                        statement_list var_statement_list = new statement_list();

                        variable_definitions _variable_definitions = LRParser.GetReductionSyntaxNode(2) as variable_definitions;
                        for (int i = 0; i < _variable_definitions.var_definitions.Count; i++)
                        {
                            ((_variable_definitions.var_definitions[i]).vars_type as array_type).elemets_types = _named_type_reference;
                            var_statement _var_statement = new var_statement((var_def_statement)_variable_definitions.var_definitions[i]);
                            var_statement_list.subnodes.Add(_var_statement);

                            parsertools.create_source_context(_var_statement, _variable_definitions.var_definitions[i], _variable_definitions.var_definitions[i]);
                        }

                        parsertools.create_source_context(_named_type_reference.names[0], LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        parsertools.create_source_context(var_statement_list, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_named_type_reference, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));

                        return var_statement_list;
                    }

                case (int)RuleConstants.RULE_VAR_DECL_LIST1:
                    //<Var_decl_list1> ::= <Var_declarations1>
                    {
                        statement_list var_statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));

                        parsertools.create_source_context(var_statement_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return var_statement_list;
                    }

                case (int)RuleConstants.RULE_VAR_DECL_LIST12:
                    //<Var_decl_list1> ::= <Var_decl_list2> <Var_declarations1>
                    {
                        statement_list var_statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));
                        var_statement_list.subnodes.AddRange(GetStatements(LRParser.GetReductionSyntaxNode(1)).subnodes);

                        parsertools.create_source_context(var_statement_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return var_statement_list;
                    }

                case (int)RuleConstants.RULE_VAR_DECL_LIST2:
                    //<Var_decl_list2> ::= <Var_declarations2>
                    {
                        statement_list var_statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));

                        parsertools.create_source_context(var_statement_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return var_statement_list;
                    }

                case (int)RuleConstants.RULE_VAR_DECL_LIST22:
                    //<Var_decl_list2> ::= <Var_decl_list2> <Var_declarations2>
                    {
                        statement_list var_statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));
                        var_statement_list.subnodes.AddRange(GetStatements(LRParser.GetReductionSyntaxNode(1)).subnodes);

                        parsertools.create_source_context(var_statement_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return var_statement_list;
                    }


                case (int)RuleConstants.RULE_DECLARATIONS:
                    //<Declarations> ::= <Var_decl_list1>
                    return LRParser.GetReductionSyntaxNode(0);

                //------------------------- Globals

                case (int)RuleConstants.RULE_USES_UNITS_TK_USES:
                    //<Uses_units> ::= 'tk_uses' <Id_list1>
                    {
                        if (_units[unit_number - 1] != null)
                            (_units[unit_number - 1] as unit_data).used_units.idents.AddRange(((ident_list)LRParser.GetReductionSyntaxNode(1)).idents);
                        parsertools.create_source_context(LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return LRParser.GetReductionSyntaxNode(1);

                        //return null;
                    }

                case (int)RuleConstants.RULE_GLOBAL_DECL_LIST:
                    //<Global_decl_list> ::= <Global_decl_list> <Separators> <Declarations>
                    {
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));
                        _statement_list.subnodes.AddRange(GetStatements(LRParser.GetReductionSyntaxNode(2)).subnodes);
                        parsertools.create_source_context(_statement_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _statement_list;
                    }

                case (int)RuleConstants.RULE_GLOBAL_DECL_LIST2:
                    //<Global_decl_list> ::= <Declarations>
                    {   // etot kod pohoje inogda ne vipolniaetsia hotia pravilo srabativaet        
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));
                        for (int i = 0; i < _statement_list.subnodes.Count; i++)
                            (_units[this.unit_number - 1] as unit_data).sub_progs.defs.Add(_statement_list.subnodes[i] as declaration);
                        parsertools.create_source_context(_statement_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return _statement_list;
                    }

                case (int)RuleConstants.RULE_INITIALIZATION_TK_ASSIGN:
                    //<Initialization> ::= <Initialization> <Separators> <Value> 'tk_Assign' <Expression>
                    {
                        assign _assign = new assign((addressed_value)LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(4) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(3)).type);
                        (_units[this.unit_number - 1] as unit_data).initialization.subnodes.Add(_assign);

                        parsertools.create_source_context(_assign, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(4));
                        return null;
                    }

                case (int)RuleConstants.RULE_INITIALIZATION_TK_ASSIGN2:
                    //<Initialization> ::= <Value> 'tk_Assign' <Expression>
                    {
                        assign _assign = new assign((addressed_value)LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        (_units[this.unit_number - 1] as unit_data).initialization.subnodes.Add(_assign);

                        parsertools.create_source_context(_assign, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return null;
                    }

                case (int)RuleConstants.RULE_GLOBAL_VARS:
                    //<Global_vars> ::= <Global_decl_list> <Separators> <Initialization> <Separators>
                    {
                        declarations _declarations = new declarations();
                        //_declarations.defs.Add((declaration)LRParser.GetReductionSyntaxNode(2));
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));
                        for (int i = 0; i < _statement_list.subnodes.Count; i++)
                        {
                            (_units[this.unit_number - 1] as unit_data).sub_progs.defs.Add(_statement_list.subnodes[i] as declaration);
                            _declarations.defs.Add(_statement_list.subnodes[i] as declaration);
                        }
                        parsertools.create_source_context(_declarations, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(3)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(0)));
                        return _declarations;
                    }

                case (int)RuleConstants.RULE_GLOBAL_VARS2:
                    //<Global_vars> ::= <Global_decl_list> <Separators>
                    {
                        //declarations _declarations = (declarations)LRParser.GetReductionSyntaxNode(0);
                        declarations _declarations = new declarations();
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));
                        for (int i = 0; i < _statement_list.subnodes.Count; i++)
                        {
                            (_units[this.unit_number - 1] as unit_data).sub_progs.defs.Add(_statement_list.subnodes[i] as declaration);
                            _declarations.defs.Add(_statement_list.subnodes[i] as declaration);
                        }
                        parsertools.create_source_context(_declarations, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(0)));
                        return _declarations;
                    }

                case (int)RuleConstants.RULE_GLOBAL_PART:
                    //<Global_part> ::= 
                    return null;

                case (int)RuleConstants.RULE_GLOBAL_PART2:
                    //<Global_part> ::= <Uses_units> <Separators>
                    {
                        //declarations _declarations = (declarations)LRParser.GetReductionSyntaxNode(0);
                        //parsertools.create_source_context(_declarations, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(0)));
                        return null;
                    }

                case (int)RuleConstants.RULE_GLOBAL_PART3:
                    //<Global_part> ::= <Uses_units> <Separators> <Global_vars>
                    {
                        //declarations _declarations = (declarations)LRParser.GetReductionSyntaxNode(0);
                        //_declarations.defs.AddRange(((declarations)LRParser.GetReductionSyntaxNode(2)).defs);
                        //parsertools.create_source_context(_declarations, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(2)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(0)));
                        return null;
                    }
                case (int)RuleConstants.RULE_GLOBAL_PART4:
                    //<Global_part> ::= <Global_vars>
                    {
                        //declarations _declarations = (declarations)LRParser.GetReductionSyntaxNode(0);
                        //parsertools.create_source_context(_declarations, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return null;
                    }

                case (int)RuleConstants.RULE_FORMAL_PARAMETER1:
                    //<Formal_parameter1> ::= <Type> <Id_list1>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(0)).text.ToLower());
                        ident_list _ident_list = GetIdents(LRParser.GetReductionSyntaxNode(1));
                        _ident_list.idents.Reverse();

                        typed_parameters _typed_parametres = new typed_parameters(_ident_list, _named_type_reference, parametr_kind.none, null);
                        formal_parameters _formal_parametres = new formal_parameters();
                        _formal_parametres.params_list.Add(_typed_parametres);

                        parsertools.create_source_context(_typed_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_PARAMETER1_TK_VAR:
                    //<Formal_parameter1> ::= 'tk_var' <Type> <Id_list1>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(1)).text.ToLower());
                        ident_list _ident_list = GetIdents(LRParser.GetReductionSyntaxNode(2));
                        _ident_list.idents.Reverse();

                        typed_parameters _typed_parametres = new typed_parameters(_ident_list, _named_type_reference, parametr_kind.var_parametr, null);
                        formal_parameters _formal_parametres = new formal_parameters();
                        _formal_parametres.params_list.Add(_typed_parametres);

                        parsertools.create_source_context(_typed_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_PARAMETER1_TK_ARRAY:
                    //<Formal_parameter1> ::= <Type> 'tk_array' <Array_list1>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(0)).text.ToLower());
                        variable_definitions _variable_definitions = LRParser.GetReductionSyntaxNode(2) as variable_definitions;
                        formal_parameters _formal_parametres = new formal_parameters();
                        _variable_definitions.var_definitions.Reverse();

                        for (int i = 0; i < _variable_definitions.var_definitions.Count; i++)
                        {
                            ((_variable_definitions.var_definitions[i]).vars_type as array_type).elemets_types = _named_type_reference;
                            _formal_parametres.params_list.Add(new typed_parameters((_variable_definitions.var_definitions[i]).vars, (_variable_definitions.var_definitions[i]).vars_type, parametr_kind.none, null));
                        }
                        _variable_definitions.var_definitions.Clear();

                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_named_type_reference, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_PARAMETER1_TK_VAR_TK_ARRAY:
                    //<Formal_parameter1> ::= 'tk_var' <Type> 'tk_array' <Array_list1>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(1)).text.ToLower());
                        variable_definitions _variable_definitions = LRParser.GetReductionSyntaxNode(3) as variable_definitions;
                        formal_parameters _formal_parametres = new formal_parameters();
                        _variable_definitions.var_definitions.Reverse();

                        for (int i = 0; i < _variable_definitions.var_definitions.Count; i++)
                        {
                            ((_variable_definitions.var_definitions[i]).vars_type as array_type).elemets_types = _named_type_reference;
                            _formal_parametres.params_list.Add(new typed_parameters((_variable_definitions.var_definitions[i]).vars, (_variable_definitions.var_definitions[i]).vars_type, parametr_kind.var_parametr, null));
                        }
                        _variable_definitions.var_definitions.Clear();

                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_named_type_reference, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_PARAMETER2:
                    //<Formal_Parameter2> ::= <Type> <Id_list2>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(0)).text.ToLower());
                        ident_list _ident_list = GetIdents(LRParser.GetReductionSyntaxNode(1));
                        _ident_list.idents.Reverse();

                        typed_parameters _typed_parametres = new typed_parameters(_ident_list, _named_type_reference, parametr_kind.none, null);
                        formal_parameters _formal_parametres = new formal_parameters();
                        _formal_parametres.params_list.Add(_typed_parametres);

                        parsertools.create_source_context(_typed_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_PARAMETER2_TK_VAR:
                    //<Formal_Parameter2> ::= 'tk_var' <Type> <Id_list2>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(1)).text.ToLower());
                        ident_list _ident_list = GetIdents(LRParser.GetReductionSyntaxNode(2));
                        _ident_list.idents.Reverse();

                        typed_parameters _typed_parametres = new typed_parameters(_ident_list, _named_type_reference, parametr_kind.var_parametr, null);
                        formal_parameters _formal_parametres = new formal_parameters();
                        _formal_parametres.params_list.Add(_typed_parametres);

                        parsertools.create_source_context(_typed_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_PARAMETER2_TK_ARRAY:
                    //<Formal_Parameter2> ::= <Type> 'tk_array' <Array_list2>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(0)).text.ToLower());
                        variable_definitions _variable_definitions = LRParser.GetReductionSyntaxNode(2) as variable_definitions;
                        formal_parameters _formal_parametres = new formal_parameters();
                        _variable_definitions.var_definitions.Reverse();

                        for (int i = 0; i < _variable_definitions.var_definitions.Count; i++)
                        {
                            ((_variable_definitions.var_definitions[i]).vars_type as array_type).elemets_types = _named_type_reference;
                            _formal_parametres.params_list.Add(new typed_parameters((_variable_definitions.var_definitions[i]).vars, (_variable_definitions.var_definitions[i]).vars_type, parametr_kind.none, null));
                        }
                        _variable_definitions.var_definitions.Clear();

                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_PARAMETER2_TK_VAR_TK_ARRAY:
                    //<Formal_Parameter2> ::= 'tk_var' <Type> 'tk_array' <Array_list2>
                    {
                        named_type_reference _named_type_reference = GetType(((token_info)LRParser.GetReductionSyntaxNode(1)).text.ToLower());
                        variable_definitions _variable_definitions = LRParser.GetReductionSyntaxNode(3) as variable_definitions;
                        formal_parameters _formal_parametres = new formal_parameters();
                        _variable_definitions.var_definitions.Reverse();

                        for (int i = 0; i < _variable_definitions.var_definitions.Count; i++)
                        {
                            ((_variable_definitions.var_definitions[i]).vars_type as array_type).elemets_types = _named_type_reference;
                            _formal_parametres.params_list.Add(new typed_parameters((_variable_definitions.var_definitions[i]).vars, (_variable_definitions.var_definitions[i]).vars_type, parametr_kind.var_parametr, null));
                        }
                        _variable_definitions.var_definitions.Clear();

                        parsertools.create_source_context(_variable_definitions, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_TYPE_LIST1:
                    //<Formal_type_list1> ::= <Formal_parameter1>
                    {
                        formal_parameters _formal_parametres = GetFormals(LRParser.GetReductionSyntaxNode(0));

                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_TYPE_LIST12:
                    //<Formal_type_list1> ::= <Formal_type_list2> <Formal_parameter1>
                    {
                        formal_parameters _formal_parametres = GetFormals(LRParser.GetReductionSyntaxNode(0));
                        _formal_parametres.params_list.AddRange(GetFormals(LRParser.GetReductionSyntaxNode(1)).params_list);

                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_TYPE_LIST2:
                    //<Formal_type_list2> ::= <Formal_Parameter2>
                    {
                        formal_parameters _formal_parametres = GetFormals(LRParser.GetReductionSyntaxNode(0));

                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_TYPE_LIST22:
                    //<Formal_type_list2> ::= <Formal_type_list2> <Formal_Parameter2>
                    {
                        formal_parameters _formal_parametres = GetFormals(LRParser.GetReductionSyntaxNode(0));
                        _formal_parametres.params_list.AddRange(GetFormals(LRParser.GetReductionSyntaxNode(1)).params_list);

                        parsertools.create_source_context(_formal_parametres, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return _formal_parametres;
                    }

                case (int)RuleConstants.RULE_FORMAL_LIST:
                    //<Formal_list> ::= 
                    return null;

                case (int)RuleConstants.RULE_FORMAL_LIST2:
                    //<Formal_list> ::= <Formal_type_list1>
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_FACT_LIST:
                    //<Fact_list> ::= 
                    return null;

                case (int)RuleConstants.RULE_FACT_LIST2:
                    //<Fact_list> ::= <List_of_expressions>
                    return LRParser.GetReductionSyntaxNode(0);

                //-------------------------- Operators

                case (int)RuleConstants.RULE_FREE_OPERATOR:
                    //<Free_operator> ::= 
                    return null;

                case (int)RuleConstants.RULE_CASE_VARIANT_LIST:
                    //<Case_variant_list> ::= <Case_variant> <Case_variant_list>
                    {
                        if_node _if_node1;
                        if (LRParser.GetReductionSyntaxNode(1) is case_variant)
                        {
                            case_variant _case_variant1 = (case_variant)LRParser.GetReductionSyntaxNode(1);
                            _if_node1 = new if_node((expression)_case_variant1.conditions.expressions[0], GetStatements(_case_variant1.exec_if_true), null);
                            parsertools.create_source_context(_if_node1, LRParser.GetReductionSyntaxNode(1),LRParser.GetReductionSyntaxNode(1)); //make
                        
                        }
                        else
                            _if_node1 = LRParser.GetReductionSyntaxNode(1) as if_node;

                        case_variant _case_variant = (case_variant)LRParser.GetReductionSyntaxNode(0);
                        if_node _if_node = new if_node((expression)_case_variant.conditions.expressions[0], _case_variant.exec_if_true, _if_node1);

                        parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(0))); //make
                        return _if_node;
                    }

                case (int)RuleConstants.RULE_CASE_VARIANT_LIST2:
                    //<Case_variant_list> ::= <Case_variant>
                    {   //unreacheable rule.. ?
                        case_variant _case_variant = (case_variant)LRParser.GetReductionSyntaxNode(0);
                        if_node _if_node = new if_node(GetExpressions(_case_variant.conditions), (statement)_case_variant.exec_if_true, null);

                        parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0)); //make
                        return _if_node;
                    }

                case (int)RuleConstants.RULE_CASE_VARIANT_TK_CASE_V_TK_COLON:
                    //<Case_variant> ::= 'tk_case_v' <Expression> 'tk_Colon' <Statements>
                    {
                        expression_list _expression_list = GetExpressions(LRParser.GetReductionSyntaxNode(1));
                        case_variant _case_variant = new case_variant(_expression_list, GetStatements(LRParser.GetReductionSyntaxNode(3)));

                        //_case_variant.source_context = (GetExpressions(LRParser.GetReductionSyntaxNode(1))).source_context;
                        parsertools.create_source_context(_case_variant, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(2)));
                        return _case_variant;
                    }

                case (int)RuleConstants.RULE_STATEMENTS:
                    //<Statements> ::= <Statements> <Separators> <Statement>
                    {
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));
                        _statement_list.subnodes.AddRange(GetStatements(LRParser.GetReductionSyntaxNode(2)).subnodes);

                        parsertools.create_source_context(_statement_list, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2)), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(0)));
                        //parsertools.create_source_context(_statement_list, _statement_list, _statement_list);   //make
                        return _statement_list;
                    }

                case (int)RuleConstants.RULE_STATEMENTS2:
                    //<Statements> ::= <Statement>
                    {
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(0));

                        parsertools.create_source_context(_statement_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return _statement_list;
                    }

                case (int)RuleConstants.RULE_STATEMENT:
                    //<Statement> ::= <Free_operator>
                    {
                        empty_statement _empty_statement = new empty_statement();

                        return _empty_statement;
                    }

                case (int)RuleConstants.RULE_STATEMENT2:
                    //<Statement> ::= <Declarations>
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_STATEMENT_TK_ASSIGN:
                    //<Statement> ::= <Value> 'tk_Assign' <Expression>
                    {
                        assign _assign = new assign((addressed_value)LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);

                        parsertools.create_source_context(_assign, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _assign;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_IF_TK_THEN_TK_END_ALL:
                    //<Statement> ::= 'tk_if' <Expression> 'tk_then' <Statements> 'tk_end_all'
                    {
                        if_node _if_node = new if_node((expression)LRParser.GetReductionSyntaxNode(1), GetStatements(LRParser.GetReductionSyntaxNode(3)), null);

                        parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(4), LRParser.GetReductionSyntaxNode(2)));
                        return _if_node;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_IF_TK_THEN_TK_ELSE_TK_END_ALL:
                    //<Statement> ::= 'tk_if' <Expression> 'tk_then' <Statements> 'tk_else' <Statements> 'tk_end_all'
                    {
                        if_node _if_node = new if_node((expression)LRParser.GetReductionSyntaxNode(1), GetStatements(LRParser.GetReductionSyntaxNode(3)), GetStatements(LRParser.GetReductionSyntaxNode(5)));

                        parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(6), LRParser.GetReductionSyntaxNode(2)));
                        return _if_node;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_BEGIN_CYCLE_TK_RAZ_TK_END_CYCLE:
                    //<Statement> ::= 'tk_begin_cycle' <Expression> 'tk_raz' <Statements> 'tk_end_cycle'
                    {   // remake without "_system_loop_var_" !
                        int32_const _int32_const = new int32_const(1);
                        ident loop_var = new ident("&_system_loop_var");
                        statement_list _statement_list = GetStatements(LRParser.GetReductionSyntaxNode(3));

                        for_node _for_node = new for_node(loop_var, _int32_const, (expression)LRParser.GetReductionSyntaxNode(1), _statement_list, for_cycle_type.to, null, null, true);

                        parsertools.create_source_context(_for_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(4), LRParser.GetReductionSyntaxNode(1)));
                        if ((_statement_list as statement).source_context != null)
                            parsertools.create_source_context(_statement_list, LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_for_node, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(4));
                        return _for_node;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_BEGIN_CYCLE_TK_FOR_TK_IDENTIFIER_TK_FROM_TK_TO_TK_END_CYCLE:
                    //<Statement> ::= 'tk_begin_cycle' 'tk_for' 'tk_Identifier' 'tk_from' <Expression> 'tk_to' <Expression> <Statements> 'tk_end_cycle'
                    {
                        for_node _for_node = new for_node((ident)LRParser.GetReductionSyntaxNode(2), (expression)LRParser.GetReductionSyntaxNode(4), (expression)LRParser.GetReductionSyntaxNode(6), GetStatements(LRParser.GetReductionSyntaxNode(7)), for_cycle_type.to, null, null, false);

                        parsertools.create_source_context(_for_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(8), LRParser.GetReductionSyntaxNode(1)));
                        parsertools.create_source_context(GetStatements(LRParser.GetReductionSyntaxNode(7)), LRParser.GetReductionSyntaxNode(7), LRParser.GetReductionSyntaxNode(7));
                        return _for_node;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_BEGIN_CYCLE_TK_WHILE_TK_END_CYCLE:
                    //<Statement> ::= 'tk_begin_cycle' 'tk_while' <Expression> <Statements> 'tk_end_cycle'
                    {
                        while_node _while_node = new while_node((expression)LRParser.GetReductionSyntaxNode(2), GetStatements(LRParser.GetReductionSyntaxNode(3)), WhileCycleType.While);

                        parsertools.create_source_context(_while_node, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(4));
                        return _while_node;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_CASE_TK_END_ALL:
                    //<Statement> ::= 'tk_case' <Separators Opt> <Case_variant_list> 'tk_end_all'
                    {
                        if_node _if_node;
                        if (LRParser.GetReductionSyntaxNode(2) is case_variant)
                        {
                            case_variant _case_variant = (case_variant)LRParser.GetReductionSyntaxNode(2);
                            _if_node = new if_node((expression)_case_variant.conditions.expressions[0], (statement)_case_variant.exec_if_true, null);

                            parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1)));   //make                       
                            return _if_node;
                        }
                        else{
                            if_node _if_node1;
                            _if_node = (if_node)LRParser.GetReductionSyntaxNode(2);
                            _if_node1 = _if_node;
                            while (_if_node1.else_body is if_node)
                                _if_node1 = _if_node1.else_body as if_node;

                            _if_node1.else_body = null;
                            parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1)));
                            return _if_node;

                        }
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_CASE_TK_ELSE_TK_END_ALL:
                    //<Statement> ::= 'tk_case' <Separators Opt> <Case_variant_list> 'tk_else' <Statements> 'tk_end_all'
                    {
                        if_node _if_node;
                        if (LRParser.GetReductionSyntaxNode(2) is case_variant)
                        {
                            case_variant _case_variant = (case_variant)LRParser.GetReductionSyntaxNode(2);
                            _if_node = new if_node((expression)_case_variant.conditions.expressions[0], (statement)_case_variant.exec_if_true, GetStatements(LRParser.GetReductionSyntaxNode(4)));

                            parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(5), LRParser.GetReductionSyntaxNode(4), LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1)));   //make                       
                            return _if_node;
                        }
                        else
                        {
                            if_node _if_node1;
                            _if_node = (if_node)LRParser.GetReductionSyntaxNode(2);
                            _if_node1 = _if_node;
                            while (_if_node1.else_body is if_node)
                               _if_node1 = _if_node1.else_body as if_node;
                                
                            
                            _if_node1.else_body = GetStatements(LRParser.GetReductionSyntaxNode(4));
                           // _if_node1.else_body.source_context.end_position
                            //parsertools.create_source_context(_if_node1, LRParser.GetReductionSyntaxNode(2), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(5), LRParser.GetReductionSyntaxNode(4), LRParser.GetReductionSyntaxNode(3)));   //make                       
                            parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(5), LRParser.GetReductionSyntaxNode(4), LRParser.GetReductionSyntaxNode(3), LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(1)));   //make                       
                            return _if_node;
                        }
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_ASSERT:
                    //<Statement> ::= 'tk_assert' <Expression>
                    {   //make it!
                        procedure_call _procedure_call = new procedure_call();
                        expression_list _expression_list = new expression_list();
                        _expression_list.expressions.Add((expression)LRParser.GetReductionSyntaxNode(1));
                        method_call _method_call = new method_call(_expression_list);
                        _method_call.dereferencing_value = new ident("assert");
                        _procedure_call.func_name = _method_call;

                        parsertools.create_source_context(_method_call.dereferencing_value, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_expression_list, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_procedure_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));

                        return _procedure_call;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_READ:
                    //<Statement> ::= 'tk_read' <Id_list1>
                    {
                        procedure_call _procedure_call = new procedure_call();
                        expression_list _expression_list = new expression_list();
                        ident_list _ident_list = GetIdents(LRParser.GetReductionSyntaxNode(1));

                        for (int i = 0; i < _ident_list.idents.Count; i++)
                        {
                            _expression_list.expressions.Add(_ident_list.idents[i] as expression);
                        }
                        _ident_list.idents.Clear();

                        method_call _method_call = new method_call(_expression_list);
                        _method_call.dereferencing_value = new ident("read");
                        _procedure_call.func_name = _method_call;

                        parsertools.create_source_context(_method_call.dereferencing_value, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_ident_list, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_procedure_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return _procedure_call;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_WRITE:
                    //<Statement> ::= 'tk_write' <List_of_expressions>
                    {
                        procedure_call _procedure_call = new procedure_call();
                        expression_list _expression_list = GetExpressions(LRParser.GetReductionSyntaxNode(1));
                        method_call _method_call = new method_call(_expression_list);
                        _method_call.dereferencing_value = new ident("write");
                        _procedure_call.func_name = _method_call;

                        parsertools.create_source_context(_method_call.dereferencing_value, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_expression_list, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_procedure_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return _procedure_call;
                    }

                case (int)RuleConstants.RULE_STATEMENT_TK_IDENTIFIER_TK_ROUNDOPEN_TK_ROUNDCLOSE:
                    //<Statement> ::= 'tk_Identifier' 'tk_RoundOpen' <Fact_list> 'tk_RoundClose'
                    {
                        procedure_call _procedure_call = new procedure_call();
                        method_call _method_call;
                        expression_list _expression_list;

                        if (LRParser.GetReductionSyntaxNode(2) != null)
                        {
                            _expression_list = GetExpressions(LRParser.GetReductionSyntaxNode(2));
                            _method_call = new method_call(_expression_list);
                        }
                        else
                            _method_call = new method_call();


                        _method_call.dereferencing_value = new ident(((ident)LRParser.GetReductionSyntaxNode(0)).name);
                        _procedure_call.func_name = _method_call;

                        parsertools.create_source_context(_method_call.dereferencing_value, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        //parsertools.create_source_context(_expression_list, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        parsertools.create_source_context(_procedure_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        return _procedure_call;
                    }


                case (int)RuleConstants.RULE_STATEMENT_TK_IDENTIFIER:
                    //<Statement> ::= 'tk_Identifier'
                    {
                        procedure_call _procedure_call = new procedure_call();
                        method_call _method_call = new method_call(null);
                        _method_call.dereferencing_value = new ident(((ident)LRParser.GetReductionSyntaxNode(0)).name);
                        _procedure_call.func_name = _method_call;

                        parsertools.create_source_context(_method_call.dereferencing_value, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0)); parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        parsertools.create_source_context(_procedure_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
                        return _procedure_call;
                    }

                case (int)RuleConstants.RULE_EXPRESSION_TK_GREATER:
                    //<Expression> ::= <Expression> 'tk_Greater' <Add Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);

                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_EXPRESSION_TK_LOWER:
                    //<Expression> ::= <Expression> 'tk_Lower' <Add Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_EXPRESSION_TK_LOWEREQUAL:
                    //<Expression> ::= <Expression> 'tk_LowerEqual' <Add Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_EXPRESSION_TK_GREATEREQUAL:
                    //<Expression> ::= <Expression> 'tk_GreaterEqual' <Add Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_EXPRESSION_TK_EQUAL:
                    //<Expression> ::= <Expression> 'tk_Equal' <Add Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_EXPRESSION_TK_NOTEQUAL:
                    //<Expression> ::= <Expression> 'tk_NotEqual' <Add Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_EXPRESSION:
                    //<Expression> ::= <Add Exp>
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_ADDEXP_TK_OR:
                    //<Add Exp> ::= <Add Exp> 'tk_or' <Mult Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_ADDEXP_TK_PLUS:
                    //<Add Exp> ::= <Add Exp> 'tk_Plus' <Mult Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_ADDEXP_TK_MINUS:
                    //<Add Exp> ::= <Add Exp> 'tk_Minus' <Mult Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_ADDEXP:
                    //<Add Exp> ::= <Mult Exp>
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_MULTEXP_TK_AND:
                    //<Mult Exp> ::= <Mult Exp> 'tk_and' <Power Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_MULTEXP_TK_MULT:
                    //<Mult Exp> ::= <Mult Exp> 'tk_Mult' <Power Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_MULTEXP_TK_DIV:
                    //<Mult Exp> ::= <Mult Exp> 'tk_Div' <Power Exp>
                    {
                        bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        return _bin_expr;
                    }

                case (int)RuleConstants.RULE_MULTEXP:
                    //<Mult Exp> ::= <Power Exp>
                    return LRParser.GetReductionSyntaxNode(0);    //make it!

                case (int)RuleConstants.RULE_POWEREXP_TK_POWER:
                    {
                        //<Power Exp> ::= <Negate Exp> 'tk_Power' <Power Exp>

                        expression_list _expression_list = new expression_list();
                        _expression_list.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);
                        _expression_list.expressions.Add(LRParser.GetReductionSyntaxNode(2) as expression);
                        method_call _method_call = new method_call(_expression_list);
                        _method_call.dereferencing_value = new ident("Power");
                        parsertools.create_source_context(_method_call.dereferencing_value, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));
                        return _method_call;

                        //bin_expr _bin_expr = new bin_expr(LRParser.GetReductionSyntaxNode(0) as expression, LRParser.GetReductionSyntaxNode(2) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(1)).type);
                        //parsertools.create_source_context(_bin_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(2));

                        //return _bin_expr;
                    }
                case (int)RuleConstants.RULE_POWEREXP:
                    //<Power Exp> ::= <Negate Exp>
                    return LRParser.GetReductionSyntaxNode(0);    //make it!

                case (int)RuleConstants.RULE_NEGATEEXP_TK_MINUS:
                    //<Negate Exp> ::= 'tk_Minus' <Value>
                    {
                        un_expr _un_expr = new un_expr(LRParser.GetReductionSyntaxNode(1) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(0)).type);
                        parsertools.create_source_context(_un_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));

                        return _un_expr;
                    }

                case (int)RuleConstants.RULE_NEGATEEXP_TK_NOT:
                    //<Negate Exp> ::= 'tk_not' <Value>
                    {
                        un_expr _un_expr = new un_expr(LRParser.GetReductionSyntaxNode(1) as expression, ((op_type_node)LRParser.GetReductionSyntaxNode(0)).type);
                        parsertools.create_source_context(_un_expr, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));

                        return _un_expr;
                    }

                case (int)RuleConstants.RULE_NEGATEEXP:
                    //<Negate Exp> ::= <Value>
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_VALUE_TK_IDENTIFIER:
                    //<Value> ::= 'tk_Identifier'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_VALUE_TK_FUNC_VAL:
                    //<Value> ::= 'tk_func_val'
                    return new ident("result");

                case (int)RuleConstants.RULE_VALUE_TK_INTEGER:
                    //<Value> ::= 'tk_integer'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_VALUE_TK_REAL:
                    //<Value> ::= 'tk_real'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_VALUE_TK_TRUE:
                    //<Value> ::= 'tk_true'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_VALUE_TK_FALSE:
                    //<Value> ::= 'tk_false'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_VALUE_TK_STRINGLITERAL:
                    //<Value> ::= 'tk_StringLiteral'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_VALUE_TK_CHAR:
                    //<Value> ::= 'tk_char'
                    return LRParser.GetReductionSyntaxNode(0);

                case (int)RuleConstants.RULE_VALUE_TK_EOL:
                    //<Value> ::= 'tk_eol'
                    {
                        literal_const_line _literal_const_line = new literal_const_line();
                        sharp_char_const _sharp_char_const_13 = new sharp_char_const(13);
                        sharp_char_const _sharp_char_const_10 = new sharp_char_const(10);
                        _literal_const_line.literals.Add(_sharp_char_const_13);
                        _literal_const_line.literals.Add(_sharp_char_const_10);

                        parsertools.create_source_context(_sharp_char_const_13, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));    //make
                        parsertools.create_source_context(_sharp_char_const_10, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));    //make
                        parsertools.create_source_context(_literal_const_line, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));     //make
                        return _literal_const_line;
                    }

                case (int)RuleConstants.RULE_VALUE_TK_IDENTIFIER_TK_SQUAREOPEN_TK_SQUARECLOSE_TK_SQUAREOPEN_TK_SQUARECLOSE:
                    //<Value> ::= 'tk_Identifier' 'tk_SquareOpen' <Fact_list> 'tk_SquareClose' 'tk_SquareOpen' <Expression> 'tk_SquareClose'
                    {

                        indexer _indexer = new indexer(GetExpressions(LRParser.GetReductionSyntaxNode(2)));
                        indexer _indexer1 = new indexer(GetExpressions(LRParser.GetReductionSyntaxNode(5)));
                        _indexer.dereferencing_value = LRParser.GetReductionSyntaxNode(0) as ident;
                        _indexer1.dereferencing_value = _indexer;
                        parsertools.create_source_context(_indexer, LRParser.GetReductionSyntaxNode(2), LRParser.GetReductionSyntaxNode(2));
                        parsertools.create_source_context(_indexer, LRParser.GetReductionSyntaxNode(5), LRParser.GetReductionSyntaxNode(5));
                        return _indexer1;
                    }

                case (int)RuleConstants.RULE_VALUE_TK_IDENTIFIER_TK_SQUAREOPEN_TK_SQUARECLOSE:
                    //<Value> ::= 'tk_Identifier' 'tk_SquareOpen' <Fact_list> 'tk_SquareClose'
                    {

                        indexer _indexer = new indexer(GetExpressions(LRParser.GetReductionSyntaxNode(2)));
                        _indexer.dereferencing_value = LRParser.GetReductionSyntaxNode(0) as ident;
                        parsertools.create_source_context(_indexer, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(3));
                        return _indexer;
                    }

                case (int)RuleConstants.RULE_VALUE_TK_IDENTIFIER_TK_ROUNDOPEN_TK_ROUNDCLOSE:
                    //<Value> ::= 'tk_Identifier' 'tk_RoundOpen' <Fact_list> 'tk_RoundClose'
                    {
                        expression_list _expression_list;
                        method_call _method_call;
                        if (LRParser.GetReductionSyntaxNode(2) != null)
                        {
                            _expression_list = GetExpressions(LRParser.GetReductionSyntaxNode(2));
                            _method_call = new method_call(_expression_list);
                        }
                        else
                            _method_call = new method_call();
                        switch (((ident)LRParser.GetReductionSyntaxNode(0)).name)
                        {
                            case "tg": _method_call.dereferencing_value = new ident("tan"); break;
                            case "ctg": _method_call.dereferencing_value = new ident("ctg"); break;
                            case "arctg": _method_call.dereferencing_value = new ident("arctan"); break;
                            case "arcctg": _method_call.dereferencing_value = new ident("arcctg"); break;
                            case "lg": _method_call.dereferencing_value = new ident("log10"); break;
                            case "mod": _method_call.dereferencing_value = new ident("md"); break;
                            case "div": _method_call.dereferencing_value = new ident("dv"); break;
                            case "rnd": _method_call.dereferencing_value = new ident("random"); break;
                            case "int": _method_call.dereferencing_value = new ident("round"); break;

                            default:
                                _method_call.dereferencing_value = new ident(((ident)LRParser.GetReductionSyntaxNode(0)).name);
                                break;
                        }
                        //_method_call.dereferencing_value = LRParser.GetReductionSyntaxNode(0) as ident;

                        parsertools.create_source_context(_method_call.dereferencing_value, LRParser.GetReductionSyntaxNode(1), LRParser.GetReductionSyntaxNode(1));
                        parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
                        return _method_call;
                    }

                case (int)RuleConstants.RULE_VALUE_TK_ROUNDOPEN_TK_ROUNDCLOSE:
                    //<Value> ::= 'tk_RoundOpen' <Expression> 'tk_RoundClose'
                    return LRParser.GetReductionSyntaxNode(1);

            }
            throw new RuleException("Unknown rule");
        }
        private Tuple<type_declaration, List<procedure_definition>> CreateTypeDeclarationWithForwardDeclaration(type_declaration cl)
        {
            var oldClDef = (class_definition) cl.type_def;
            var classDef = SyntaxTreeBuilder.BuildClassDefinition();
            var typeDeclaration = new type_declaration(cl.type_name, classDef);
            classDef.where_section = oldClDef.where_section;
            var procedures = new List<procedure_definition>();
            var classMembers = new class_members(access_modifer.public_modifer);
            classDef.body.class_def_blocks.Add(classMembers);

            foreach (var member in oldClDef.body.class_def_blocks.SelectMany(x => x.members))
            {
                if (member is var_def_statement)
                {
                    classMembers.Add(member);
                }
                else
                {
                    var procDef = (procedure_definition) member;
                    if (procDef.proc_header is constructor)
                    {
                        classMembers.Add(procDef);
                        continue;
                    }
                    procedure_header procHeader;
                    if (procDef.proc_header is function_header)
                    {
                        var fh = (function_header) procDef.proc_header;
                        procHeader = new function_header
                            {
                                name = new method_name(fh.name.meth_name.name),
                                source_context = fh.source_context,
                                parameters = fh.parameters,
                                of_object = fh.of_object,
                                class_keyword = fh.class_keyword
                            };
                        ((function_header)procHeader).return_type = fh.return_type;
                    }
                    else
                    {
                        procHeader = new procedure_header
                            {
                                name = new method_name(procDef.proc_header.name.meth_name.name),
                                source_context = procDef.proc_header.source_context,
                                parameters = procDef.proc_header.parameters,
                                of_object = procDef.proc_header.of_object,
                                class_keyword = procDef.proc_header.class_keyword
                            };
                    }

                    procDef.proc_header.name.class_name = cl.type_name;
                    procedures.Add(procDef);
                    classMembers.Add(procHeader);
                }
            }

            return new Tuple<type_declaration, List<procedure_definition>>(typeDeclaration, procedures);
        }
Esempio n. 26
0
		private procedure_header get_method_header(ICSharpCode.NRefactory.Ast.MethodDeclaration method)
		{
			procedure_header proc_header;
			if (is_void(method.TypeReference))
			{
				proc_header = new procedure_header();
			}
			else
			{
				proc_header = new function_header();
			}
			proc_header.name = new method_name();
			proc_header.name.meth_name = new ident(method.Name);
			proc_header.source_context = get_source_context(method);
			if (proc_header is function_header)
				(proc_header as function_header).return_type = get_type_reference(method.TypeReference);
			proc_header.parameters = get_parameters(method.Parameters);
			proc_header.proc_attributes = new procedure_attributes_list();
			if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Abstract) == ICSharpCode.NRefactory.Ast.Modifiers.Abstract)
				proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_abstract));
			if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Virtual) == ICSharpCode.NRefactory.Ast.Modifiers.Virtual)
				proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_virtual));
			if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Override) == ICSharpCode.NRefactory.Ast.Modifiers.Override)
				proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_override));
			//if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Overloads) == ICSharpCode.NRefactory.Ast.Modifiers.Overloads)
			//	proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_overload));
			if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.New) == ICSharpCode.NRefactory.Ast.Modifiers.New)
				proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_reintroduce));
			if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Static) == ICSharpCode.NRefactory.Ast.Modifiers.Static)
				proc_header.class_keyword = true;
			return proc_header;
		}
        private void visit_procedure_header(SyntaxTree.procedure_header _procedure_header)
        {
            if (_procedure_header.name != null && _procedure_header.name.meth_name is SyntaxTree.operator_name_ident &&
                !SyntaxTree.OperatorServices.IsAssigmentOperator((_procedure_header.name.meth_name as SyntaxTree.operator_name_ident).operator_type))
            {
                AddError(new OverloadOperatorCanNotBeProcedure(get_location(_procedure_header)));
            }
            if (_procedure_header is SyntaxTree.constructor &&
                (_procedure_header.template_args != null || (_procedure_header.name != null && _procedure_header.name.meth_name != null && _procedure_header.name.meth_name is SyntaxTree.template_type_name)))
            {
                AddError(get_location(_procedure_header), "CONSTRUCTOR_CAN_NOT_BE_GENERIC");
            }
            current_function_header = _procedure_header;
            hard_node_test_and_visit(_procedure_header.name);
            current_function_header = null;
            if (context.converted_template_type != null)
            {
                return;
            }
            if (_procedure_header.template_args != null)
            {
                visit_generic_params(context.top_function, _procedure_header.template_args.idents);
            }
            weak_node_test_and_visit(_procedure_header.parameters);
            if (_procedure_header.name.class_name != null) 
            	with_class_name = true;
            if (_procedure_header.class_keyword && !has_static_attr(_procedure_header.proc_attributes.proc_attributes))
            {
                SyntaxTree.procedure_attribute pa = new SyntaxTree.procedure_attribute(PascalABCCompiler.SyntaxTree.proc_attribute.attr_static);
                pa.source_context = _procedure_header.source_context;
                _procedure_header.proc_attributes.proc_attributes.Add(pa);
            }
            
            weak_node_test_and_visit(_procedure_header.proc_attributes);
			with_class_name = false;
            CheckOverrideOrReintroduceExpectedWarning(get_location(_procedure_header));
            if (context.top_function != null && context.top_function is common_namespace_function_node && (context.top_function as common_namespace_function_node).ConnectedToType != null && !context.top_function.IsOperator)
            {
                concrete_parameter_type cpt = concrete_parameter_type.cpt_none;
                SemanticTree.parameter_type pt = PascalABCCompiler.SemanticTree.parameter_type.value;
                if ((context.top_function as common_namespace_function_node).ConnectedToType.is_value_type)
                {
                    cpt = concrete_parameter_type.cpt_var;
                    pt = PascalABCCompiler.SemanticTree.parameter_type.var;
                }
                type_node cur_tn = (context.top_function as common_namespace_function_node).ConnectedToType;
                type_node self_type = cur_tn;
                if (context.top_function.generic_params != null && self_type.is_generic_type_definition)
                {
                    self_type = self_type.get_instance(context.top_function.get_generic_params_list());
                }
                if (!has_extensionmethod_attr(_procedure_header.proc_attributes.proc_attributes))
                {
                    common_parameter cp = new common_parameter(compiler_string_consts.self_word, self_type, pt,
                                                                                context.top_function, cpt, null, null);

                    context.top_function.parameters.AddElementFirst(cp);
                    context.top_function.scope.AddSymbol(compiler_string_consts.self_word, new SymbolInfo(cp));
                }
            }
            if (_procedure_header is SyntaxTree.constructor)
            {
                common_method_node cmnode = context.top_function as common_method_node;
                if (cmnode != null)
                {
                    cmnode.is_constructor = true;
                    cmnode.return_value_type = context.converted_type;
                }
                else if (context.top_function is common_namespace_function_node && (context.top_function as common_namespace_function_node).ConnectedToType != null)
                    AddError(get_location(_procedure_header), "EXTENSION_CONSTRUCTOR_NOT_ALLOWED");
                else
                if (context.converted_compiled_type != null)
                    AddError(get_location(_procedure_header), "EXTENSION_CONSTRUCTOR_NOT_ALLOWED");
            }

            bool unique = context.close_function_params(body_exists);

            if (context.converted_type != null && context.converted_type.IsInterface)
            {
                if (body_exists)
                {
                    AddError(new InterfaceFunctionWithBody(get_location(_procedure_header)));
                }
                common_method_node cmnode = context.top_function as common_method_node;
                context.set_virtual_abstract(cmnode);
            }
			
            if (context.converted_type != null)
            {
            	common_method_node cmnode = context.top_function as common_method_node;
            	if (cmnode != null && cmnode.polymorphic_state == SemanticTree.polymorphic_state.ps_virtual_abstract && body_exists)
            	{
            		AddError(new AbstractMethodWithBody(get_location(_procedure_header)));
            	}
            }
            if (_procedure_header.where_defs != null)
            {
                if (unique)
                {
                    visit_where_list(_procedure_header.where_defs);
                }
                else
                {
                    AddError(get_location(_procedure_header.where_defs), "WHERE_SECTION_MUST_BE_ONLY_IN_FIRST_DECLARATION");
                }
            }
            assign_doc_info(context.top_function,_procedure_header);
            if (_procedure_header.attributes != null)
            {
            	make_attributes_for_declaration(_procedure_header, context.top_function);
            }
            /*if (_procedure_header.name != null && context.converted_compiled_type != null && context.top_function is common_namespace_function_node)
            {
                if (context.FindMethodToOverride(context.top_function as common_namespace_function_node) != null)
                    AddError(new CanNotDeclareExtensionMethodAsOverrided(get_location(_procedure_header)));
            }*/
            if (context.converted_type != null && has_dll_import_attribute(context.top_function))
            	AddError(get_dll_import_attribute(context.top_function).location, "DLLIMPORT_ATTRIBUTE_CANNOT_BE_APPLIED_TO_METHOD");
            if (!body_exists)
            {
                if (_procedure_header.name.class_name != null && context.converted_explicit_interface_type != null)
                {
                    AddError(get_location(_procedure_header), "EXPLICIT_IMPLEMENTATION_EXPECTED");
                }
                if ((context.top_function.semantic_node_type == semantic_node_type.common_method_node)
                    || ((context.func_stack_size_is_one()) && (_is_interface_part)))
                {
                    context.leave_block();
                    if (_procedure_header.name.class_name != null && context.converted_compiled_type != null)
                        context.converted_compiled_type = null;
                }
            }
            body_exists = false;
           
        }
 private bool IsForward(procedure_header hdr)
 {
 	if (hdr.proc_attributes == null) return false;
 	for (int i=0; i<hdr.proc_attributes.proc_attributes.Count; i++)
 		if (hdr.proc_attributes.proc_attributes[i].attribute_type == proc_attribute.attr_forward)
 		return true;
 	return false;
 }
		public void write_procedure_header(procedure_header _procedure_header)
		{
			write_type_definition(_procedure_header);
			if (_procedure_header.parameters == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_procedure_header.parameters.visit(this);
			}
			if (_procedure_header.proc_attributes == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_procedure_header.proc_attributes.visit(this);
			}
			if (_procedure_header.name == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_procedure_header.name.visit(this);
			}
			bw.Write(_procedure_header.of_object);
			bw.Write(_procedure_header.class_keyword);
			if (_procedure_header.template_args == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_procedure_header.template_args.visit(this);
			}
			if (_procedure_header.where_defs == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_procedure_header.where_defs.visit(this);
			}
		}
Esempio n. 30
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public procedure_definition(procedure_header _proc_header,proc_block _proc_body)
		{
			this._proc_header=_proc_header;
			this._proc_body=_proc_body;
		}