public override void visit(ident id)
        {
            // Check dot node
            var upper = UpperNode(1);
            //if (upper is dot_node)
            //    return;

            var idName = id.name;
            var idSourceContext = id.source_context;

            if (idName.ToLower() == "self")
            {
                var newSelf = new dot_node(new ident("self"), new ident(Consts.Self));
                Replace(id, newSelf);
            }

            // Detect where is id from
            if (CollectedLocals.Contains(idName))
            {
                Replace(id, new ident(CapturedLocalsMap[idName], idSourceContext));
            }
            else if (CollectedFormalParams.Contains(idName))
            {
                Replace(id, new ident(CapturedFormalParamsMap[idName], idSourceContext));
            }
            else if (IsInClassMethod)
            {
                // In class -> check fields
                if (CollectedClassFields.Contains(idName))
                {
                    // Good
                    // Name in class fields -> capture as class field

                    var capturedId = new dot_node(new dot_node(new ident("self"), new ident(Consts.Self)), id);
                    Replace(id, capturedId);
                }
                else
                {
                    // Bad
                    // At syntax we don't know if the name is class field or not coz of e.g. base .NET classes
                    // HERE WE SHOULD REPLACE TO yield_unknown_reference -> so decision is passed to semantic
                    // Check for globals will be processed at semantic, too
                }
            }
            else
            {
                // Not in class -> check globals
                if (CollectedUnitGlobals.Contains(idName))
                {
                    // Global -> just do nothing
                }
                else
                {
                    // What about static classes - search at semantic
                    // HERE WE SHOULD REPLACE TO yield_unknown_reference -> so decision is passed to semantic
                }
            }
        }
示例#2
0
		public override void visit(dot_node _dot_node)
		{
			prepare_node(_dot_node.left,"left");
			prepare_node(_dot_node.right,"right");
		}
		public void visit(dot_node _dot_node)
		{
			bw.Write((Int16)63);
			write_dot_node(_dot_node);
		}
        private void dot_node_as_expression_dot_ident(expression_node en, SyntaxTree.ident id_right, motivation mot, addressed_value syntax_node)
        {
            if (en is typed_expression)
                try_convert_typed_expression_to_function_call(ref en);
            SymbolInfo si = en.type.find_in_type(id_right.name, context.CurrentScope);
            if (si == null)
            {
                AddError(new MemberIsNotDeclaredInType(id_right, get_location(id_right), en.type));
            }

            try_convert_typed_expression_to_function_call(ref en);

            /*
            if (en.semantic_node_type == semantic_node_type.typed_expression)
            {
                type_node tn11=en.type;
                delegated_methods dm11=tn11 as delegated_methods;
                if (dm11!=null)
                {
                    en = dm11.empty_param_method;
                }
            }
            */

            switch (mot)
            {
                case motivation.address_reciving:
                    {
                        return_addressed_value(address_expression_reciving(id_right, si, en));
                        return;
                    }
                case motivation.expression_evaluation:
                    {
                        //en = expression_value_reciving(id_right, si, en, true);
            			//try_convert_typed_expression_to_function_call(ref en);
            			//return_value(en);
                        if (si.sym_info is function_node && (si.sym_info as function_node).is_extension_method)
                        {
                            dot_node dnode = new dot_node(syntax_node, id_right);
                            method_call mc = new method_call(dnode, new expression_list());
                            mc.visit(this);
                            return;
                        }
                        return_value(expression_value_reciving(id_right, si, en, true));
                        return;
                    }
                case motivation.semantic_node_reciving:
                    {
                        return_semantic_value(expression_value_reciving(id_right, si, en, true));
                        return;
                    }
            }
            throw new CompilerInternalError("Invalid motivation.");
        }
 private SyntaxTree.procedure_call ConvertOperatorToProcedureCall(SyntaxTree.assign _assign)
 {
     SyntaxTree.ident operator_name = new PascalABCCompiler.SyntaxTree.ident(name_reflector.get_name(_assign.operator_type));
     operator_name.source_context = _assign.to.source_context;
     SyntaxTree.dot_node dot = new PascalABCCompiler.SyntaxTree.dot_node(_assign.to, operator_name);
     dot.source_context = _assign.to.source_context;
     SyntaxTree.expression_list exprlist = new SyntaxTree.expression_list();
     exprlist.expressions.Add(_assign.from);
     exprlist.source_context = _assign.to.source_context;
     SyntaxTree.method_call add_methcall = new SyntaxTree.method_call(exprlist);
     add_methcall.dereferencing_value = dot;
     add_methcall.source_context = _assign.source_context;
     SyntaxTree.procedure_call add_proccall = new SyntaxTree.procedure_call(add_methcall);
     add_proccall.source_context = _assign.source_context;
     return add_proccall;
 }
示例#6
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public closure_substituting_node(string _name,dot_node _substitution,SourceContext sc)
		{
			this._name=_name;
			this._substitution=_substitution;
			source_context = sc;
		}
 public override void visit(dot_node dn)
 {
     ProcessNode(dn.left);
     if (dn.right.GetType() != typeof(ident))
         ProcessNode(dn.right);
 }
 public override void visit(dot_node _dot_node)
 {
     ProcessNode(_dot_node.left);
     //правую часть не обходим
 }
public Object CreateNonTerminalObject(int ReductionRuleIndex)
{
switch (ReductionRuleIndex)
{
    case (int)RuleConstants.RULE_MODULE_TKMODULE_TKMAINIDENT_TKWHERE :
	//<module> ::= 'tkModule' 'tkMainIdent' 'tkWhere' <reference> <imports> <body> <empty>
{
ident_list _ident_list = new ident_list();
    _ident_list.idents.Add(new ident("LibForHaskell"));
    unit_or_namespace _unit_or_namespace = new unit_or_namespace(_ident_list);
    uses_list ul = (uses_list)LRParser.GetReductionSyntaxNode(4);
    if (ul == null)
        ul = new uses_list();
    ul.units.Insert(0, _unit_or_namespace);
    ////////////////
    declarations _defs = new declarations();
    for (int i = 0; i < _function_lambda_definitions.Count; i++)
        _defs.defs.Add((declaration)lambda((function_lambda_definition)_function_lambda_definitions[i]));
    for (int i = 0; i < _functions.Count; i++)
    {
        _defs.defs.Add((declaration)_functions[i]);
        int k = 1;
        while (k < _function_lambda_definitions_after.Count)
        {
            int j = k;
            while (j < _function_lambda_definitions_after.Count && ((procedure_definition)_functions[i]).proc_header.name.meth_name.name != (string)_function_lambda_definitions_after[j])
                j += 2;
            if (j < _function_lambda_definitions_after.Count)
            {
                _defs.defs.Add((declaration)lambda((function_lambda_definition)_function_lambda_definitions_after[j - 1]));
                _function_lambda_definitions_after.RemoveAt(j);
                _function_lambda_definitions_after.RemoveAt(j - 1);
            }
            k = j;
        }
    }
    int kk = 1;
    while (kk < _function_lambda_definitions_after.Count)
    {
        int j = 0;
        while (j < _defs.defs.Count && ((procedure_definition)_defs.defs[j]).proc_header.name.meth_name.name != (string)_function_lambda_definitions_after[kk])
            j++;
        if (j < _defs.defs.Count)
        {
            _defs.defs.Insert(j+1, (declaration)lambda((function_lambda_definition)_function_lambda_definitions_after[kk - 1]));
            _function_lambda_definitions_after.RemoveAt(kk);
            _function_lambda_definitions_after.RemoveAt(kk - 1);
        }
        else
            kk += 2;
    }

    //for (int i = 0; i < _function_lambda_definitions.Count; i++)
        //_defs.defs.Add(lambda((function_lambda_definition)_function_lambda_definitions[i]));
    for (int i = 0; i < let_where_funcs.Count; i++)
        _defs.defs.Add((procedure_definition)let_where_funcs[i]);
    
    block _block = new block(_defs, ((block)LRParser.GetReductionSyntaxNode(5)).program_code);
                                                ///////////////////////////////////////
											    program_module _program_module = new program_module(null, ul, _block, null);

            									_program_module.Language = LanguageId.PascalABCNET;
            									parsertools.create_source_context(_program_module, parsertools.sc_not_null(null, ul, null, LRParser.GetReductionSyntaxNode(5)), LRParser.GetReductionSyntaxNode(5));
                                                
                                                _functions.Clear();
                                                _function_lambda_definitions.Clear();
                                                func_name.Clear();
                                                lambda_num = 0;
                                                list_method_calls.Clear();
                                                list_method_calls_main.Clear();
                                                list_return_funcs.Clear();
                                                list_return_funcs_main.Clear();
                                                list_params1.Clear();
                                                list_method_calls_lambda.Clear();
                                                last_list_method_calls.Clear();
                                                last_list_method_calls_lambda.Clear();
                                                last_function_lambda_definitions.Clear();
                                          let_funcs1.Clear();
                                                let_funcs_funcs.Clear();
                                                let_func_last.Clear();
                                                let_flag.Clear();
                                                token_where_count = 0;
                                                let_where_funcs_main.Clear();
                                                let_where_funcs.Clear();
                                                token_where = 0;
                                                last_where_funcs.Clear();
                                                let_where_list_params.Clear();
                                                _function_lambda_definitions_main.Clear();
                                                let_stack.Clear();
                                                token_let = 0;
                                                lambda_stack.Clear();

            									return _program_module;
										}
	case (int)RuleConstants.RULE_MODULE :
	//<module> ::= <reference> <imports> <body> <empty>
{
	ident_list _ident_list = new ident_list();
    _ident_list.idents.Add(new ident("LibForHaskell"));
    unit_or_namespace _unit_or_namespace = new unit_or_namespace(_ident_list);
    uses_list ul = (uses_list)LRParser.GetReductionSyntaxNode(1);
    if (ul == null)
        ul = new uses_list();
    ul.units.Insert(0, _unit_or_namespace);
    ////////////////
    declarations _defs = new declarations();
    for (int i = 0; i < _function_lambda_definitions.Count; i++)
        _defs.defs.Add((declaration)lambda((function_lambda_definition)_function_lambda_definitions[i]));
    for (int i = 0; i < _functions.Count; i++)
    {
        _defs.defs.Add((declaration)_functions[i]);
        int k = 1;
        while (k < _function_lambda_definitions_after.Count)
        {
            int j = k;
            while (j < _function_lambda_definitions_after.Count && ((procedure_definition)_functions[i]).proc_header.name.meth_name.name != (string)_function_lambda_definitions_after[j])
                j += 2;
            if (j < _function_lambda_definitions_after.Count)
            {
                _defs.defs.Add((declaration)lambda((function_lambda_definition)_function_lambda_definitions_after[j - 1]));
                _function_lambda_definitions_after.RemoveAt(j);
                _function_lambda_definitions_after.RemoveAt(j - 1);
            }
            k = j - 1;
        }
    }
    int kk = 1;
    while (kk < _function_lambda_definitions_after.Count)
    {
        int j = 0;
        while (j < _defs.defs.Count && ((procedure_definition)_defs.defs[j]).proc_header.name.meth_name.name != (string)_function_lambda_definitions_after[kk])
            j++;
        if (j < _defs.defs.Count)
        {
            _defs.defs.Insert(j + 1, (declaration)lambda((function_lambda_definition)_function_lambda_definitions_after[kk - 1]));
            _function_lambda_definitions_after.RemoveAt(kk);
            _function_lambda_definitions_after.RemoveAt(kk - 1);
        }
        else
            kk += 2;
    }
    block _block = new block(_defs, ((block)LRParser.GetReductionSyntaxNode(2)).program_code);
    ///////////////////////////////
											program_module _program_module = new program_module(null, ul, (block)LRParser.GetReductionSyntaxNode(2), null);

            									_program_module.Language = LanguageId.PascalABCNET;
            									parsertools.create_source_context(_program_module, parsertools.sc_not_null(null, ul, null, LRParser.GetReductionSyntaxNode(2)), LRParser.GetReductionSyntaxNode(2));

                                                _functions.Clear();
                                                _function_lambda_definitions.Clear();
                                                func_name.Clear();
                                                lambda_num = 0;
                                                list_method_calls.Clear();
                                                list_method_calls_main.Clear();
                                                list_return_funcs.Clear();
                                                list_return_funcs_main.Clear();
                                                list_params1.Clear();
                                                list_method_calls_lambda.Clear();
                                                last_list_method_calls.Clear();
                                                last_list_method_calls_lambda.Clear();
                                                last_function_lambda_definitions.Clear();
                                                let_funcs1.Clear();
                                                let_funcs_funcs.Clear();
                                                let_func_last.Clear();
                                                let_flag.Clear();
                                                let_where_funcs.Clear();
                                                token_where_count = 0;
                                                let_where_funcs_main.Clear();
                                                let_where_funcs.Clear();
                                                token_where = 0;
                                                last_where_funcs.Clear();
                                                let_where_list_params.Clear();
                                                _function_lambda_definitions_main.Clear();
                                                let_stack.Clear();
                                                lambda_stack.Clear();
                                                token_let = 0;

            									return _program_module;
										}
    case (int)RuleConstants.RULE_MODULE_TKMODULE_TKIDENT_TKWHERE:
//<module> ::= 'tkModule' 'tkIdent' 'tkWhere' <reference> <imports> <funcs> <empty>
{
    ident_list _ident_list = new ident_list();
    _ident_list.idents.Add(new ident("LibForHaskell"));
    unit_or_namespace _unit_or_namespace = new unit_or_namespace(_ident_list);
    uses_list ul = (uses_list)LRParser.GetReductionSyntaxNode(4);
    if (ul == null)
        ul = new uses_list();
    ul.units.Insert(0, _unit_or_namespace);
    ////////////////
    declarations _defs = new declarations();
    for (int i = 0; i < _function_lambda_definitions.Count; i++)
        _defs.defs.Add((declaration)lambda((function_lambda_definition)_function_lambda_definitions[i]));
    for (int i = 0; i < _functions.Count; i++)
    {
        _defs.defs.Add((declaration)_functions[i]);
        int k = 1;
        while (k < _function_lambda_definitions_after.Count)
        {
            int j = k;
            while (j < _function_lambda_definitions_after.Count && ((procedure_definition)_functions[i]).proc_header.name.meth_name.name != (string)_function_lambda_definitions_after[j])
                j += 2;
            if (j < _function_lambda_definitions_after.Count)
            {
                _defs.defs.Add((declaration)lambda((function_lambda_definition)_function_lambda_definitions_after[j - 1]));
                _function_lambda_definitions_after.RemoveAt(j);
                _function_lambda_definitions_after.RemoveAt(j - 1);
            }
            k = j;
        }
    }
    int kk = 1;
    while (kk < _function_lambda_definitions_after.Count)
    {
        int j = 0;
        while (j < _defs.defs.Count && ((procedure_definition)_defs.defs[j]).proc_header.name.meth_name.name != (string)_function_lambda_definitions_after[kk])
            j++;
        if (j < _defs.defs.Count)
        {
            _defs.defs.Insert(j + 1, (declaration)lambda((function_lambda_definition)_function_lambda_definitions_after[kk - 1]));
            _function_lambda_definitions_after.RemoveAt(kk);
            _function_lambda_definitions_after.RemoveAt(kk - 1);
        }
        else
            kk += 2;
    }

    //for (int i = 0; i < _function_lambda_definitions.Count; i++)
    //_defs.defs.Add(lambda((function_lambda_definition)_function_lambda_definitions[i]));
    for (int i = 0; i < let_where_funcs.Count; i++)
        _defs.defs.Add((procedure_definition)let_where_funcs[i]);

    //////////////////////////interface
    interface_node _interface_node = new interface_node();
    _interface_node.uses_modules = ul;
    _interface_node.using_namespaces = null;
    _interface_node.interface_definitions = LRParser.GetReductionSyntaxNode(5) as declarations;
    ///////////////////////////unit_heading
    unit_name _unit_name = new unit_name((ident)LRParser.GetReductionSyntaxNode(1), UnitHeaderKeyword.Unit);
    initfinal_part _initfinal_part=new initfinal_part();
    unit_module _unit_module = new unit_module(_unit_name, _interface_node, null, _initfinal_part.initialization_sect, _initfinal_part.finalization_sect);
    _unit_module.Language = LanguageId.PascalABCNET;

    _functions.Clear();
    _function_lambda_definitions.Clear();
    func_name.Clear();
    lambda_num = 0;
    list_method_calls.Clear();
    list_method_calls_main.Clear();
    list_return_funcs.Clear();
    list_return_funcs_main.Clear();
    list_params1.Clear();
    list_method_calls_lambda.Clear();
    last_list_method_calls.Clear();
    last_list_method_calls_lambda.Clear();
    last_function_lambda_definitions.Clear();
    let_funcs1.Clear();
    let_funcs_funcs.Clear();
    let_func_last.Clear();
    let_flag.Clear();
    token_where_count = 0;
    let_where_funcs_main.Clear();
    let_where_funcs.Clear();
    token_where = 0;
    last_where_funcs.Clear();
    let_where_list_params.Clear();
    _function_lambda_definitions_main.Clear();
    let_stack.Clear();
    token_let = 0;
    lambda_stack.Clear();

    return _unit_module;
}
	case (int)RuleConstants.RULE_REFERENCE :
	//<reference> ::= 
	//NONTERMINAL:<reference> ::= 
	return null;
	//ENDNONTERMINAL
	case (int)RuleConstants.RULE_REFERENCE_TKREF_TKSTRING :
	//<reference> ::= 'tkRef' 'tkString'
{
            							token_info t1 = new token_info();
            							t1.text = ((ident)LRParser.GetReductionSyntaxNode(0)).name;
            							t1.source_context = ((ident)LRParser.GetReductionSyntaxNode(0)).source_context;
            							token_info t2 = new token_info();
            							t2.text = ((string_const)LRParser.GetReductionSyntaxNode(1)).Value;
            							t2.source_context = ((string_const)LRParser.GetReductionSyntaxNode(1)).source_context;
            							compiler_directive cd = new compiler_directive(t1, t2);
            							parsertools.create_source_context(cd, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
            							CompilerDirectives.Add(cd);
            							return null;
        							}
	case (int)RuleConstants.RULE_IMPORTS :
	//<imports> ::= 
	//NONTERMINAL:<imports> ::= 
	return null;
	//ENDNONTERMINAL
	case (int)RuleConstants.RULE_IMPORTS2 :
	//<imports> ::= <import> <empty>
{
            							uses_list _uses_list = new uses_list();

            							_uses_list.units.Add((unit_or_namespace)LRParser.GetReductionSyntaxNode(0));

            							return _uses_list;
        							}
    case (int)RuleConstants.RULE_IMPORTS3:
//<imports> ::= <imports> <empty> <import>
{
            							uses_list _uses_list = (uses_list)LRParser.GetReductionSyntaxNode(0);
            							_uses_list.units.Add((unit_or_namespace)LRParser.GetReductionSyntaxNode(2));

            							return _uses_list;
        							}
	case (int)RuleConstants.RULE_IMPORT_TKIMPORT_TKIDENT :
	//<import> ::= 'tkImport' 'tkIdent'
{
            							ident_list _ident_list = new ident_list();
            							_ident_list.source_context = ((ident)LRParser.GetReductionSyntaxNode(1)).source_context;
            							_ident_list.idents.Add((ident)LRParser.GetReductionSyntaxNode(1));

            							unit_or_namespace _unit_or_namespace = new unit_or_namespace(_ident_list);
            							parsertools.create_source_context(_unit_or_namespace,_ident_list, _ident_list);

            							return _unit_or_namespace;
        							}
	case (int)RuleConstants.RULE_BODY :
	//<body> ::= <main_func>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_BODY2 :
	//<body> ::= <funcs> <main_func>

								{
            							token_info _token_info = new token_info(";");

           								_token_info.source_context = parsertools.GetTokenSourceContext();

            							block _block = new block((declarations)LRParser.GetReductionSyntaxNode(0), ((block)LRParser.GetReductionSyntaxNode(1)).program_code);

            							parsertools.create_source_context(_block, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(0), ((block)LRParser.GetReductionSyntaxNode(1)).program_code), _token_info);
            							return _block;
       							}

	case (int)RuleConstants.RULE_FUNCS :
	//<funcs> ::= <funcs_variants> <empty>
{
           								declarations _declarations = new declarations();
                                                      ArrayList funcs = (ArrayList)LRParser.GetReductionSyntaxNode(0);
                                        			for (int i = 0;i < funcs.Count;i++)
                                        			{
                                            			_declarations.defs.Add((declaration)funcs[i]);
                                            			parsertools.create_source_context(_declarations, parsertools.sc_not_null(_declarations, (declaration)funcs[i]), (declaration)funcs[i]);
                                        			}

                                        			param_value_list.Clear();
                                                      param_value_list_main.Clear();
                                        			body_variant_list.Clear();
                                        			body_variant_list_main.Clear();
								      guard_list.Clear();
                                                      guard_list_main.Clear();
							            list_params_main.Clear();
                                                      list_params.Clear();
                                                      list_param.Clear();
                                                      list_params_temp.Clear();
                                                      where_flag = false;
                                                      decls_counts = 0;
                                                      let_where_funcs.Clear();
            						      return _declarations;
        							}
	case (int)RuleConstants.RULE_FUNCS_VARIANTS :
	//<funcs_variants> ::= <variants> <empty>
{
param_value_list_main.Add(param_value_list.Clone());
    body_variant_list_main.Add(body_variant_list.Clone());
    list_method_calls_main.Add(list_method_calls.Clone());
    guard_list_main.Add(guard_list.Clone());
    list_params_main.Add(list_params.Clone());
    list_params.Clear();

    ArrayList funcs = new ArrayList();
    
    for (int k = 0; k < func_name.Count; k++)
    {
        //////////////////////////head

        method_name _method_name = new method_name(null, (ident)func_name[k], null);
        parsertools.create_source_context(_method_name, func_name[k], func_name[k]);

        function_header _function_header = new function_header();

        object rt = new object();
        _function_header.name = _method_name;
        if (_function_header.name.meth_name is template_type_name)
        {
            _function_header.template_args = (_function_header.name.meth_name as template_type_name).template_args;
            ident id = new ident(_function_header.name.meth_name.name);
            parsertools.create_source_context(id, _function_header.name.meth_name, _function_header.name.meth_name);
            _function_header.name.meth_name = id;
        }
        ////////////////////////////////params
        formal_parameters _formal_parametres = new formal_parameters();
        expression_list f = null;
        if (((ArrayList)param_value_list_main[k])[0] != null)
        {
            f = (expression_list)((ArrayList)param_value_list_main[k])[((ArrayList)param_value_list_main[k]).Count - 1];
            string s = "";
            for (int i = 0; i < ((ArrayList)param_value_list_main[k]).Count; i++)
            {
                for (int j = 0; j < ((expression_list)((ArrayList)param_value_list_main[k])[i]).expressions.Count; j++)
                    if (((expression_list)((ArrayList)param_value_list_main[k])[i]).expressions[j] is ident)
                        s += ((ident)((expression_list)((ArrayList)param_value_list_main[k])[i]).expressions[j]).name;
            }
            for (int i = 0; i < ((expression_list)((ArrayList)param_value_list_main[k])[((ArrayList)param_value_list_main[k]).Count - 1]).expressions.Count; i++)
            {
                ident_list _ident_list = new ident_list();
                ident id = new ident(s + i.ToString());
                _ident_list.source_context = id.source_context;
                _ident_list.idents.Add(id);
                named_type_reference _named_type_reference1 = new named_type_reference();

                ident idtype1 = new ident("datatype");
                _named_type_reference1.source_context = idtype1.source_context;
                _named_type_reference1.names.Add(idtype1);

                typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference1, parametr_kind.none, null);
                parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference1);

                _formal_parametres.params_list.Add(_typed_parametres);
            }
            _function_header.parameters = _formal_parametres;
        }
        //////////////////////////type
        {
            named_type_reference _named_type_reference11 = new named_type_reference();
            ident idtype11 = new ident("datatype");
            _named_type_reference11.source_context = idtype11.source_context;
            _named_type_reference11.names.Add(idtype11);

            rt = _named_type_reference11;
            _function_header.return_type = (type_definition)_named_type_reference11;
        }

        _function_header.of_object = false;
        _function_header.class_keyword = false;
        token_info _token_info = new token_info("function");
        _token_info.source_context = parsertools.GetTokenSourceContext();
        parsertools.create_source_context(_function_header, _token_info, rt);
        
        //////////////////////////////////////block
        statement_list stmt_l = new statement_list();

        statement last_if = null;
        ArrayList vars = new ArrayList();
        if (((ArrayList)param_value_list_main[k])[0] != null)
        {
            bool flag = false;
            for (int i = ((ArrayList)body_variant_list_main[k]).Count - 1; i >= 0; i--)
            {
                expression_list pv = (expression_list)((ArrayList)param_value_list_main[k])[i];
                statement body_part = (statement)((ArrayList)body_variant_list_main[k])[i];
                expression guard = null;
                if (i < ((ArrayList)guard_list_main[k]).Count)
                    guard = (expression)((ArrayList)guard_list_main[k])[i];

                if_node _if_node = new if_node(null, body_part, last_if);
                parsertools.create_source_context(_if_node, null, parsertools.sc_not_null(body_part, last_if));

                ///////////
                named_type_reference _named_type_reference111 = new named_type_reference();

                ident idtype111 = new ident("datatype");
                _named_type_reference111.source_context = idtype111.source_context;
                _named_type_reference111.names.Add(idtype111);

                expression_list el = new expression_list();
                el.expressions.Add(new ident("true") as expression);
                literal lt;
                string text = "boolean";
                lt = new string_const(text);
                el.expressions.Add(lt as expression);
                /////
                named_type_reference ntr = _named_type_reference111;
                new_expr newexpr = new new_expr(ntr, el, false, null);
                parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference111));
                ///////////
                expression last_expr = newexpr as expression;
                if (guard != null)
                    last_expr = guard;
                for (int j = 0; j < _function_header.parameters.params_list.Count; j++)
                {
                    typed_parameters tp = (typed_parameters)_function_header.parameters.params_list[j];
                    if (j < pv.expressions.Count && !(pv.expressions[j] is ident))//vstavka if (vyhod iz rekursii)
                    {
                        op_type_node _op_type_node = new op_type_node(Operators.Equal);
                        _op_type_node.source_context = parsertools.GetTokenSourceContext();
                        bin_expr _bin_expr = new bin_expr(tp.idents.idents[0] as expression, (expression)pv.expressions[j], _op_type_node.type);
                        parsertools.create_source_context(_bin_expr, tp.idents.idents[0], pv.expressions[j]);

                        op_type_node _op_type_node1 = new op_type_node(Operators.LogicalAND);
                        _op_type_node1.source_context = parsertools.GetTokenSourceContext();
                        bin_expr _bin_expr1 = new bin_expr(_bin_expr, last_expr, _op_type_node1.type);
                        parsertools.create_source_context(_bin_expr1, _bin_expr, last_expr);
                        last_expr = _bin_expr1;
                    }
                }
                _if_node.condition = _ob(last_expr);
                ////novye peremennye
                statement_list _ass = new statement_list();
                for (int j = 0; j < _function_header.parameters.params_list.Count; j++)
                {
                    if (j < pv.expressions.Count && pv.expressions[j] is ident && ((ident)pv.expressions[j]).name != _function_header.parameters.params_list[j].idents.idents[0].name)
                    {
                        ident_list il = new ident_list();
                        il.idents.Add(new ident(((ident)pv.expressions[j]).name));
                        method_call mc = find_method_call(((ident)pv.expressions[j]).name, k);
                        if (mc == null)
                        {
                            named_type_reference _named_type_reference1 = new named_type_reference();
                            ident idtype1 = new ident("datatype");
                            _named_type_reference1.source_context = idtype1.source_context;
                            _named_type_reference1.names.Add(idtype1);

                            var_def_statement _var_def_statement = new var_def_statement(il, (type_definition)_named_type_reference1, null, definition_attribute.None, false);
                            parsertools.create_source_context(_var_def_statement, il, _named_type_reference1);
                            var_statement _var_statement = new var_statement(_var_def_statement);
                            parsertools.create_source_context(_var_statement, null, _var_def_statement);
                            //((statement_list)_if_node.then_body).subnodes.Insert(0, _var_statement);//obyavlenie peremennoy
                            int ii = ((ArrayList)body_variant_list_main[k]).Count - 1;
                            int jj = 0;
                            bool b = false;
                            expression_list exl = (expression_list)((ArrayList)param_value_list_main[k])[ii];
                            while (ii > i && !b)
                            {
                                jj = 0;
                                while (jj < exl.expressions.Count && (!(exl.expressions[jj] is ident) || ((ident)exl.expressions[jj]).name != ((ident)pv.expressions[j]).name))
                                    jj++;
                                if (jj < exl.expressions.Count)
                                    b = true;
                                ii--;
                                if (ii > i)
                                    exl = (expression_list)((ArrayList)param_value_list_main[k])[ii];
                            }
                            if (!b)
                            {
                                int kk = 0;
                                while (kk < vars.Count && il.idents[0].name != ((var_statement)vars[kk]).var_def.vars.idents[0].name)
                                    kk++;
                                if (kk >= vars.Count)
                                    vars.Add(_var_statement);
                            }
                        }
                        else
                        {
                            bool b = false;
                            int ii = ((ArrayList)body_variant_list_main[k]).Count - 1;
                            int jj = 0;
                            expression_list exl = (expression_list)((ArrayList)param_value_list_main[k])[ii];
                            while (ii > i && !b)
                            {
                                jj = 0;
                                while (jj < exl.expressions.Count && (!(exl.expressions[jj] is ident) || ((ident)exl.expressions[jj]).name != ((ident)pv.expressions[j]).name))
                                    jj++;
                                if (jj < exl.expressions.Count)
                                    b = true;
                                ii--;
                                if (ii > i)
                                    exl = (expression_list)((ArrayList)param_value_list_main[k])[ii];
                            }
                            if (!b)
                            {
                                _function_header.parameters.params_list[j].vars_type = func_type(mc.parameters.expressions.Count);
                                stmt_l.subnodes.Add(var_st(((ident)pv.expressions[j]).name, func_type(mc.parameters.expressions.Count)));
                            }
                        }

                        op_type_node _op_type_node2 = new op_type_node(Operators.Assignment);
                        _op_type_node2.source_context = parsertools.GetTokenSourceContext();
                        assign _assign = new assign(il.idents[0] as addressed_value, _function_header.parameters.params_list[j].idents.idents[0] as expression, _op_type_node2.type);
                        parsertools.create_source_context(_assign, il.idents[0], _function_header.parameters.params_list[j].idents.idents[0]);
                        _ass.subnodes.Add(_assign);
                    }
                }

                ///////////////////////////////////////list_param
                if (((ArrayList)list_params_main[k]).Count != 0 && i < ((ArrayList)list_params_main[k]).Count)
                {
                    for (int ll = 0; ll < ((ArrayList)((ArrayList)list_params_main[k])[i]).Count; ll++)
                    {
                        //if (i == ((ArrayList)body_variant_list_main[k]).Count - 1)
                        for (int l = 0; l < ((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll]).Count; l++)
                        {
                            ident_list il1 = new ident_list();
                            il1.idents.Add(new ident(((ident)((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll])[l]).name));
                            named_type_reference _named_type_reference1 = new named_type_reference();
                            ident idtype1 = new ident("datatype");
                            _named_type_reference1.names.Add(idtype1);

                            var_def_statement _var_def_statement = new var_def_statement(il1, (type_definition)_named_type_reference1, null, definition_attribute.None, false);
                            parsertools.create_source_context(_var_def_statement, il1, _named_type_reference1);
                            var_statement _var_statement = new var_statement(_var_def_statement);
                            //stmt_l.subnodes.Add(_var_statement);
                            int j = 0;
                            while (j < vars.Count && il1.idents[0].name != ((var_statement)vars[j]).var_def.vars.idents[0].name)
                                j++;
                            if (j >= vars.Count)
                                vars.Add(_var_statement);
                        }
                        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
                        dot_node _dot_node = new dot_node(null, (addressed_value)(new ident("head")));
                        ident id = new ident();
                        for (int i1 = 0; i1 < ((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll]).Count; i1++)
                            id.name += ((ident)((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll])[i1]).name;
                        if (id.name != null)
                        {
                            _dot_node.left = (addressed_value)(id);
                            object o = null;
                            method_call _method_call = new method_call(o as expression_list);
                            if (_method_call is dereference)
                                ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                            assign _assign1 = new assign(((ident)((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll])[((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll]).Count - 1]) as addressed_value, _method_call as expression, _op_type_node.type);
                            _ass.subnodes.Add(_assign1);

                            ///
                            for (int i1 = ((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll]).Count - 2; i1 > 0; i1--)
                            {
                                _dot_node = new dot_node((addressed_value)id, (addressed_value)(new ident("tail")));
                                for (int j1 = 0; j1 < ((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll]).Count - 2 - i1; j1++)
                                {
                                    _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("tail")));
                                }
                                _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("head")));

                                _method_call = new method_call(o as expression_list);
                                if (_method_call is dereference)
                                    ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                                _assign1 = new assign(((ident)((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll])[i1]) as addressed_value, _method_call as expression, _op_type_node.type);
                                _ass.subnodes.Add(_assign1);
                            }

                            _dot_node = new dot_node((addressed_value)id, (addressed_value)(new ident("tail")));

                            for (int j1 = 0; j1 < ((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll]).Count - 2; j1++)
                            {
                                _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("tail")));
                            }
                            _method_call = new method_call(o as expression_list);
                            if (_method_call is dereference)
                                ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                            _assign1 = new assign(((ident)((ArrayList)((ArrayList)((ArrayList)list_params_main[k])[i])[ll])[0]) as addressed_value, _method_call as expression, _op_type_node.type);
                            _ass.subnodes.Add(_assign1);
                        }
                    }
                }
                ///////////////////////////////////////////////////////////////////////
                parsertools.create_source_context(_if_node, null, _if_node);
                last_if = new statement_list();
                for (int ii = 0; ii < _ass.subnodes.Count; ii++)
                    ((statement_list)last_if).subnodes.Add((assign)_ass.subnodes[ii]);

                ((statement_list)last_if).subnodes.Add(_if_node);
            }
            stmt_l.subnodes.Add(last_if);
        }
        else
        {
            stmt_l.subnodes.Add((statement)((ArrayList)body_variant_list_main[k])[0]);
        }

        //////////////////

        block _block = new block(null, null);
        _block.defs = new declarations();
        for (int l = 0; l < vars.Count; l++)
            _block.defs.defs.Add(vars[l] as var_statement);

        statement_list sl = null;
        if (stmt_l is statement_list)
            sl = stmt_l as statement_list;
        else
        {
            sl = new statement_list();
            sl.subnodes.Add(stmt_l as statement);
            if (!(stmt_l is empty_statement))
                parsertools.assign_source_context(sl, stmt_l);
        }
        _block.program_code = sl;
        //////////////////
        ArrayList lamdas = find_lambda_funcs_main(_function_header.name.meth_name.name);
        for (int l = 0; l < lamdas.Count; l++)
            _block.defs.defs.Add(lambda((function_lambda_definition)lamdas[l]));
        //////////////////
        int r = 0;
        while (r < let_funcs_funcs.Count && ((string)((ArrayList)let_funcs_funcs[r])[0]) != _function_header.name.meth_name.name)
            r++;
        if (r < let_funcs_funcs.Count)
        {
            if (_block.defs == null)
                _block.defs = new declarations();
            for (int l = 0; l < ((ArrayList)((ArrayList)let_funcs_funcs[r])[1]).Count; l++)
                _block.defs.defs.Add(((ArrayList)((ArrayList)let_funcs_funcs[r])[1])[l] as procedure_definition);
        }
        let_funcs.Clear();
        //////////////////
        procedure_definition _procedure_definition = new procedure_definition(_function_header, null);
        rt = _function_header;
        if (_block != null)
        {
            rt = _block;
            if (_block is proc_block)
                _procedure_definition.proc_body = (proc_block)_block;
        }
        parsertools.create_source_context(_procedure_definition, _function_header, rt);
        funcs.Add(_procedure_definition);
        _functions.Add(_procedure_definition);
    }
    return funcs;}
	case (int)RuleConstants.RULE_VARIANTS :
	//<variants> ::= <variant> <empty>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_VARIANTS2 :
	//<variants> ::= <variants> <variant>
return LRParser.GetReductionSyntaxNode(0);
    case (int)RuleConstants.RULE_VARIANT_TKIDENT:
//<variant> ::= 'tkIdent' <params> <guard_body_list> <where_var>
{
    ArrayList body_list = (ArrayList)LRParser.GetReductionSyntaxNode(2);
    for (int g_ind = 0; g_ind < body_list.Count; g_ind++)
    {
        ///////////////////////////////////body
        statement_list st = null;

        statement_list body_1 = (statement_list)((ArrayList)body_list[g_ind])[1];

        if (LRParser.GetReductionSyntaxNode(3) != null)
        {
            ArrayList ar = (ArrayList)LRParser.GetReductionSyntaxNode(3);
            for (int ii = 0; ii < ar.Count; ii++)
                where_funcs.Add(ar[ii]);

            statement_list _statement_list = body_1;
            //////////////////////////////////////////////for guard
            formal_parameters _formal_parametres = null;
            //////////////////////////
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            /////////////////////////////
            lambda_num++;
            function_lambda_definition _procedure_definition = new function_lambda_definition();
            _procedure_definition.formal_parameters = _formal_parametres;
            _procedure_definition.return_type = (type_definition)_named_type_reference1;
            _procedure_definition.ident_list = null;
            _procedure_definition.proc_body = null;
            _procedure_definition.parameters = null;
            _procedure_definition.lambda_name = "__lam_where__" + lambda_num;
            //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, null, null, null, "lambda_where" + lambda_num);
            _procedure_definition.proc_body = _statement_list;
            procedure_definition pr = lambda(_procedure_definition);
            //_function_lambda_definitions.Add(_procedure_definition);////////////////
            ((block)pr.proc_body).defs = new declarations();
            int start = 0;
            int k = where_funcs.Count - 1;
            while (k > 0 && ((procedure_definition)where_funcs[k]).proc_header.name.meth_name.name.Contains("__lambda__"))
                k--;
            int kk = 0;
            while (k > 0 && kk < ar.Count - 1 && !((procedure_definition)where_funcs[k]).proc_header.name.meth_name.name.Contains("__lambda__"))
            {
                k--;
                kk++;
            }
            start = k;
            int i = start;
            int n = where_funcs.Count;
            if (start >= 0)
                while (i < n)
                {
                    ((block)pr.proc_body).defs.defs.Add((procedure_definition)where_funcs[start]);
                    where_funcs.RemoveAt(start);
                    i++;
                }
            /////////////////////////////////lambda
            if (lambda_stack.Count > 0 && ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count == 0)
                lambda_stack.RemoveAt(lambda_stack.Count - 1);
            if (lambda_stack.Count > 0)
            {
                if (((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count > 0)
                {
                    if (((block)pr.proc_body).defs == null)
                        ((block)pr.proc_body).defs = new declarations();
                    for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
                        ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)lambda_stack[lambda_stack.Count - 1])[ii]);
                    for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
                        _function_lambda_definitions.RemoveAt(_function_lambda_definitions.Count - 1);
                }
                //lambda_stack.RemoveAt(lambda_stack.Count - 1);
            }
            //////////////////////////////////
            where_funcs.Add(pr);
            //if (let_flag.Count > 0)
            //let_func_last.Add(pr);
            expression_list el = new expression_list();
            //where_fact_params.Clear();
            op_type_node _op_type_node = new op_type_node(Operators.Assignment);
            assign _assign = new assign((addressed_value)new ident("result"), new ident(_procedure_definition.lambda_name), Operators.Assignment);

            statement_list _statement_list1 = new statement_list();
            _statement_list1.subnodes.Add(_assign);
            st = _statement_list1;
        }
        else
        {
            //////////////////////////////////////////////for guard
            st = body_1;
        }
        ///////////////////////////////////\body


        ////////////////////////////////////////////////////for let & where
        let_where_funcs.Clear();
        while (let_where_funcs_main.Count > 1)
            let_where_funcs_main.RemoveAt(let_where_funcs_main.Count - 1);
        list_params1.Clear();
        let_flag.Clear();
        int iiii = 0;
        while (iiii < func_name.Count && ((ident)func_name[iiii]).name != ((ident)LRParser.GetReductionSyntaxNode(0)).name)
            iiii++;
        if (iiii == func_name.Count && let_funcs_funcs.Count == 0 || (let_funcs_funcs.Count > 0 && ((string)((ArrayList)let_funcs_funcs[let_funcs_funcs.Count - 1])[0]) != ((ident)LRParser.GetReductionSyntaxNode(0)).name))
        {
            ArrayList ar = new ArrayList();
            ar.Add(((ident)LRParser.GetReductionSyntaxNode(0)).name);
            if (where_funcs.Count > 0)
            {
                for (int i = 0; i < let_funcs.Count; i++)
                    ((block)((procedure_definition)where_funcs[0]).proc_body).defs.defs.Add((procedure_definition)let_funcs[i]);
                ar.Add(where_funcs.Clone());
            }
            else
                ar.Add(let_funcs.Clone());
            let_funcs_funcs.Add(ar);
            let_funcs.Clear();
            where_funcs.Clear();
            let_func_last.Clear();
        }
        else
        {
            int r = 0;
            while (r < let_funcs_funcs.Count && ((string)((ArrayList)let_funcs_funcs[r])[0]) !=
                ((ident)LRParser.GetReductionSyntaxNode(0)).name)
                r++;
            if (r < let_funcs_funcs.Count)
            {
                if (where_funcs.Count > 0)
                {
                    for (int i = 0; i < let_funcs.Count; i++)
                        ((block)((procedure_definition)where_funcs[0]).proc_body).defs.defs.Add((procedure_definition)let_funcs[i]);
                    for (int i = 0; i < where_funcs.Count; i++)
                        ((ArrayList)((ArrayList)let_funcs_funcs[r])[1]).Add(where_funcs[i]);
                }
                else
                    for (int i = 0; i < let_funcs.Count; i++)
                        ((ArrayList)((ArrayList)let_funcs_funcs[r])[1]).Add(let_funcs[i]);
                let_funcs.Clear();
                where_funcs.Clear();
                let_func_last.Clear();
            }
        }

        if (iiii == func_name.Count)
        {
            /////////////////////////////////////////////////////
            ArrayList ar_lambda = new ArrayList();
            ar_lambda.Add(((ident)LRParser.GetReductionSyntaxNode(0)).name);
            ar_lambda.Add(_function_lambda_definitions.Clone());
            _function_lambda_definitions_main.Add(ar_lambda.Clone());
            _function_lambda_definitions.Clear();
            /////////////////////////////////////////////////////
        }
        else
        {
            //////////////////////////////////
            ArrayList ar_lambda = (ArrayList)_function_lambda_definitions.Clone();
            for (int i = 0; i < ar_lambda.Count; i++)
                ((ArrayList)((ArrayList)_function_lambda_definitions_main[_function_lambda_definitions_main.Count - 1])[1]).Add(ar_lambda[i]);
            _function_lambda_definitions.Clear();
            //////////////////////////////////
        }
        ////////////////////////////////////////////////////

        if (st/* LRParser.GetReductionSyntaxNode(2)*/ != null)
        {
            int i = 0;
            while (i < func_name.Count && ((ident)func_name[i]).name != ((ident)LRParser.GetReductionSyntaxNode(0)).name)
                i++;
            if (i == func_name.Count)
            {
                func_name.Add((ident)LRParser.GetReductionSyntaxNode(0));
                list_return_funcs_main.Add(list_return_funcs.Clone());
                list_return_funcs.Clear();
                if (list_method_calls_main.Count > 0)
                    for (int iii = 0; iii < ((ArrayList)list_method_calls_main[list_method_calls_main.Count - 1]).Count; iii++)
                        if (list_method_calls.Count > 0)
                            list_method_calls.RemoveAt(0);
                list_method_calls_main.Add(list_method_calls.Clone());
                if (param_value_list.Count != 0)
                {
                    param_value_list_main.Add(param_value_list.Clone());
                    body_variant_list_main.Add(body_variant_list.Clone());
                    guard_list_main.Add(guard_list.Clone());
                    list_params_main.Add(list_params.Clone());
                }
                param_value_list.Clear();
                body_variant_list.Clear();
                guard_list.Clear();
                list_params.Clear();
                param_value_list.Add(LRParser.GetReductionSyntaxNode(1));
                ////////////////Dobavlyaem formalnye parametry
                //statement_list st = (statement_list)LRParser.GetReductionSyntaxNode(4);
                if (st.subnodes[0] is assign)
                {
                    if (((assign)st.subnodes[0]).from is function_lambda_call)
                    {
                        function_lambda_call flc = (function_lambda_call)(((assign)st.subnodes[0]).from);
                        function_lambda_definition fld = ((function_lambda_call)(((assign)st.subnodes[0]).from)).f_lambda_def;
                        for (int ind = flc.parameters.expressions.Count; ind < fld.parameters.expressions.Count; ind++)
                        {
                            if (param_value_list.Count == 0)
                                param_value_list.Add(new expression_list());
                            if (param_value_list[param_value_list.Count - 1] == null)
                                param_value_list[param_value_list.Count - 1] = new expression_list();
                            ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Add(fld.parameters.expressions[ind]);
                        }
                    }
                    if (((assign)st.subnodes[0]).from is method_call)
                    {
                        method_call mc = (method_call)(((assign)st.subnodes[0]).from);
                        int jjj = 0;
                        int ind_null = -1;
                        while (jjj < mc.parameters.expressions.Count)
                            if (mc.parameters.expressions[jjj] is new_expr && ((new_expr)mc.parameters.expressions[jjj]).params_list.expressions[0] is string_const &&
                                ((string_const)((new_expr)mc.parameters.expressions[jjj]).params_list.expressions[0]).Value == "$null")
                            {
                                ind_null = jjj;
                                jjj = mc.parameters.expressions.Count;
                            }
                            else
                                jjj++;
                        if (ind_null >= 0)
                            for (int ind = ind_null; ind < mc.parameters.expressions.Count; ind++)
                            {
                                //int j = 0;
                                //while ()
                                if (param_value_list.Count == 0)
                                    param_value_list.Add(new expression_list());
                                if (param_value_list[param_value_list.Count - 1] == null)
                                    param_value_list[param_value_list.Count - 1] = new expression_list();
                                ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Add(new ident("$param" + ind));
                                ((method_call)(((assign)st.subnodes[0]).from)).parameters.expressions.Insert(ind, new ident("$param" + ind));
                                ((method_call)(((assign)st.subnodes[0]).from)).parameters.expressions.RemoveAt(ind + 1);
                            }
                    }
                }
                ////////////////
                body_variant_list.Add(st);
                //guard_list.Add(LRParser.GetReductionSyntaxNode(2));
                guard_list.Add(((ArrayList)body_list[g_ind])[0]);
                if (list_params_temp.Count != 0)
                {
                    list_params.Add(list_params_temp.Clone());
                    list_params_temp.Clear();
                }
            }
            else
            {
                ArrayList ar = (ArrayList)list_method_calls.Clone();
                for (int iii = 0; iii < list_method_calls.Count; iii++)
                    ((ArrayList)list_method_calls_main[list_method_calls_main.Count - 1]).Add(ar[iii]);
                param_value_list.Add(LRParser.GetReductionSyntaxNode(1));
                ////////////////Dobavlyaem formalnye parametry
                //statement_list st = (statement_list)LRParser.GetReductionSyntaxNode(4);
                if (st.subnodes[0] is assign)
                {
                    if (((assign)st.subnodes[0]).from is function_lambda_call)
                    {
                        function_lambda_call flc = (function_lambda_call)(((assign)st.subnodes[0]).from);
                        function_lambda_definition fld = ((function_lambda_call)(((assign)st.subnodes[0]).from)).f_lambda_def;
                        for (int ind = flc.parameters.expressions.Count; ind < fld.parameters.expressions.Count; ind++)
                        {
                            if (param_value_list.Count == 0)
                                param_value_list.Add(new expression_list());
                            if (param_value_list[param_value_list.Count - 1] == null)
                                param_value_list[param_value_list.Count - 1] = new expression_list();
                            ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Add(fld.parameters.expressions[ind]);
                        }
                    }
                    if (((assign)st.subnodes[0]).from is method_call)
                    {
                        method_call mc = (method_call)(((assign)st.subnodes[0]).from);
                        int jjj = 0;
                        int ind_null = -1;
                        while (jjj < mc.parameters.expressions.Count)
                            if (mc.parameters.expressions[jjj] is new_expr && ((new_expr)mc.parameters.expressions[jjj]).params_list.expressions[0] is string_const &&
                                ((string_const)((new_expr)mc.parameters.expressions[jjj]).params_list.expressions[0]).Value == "$null")
                            {
                                ind_null = jjj;
                                jjj = mc.parameters.expressions.Count;
                            }
                            else
                                jjj++;
                        if (ind_null >= 0)
                            for (int ind = ind_null; ind < mc.parameters.expressions.Count; ind++)
                            {
                                if (param_value_list.Count == 0)
                                    param_value_list.Add(new expression_list());
                                if (param_value_list[param_value_list.Count - 1] == null)
                                    param_value_list[param_value_list.Count - 1] = new expression_list();
                                ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Add(new ident("$param" + ind));
                                ((method_call)(((assign)st.subnodes[0]).from)).parameters.expressions.Insert(ind, new ident("$param" + ind));
                                ((method_call)(((assign)st.subnodes[0]).from)).parameters.expressions.RemoveAt(ind + 1);
                            }
                    }
                }
                ////////////////
                body_variant_list.Add(st);
                //guard_list.Add(LRParser.GetReductionSyntaxNode(2));
                guard_list.Add(((ArrayList)body_list[g_ind])[0]);
                if (list_params_temp.Count != 0)
                {
                    list_params.Add(list_params_temp.Clone());
                    list_params_temp.Clear();
                }
            }
        }
        else
        {
            int i = 0;
            while (i < func_name.Count && ((ident)func_name[i]).name != ((ident)LRParser.GetReductionSyntaxNode(0)).name)
                i++;
            if (i == func_name.Count)
            {
                func_name.Add((ident)LRParser.GetReductionSyntaxNode(0));
            }
        }
        list_params1.Clear();
        //int kk = last_list_method_calls.Count;
        //kk = last_function_lambda_definitions.Count;
        for (int i = 0; i < last_function_lambda_definitions.Count; i++)
        {
            for (int j = 0; j < ((function_lambda_definition)last_function_lambda_definitions[i]).formal_parameters.params_list.Count; j++)
            {
                string name_param = ((function_lambda_definition)last_function_lambda_definitions[i]).formal_parameters.params_list[j].idents.idents[0].name;
                int k = 0;
                while (k < last_list_method_calls.Count && ((ident)((method_call)last_list_method_calls[k]).dereferencing_value).name != name_param)
                    k++;
                if (k < last_list_method_calls.Count)
                {
                    function_lambda_definition fld = find_func_lambda_after(((function_lambda_definition)last_function_lambda_definitions[i]).lambda_name);
                    fld.formal_parameters.params_list[j].vars_type = func_type(((method_call)last_list_method_calls[k]).parameters.expressions.Count);
                }
            }
        }
        last_list_method_calls.Clear();
        last_function_lambda_definitions.Clear();
    }
    return null;
}
    case (int)RuleConstants.RULE_VARIANT_TKQUOTE_TKIDENT_TKQUOTE:
//<variant> ::= <list_param1> 'tkQuote' 'tkIdent' 'tkQuote' <list_param1> <guard_body_list> <where_var>
{
    ArrayList body_list = (ArrayList)LRParser.GetReductionSyntaxNode(5);
    for (int g_ind = 0; g_ind < body_list.Count; g_ind++)
    {
        ///////////////////////////////////body
        statement_list st = null;

        statement_list body_1 = (statement_list)((ArrayList)body_list[g_ind])[1];

        if (LRParser.GetReductionSyntaxNode(6) != null)
        {
            ArrayList ar = (ArrayList)LRParser.GetReductionSyntaxNode(6);
            for (int ii = 0; ii < ar.Count; ii++)
                where_funcs.Add(ar[ii]);

            statement_list _statement_list = body_1;
            //////////////////////////////////////////////for guard
            formal_parameters _formal_parametres = null;
            //////////////////////////
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            /////////////////////////////
            lambda_num++;
            function_lambda_definition _procedure_definition = new function_lambda_definition();
            _procedure_definition.formal_parameters = _formal_parametres;
            _procedure_definition.return_type = (type_definition)_named_type_reference1;
            _procedure_definition.ident_list = null;
            _procedure_definition.proc_body = null;
            _procedure_definition.parameters = null;
            _procedure_definition.lambda_name = "__lam_where__" + lambda_num;
            //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, null, null, null, "lambda_where" + lambda_num);
            _procedure_definition.proc_body = _statement_list;
            procedure_definition pr = lambda(_procedure_definition);
            //_function_lambda_definitions.Add(_procedure_definition);////////////////
            ((block)pr.proc_body).defs = new declarations();
            int start = 0;
            int k = where_funcs.Count - 1;
            while (k > 0 && ((procedure_definition)where_funcs[k]).proc_header.name.meth_name.name.Contains("__lambda__"))
                k--;
            int kk = 0;
            while (k > 0 && kk < ar.Count - 1 && !((procedure_definition)where_funcs[k]).proc_header.name.meth_name.name.Contains("__lambda__"))
            {
                k--;
                kk++;
            }
            start = k;
            int i = start;
            int n = where_funcs.Count;
            if (start >= 0)
                while (i < n)
                {
                    ((block)pr.proc_body).defs.defs.Add((procedure_definition)where_funcs[start]);
                    where_funcs.RemoveAt(start);
                    i++;
                }
            /////////////////////////////////lambda
            if (lambda_stack.Count > 0 && ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count == 0)
                lambda_stack.RemoveAt(lambda_stack.Count - 1);
            if (lambda_stack.Count > 0)
            {
                if (((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count > 0)
                {
                    if (((block)pr.proc_body).defs == null)
                        ((block)pr.proc_body).defs = new declarations();
                    for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
                        ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)lambda_stack[lambda_stack.Count - 1])[ii]);
                    for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
                        _function_lambda_definitions.RemoveAt(_function_lambda_definitions.Count - 1);
                }
                //lambda_stack.RemoveAt(lambda_stack.Count - 1);
            }
            //////////////////////////////////
            where_funcs.Add(pr);
            //if (let_flag.Count > 0)
            //let_func_last.Add(pr);
            expression_list el = new expression_list();
            //where_fact_params.Clear();
            op_type_node _op_type_node = new op_type_node(Operators.Assignment);
            assign _assign = new assign((addressed_value)new ident("result"), new ident(_procedure_definition.lambda_name), Operators.Assignment);

            statement_list _statement_list1 = new statement_list();
            _statement_list1.subnodes.Add(_assign);
            st = _statement_list1;
        }
        else
        {
            //////////////////////////////////////////////for guard
            st = body_1;
        }
        ///////////////////////////////////\body

        ident _ident = (ident)LRParser.GetReductionSyntaxNode(2);
        expression_list _ex_l1 = (expression_list)LRParser.GetReductionSyntaxNode(0);
        expression_list _ex_l2 = (expression_list)LRParser.GetReductionSyntaxNode(4);
        for (int i = 0; i < _ex_l2.expressions.Count; i++)
            _ex_l1.expressions.Add(_ex_l2.expressions[i]);

        ////////////////////////////////////////////////////for let & where
        let_where_funcs.Clear();
        while (let_where_funcs_main.Count > 1)
            let_where_funcs_main.RemoveAt(let_where_funcs_main.Count - 1);
        list_params1.Clear();
        let_flag.Clear();
        int iiii = 0;
        while (iiii < func_name.Count && ((ident)func_name[iiii]).name != _ident.name)
            iiii++;
        if (iiii == func_name.Count && let_funcs_funcs.Count == 0 || (let_funcs_funcs.Count > 0 && ((string)((ArrayList)let_funcs_funcs[let_funcs_funcs.Count - 1])[0]) != _ident.name))
        {
            ArrayList ar = new ArrayList();
            ar.Add(_ident.name);
            if (where_funcs.Count > 0)
            {
                for (int i = 0; i < let_funcs.Count; i++)
                    ((block)((procedure_definition)where_funcs[0]).proc_body).defs.defs.Add((procedure_definition)let_funcs[i]);
                ar.Add(where_funcs.Clone());
            }
            else
                ar.Add(let_funcs.Clone());
            let_funcs_funcs.Add(ar);
            let_funcs.Clear();
            where_funcs.Clear();
            let_func_last.Clear();
        }
        else
        {
            int r = 0;
            while (r < let_funcs_funcs.Count && ((string)((ArrayList)let_funcs_funcs[r])[0]) !=
                _ident.name)
                r++;
            if (r < let_funcs_funcs.Count)
            {
                if (where_funcs.Count > 0)
                {
                    for (int i = 0; i < let_funcs.Count; i++)
                        ((block)((procedure_definition)where_funcs[0]).proc_body).defs.defs.Add((procedure_definition)let_funcs[i]);
                    for (int i = 0; i < where_funcs.Count; i++)
                        ((ArrayList)((ArrayList)let_funcs_funcs[r])[1]).Add(where_funcs[i]);
                }
                else
                    for (int i = 0; i < let_funcs.Count; i++)
                        ((ArrayList)((ArrayList)let_funcs_funcs[r])[1]).Add(let_funcs[i]);
                let_funcs.Clear();
                where_funcs.Clear();
                let_func_last.Clear();
            }
        }

        if (iiii == func_name.Count)
        {
            /////////////////////////////////////////////////////
            ArrayList ar_lambda = new ArrayList();
            ar_lambda.Add(_ident.name);
            ar_lambda.Add(_function_lambda_definitions.Clone());
            _function_lambda_definitions_main.Add(ar_lambda.Clone());
            _function_lambda_definitions.Clear();
            /////////////////////////////////////////////////////
        }
        else
        {
            //////////////////////////////////
            ArrayList ar_lambda = (ArrayList)_function_lambda_definitions.Clone();
            for (int i = 0; i < ar_lambda.Count; i++)
                ((ArrayList)((ArrayList)_function_lambda_definitions_main[_function_lambda_definitions_main.Count - 1])[1]).Add(ar_lambda[i]);
            _function_lambda_definitions.Clear();
            //////////////////////////////////
        }
        ////////////////////////////////////////////////////

        if (st/*LRParser.GetReductionSyntaxNode(7)*/ != null)
        {
            int i = 0;
            while (i < func_name.Count && ((ident)func_name[i]).name != _ident.name)
                i++;
            if (i == func_name.Count)
            {
                func_name.Add(_ident);
                list_return_funcs_main.Add(list_return_funcs.Clone());
                list_return_funcs.Clear();
                if (list_method_calls_main.Count > 0)
                    for (int iii = 0; iii < ((ArrayList)list_method_calls_main[list_method_calls_main.Count - 1]).Count; iii++)
                        if (list_method_calls.Count > 0)
                            list_method_calls.RemoveAt(0);
                list_method_calls_main.Add(list_method_calls.Clone());
                if (param_value_list.Count != 0)
                {
                    param_value_list_main.Add(param_value_list.Clone());
                    body_variant_list_main.Add(body_variant_list.Clone());
                    guard_list_main.Add(guard_list.Clone());
                    list_params_main.Add(list_params.Clone());
                }
                param_value_list.Clear();
                body_variant_list.Clear();
                guard_list.Clear();
                list_params.Clear();
                param_value_list.Add(_ex_l1);
                ////////////////Dobavlyaem formalnye parametry
                //statement_list st = (statement_list)LRParser.GetReductionSyntaxNode(7);
                if (st.subnodes[0] is assign)
                {
                    if (((assign)st.subnodes[0]).from is function_lambda_call)
                    {
                        function_lambda_call flc = (function_lambda_call)(((assign)st.subnodes[0]).from);
                        function_lambda_definition fld = ((function_lambda_call)(((assign)st.subnodes[0]).from)).f_lambda_def;
                        for (int ind = flc.parameters.expressions.Count; ind < fld.parameters.expressions.Count; ind++)
                        {
                            if (param_value_list.Count == 0)
                                param_value_list.Add(new expression_list());
                            if (param_value_list[param_value_list.Count - 1] == null)
                                param_value_list[param_value_list.Count - 1] = new expression_list();
                            ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Add(fld.parameters.expressions[ind]);
                        }
                    }
                    if (((assign)st.subnodes[0]).from is method_call)
                    {
                        method_call mc = (method_call)(((assign)st.subnodes[0]).from);
                        int jjj = 0;
                        int ind_null = -1;
                        while (jjj < mc.parameters.expressions.Count)
                            if (mc.parameters.expressions[jjj] is new_expr && ((new_expr)mc.parameters.expressions[jjj]).params_list.expressions[0] is string_const &&
                                ((string_const)((new_expr)mc.parameters.expressions[jjj]).params_list.expressions[0]).Value == "$null")
                            {
                                ind_null = jjj;
                                jjj = mc.parameters.expressions.Count;
                            }
                            else
                                jjj++;
                        if (ind_null >= 0)
                            for (int ind = ind_null; ind < mc.parameters.expressions.Count; ind++)
                            {
                                //int j = 0;
                                //while ()
                                if (param_value_list.Count == 0)
                                    param_value_list.Add(new expression_list());
                                if (param_value_list[param_value_list.Count - 1] == null)
                                    param_value_list[param_value_list.Count - 1] = new expression_list();
                                ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Add(new ident("$param" + ind));
                                ((method_call)(((assign)st.subnodes[0]).from)).parameters.expressions.Insert(ind, new ident("$param" + ind));
                                ((method_call)(((assign)st.subnodes[0]).from)).parameters.expressions.RemoveAt(ind + 1);
                            }
                    }
                }
                ////////////////
                body_variant_list.Add(st);
                //guard_list.Add(LRParser.GetReductionSyntaxNode(5));
                guard_list.Add(((ArrayList)body_list[g_ind])[0]);
                if (list_params_temp.Count != 0)
                {
                    list_params.Add(list_params_temp.Clone());
                    list_params_temp.Clear();
                }
            }
            else
            {
                ArrayList ar = (ArrayList)list_method_calls.Clone();
                for (int iii = 0; iii < list_method_calls.Count; iii++)
                    ((ArrayList)list_method_calls_main[list_method_calls_main.Count - 1]).Add(ar[iii]);
                param_value_list.Add(_ex_l1);
                ////////////////Dobavlyaem formalnye parametry
                //statement_list st = (statement_list)LRParser.GetReductionSyntaxNode(7);
                if (st.subnodes[0] is assign)
                {
                    if (((assign)st.subnodes[0]).from is function_lambda_call)
                    {
                        function_lambda_call flc = (function_lambda_call)(((assign)st.subnodes[0]).from);
                        function_lambda_definition fld = ((function_lambda_call)(((assign)st.subnodes[0]).from)).f_lambda_def;
                        for (int ind = flc.parameters.expressions.Count; ind < fld.parameters.expressions.Count; ind++)
                        {
                            if (param_value_list.Count == 0)
                                param_value_list.Add(new expression_list());
                            if (param_value_list[param_value_list.Count - 1] == null)
                                param_value_list[param_value_list.Count - 1] = new expression_list();
                            ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Add(fld.parameters.expressions[ind]);
                        }
                    }
                    if (((assign)st.subnodes[0]).from is method_call)
                    {
                        method_call mc = (method_call)(((assign)st.subnodes[0]).from);
                        int jjj = 0;
                        int ind_null = -1;
                        while (jjj < mc.parameters.expressions.Count)
                            if (mc.parameters.expressions[jjj] is new_expr && ((new_expr)mc.parameters.expressions[jjj]).params_list.expressions[0] is string_const &&
                                ((string_const)((new_expr)mc.parameters.expressions[jjj]).params_list.expressions[0]).Value == "$null")
                            {
                                ind_null = jjj;
                                jjj = mc.parameters.expressions.Count;
                            }
                            else
                                jjj++;
                        if (ind_null >= 0)
                            for (int ind = ind_null; ind < mc.parameters.expressions.Count; ind++)
                            {
                                if (param_value_list.Count == 0)
                                    param_value_list.Add(new expression_list());
                                if (param_value_list[param_value_list.Count - 1] == null)
                                    param_value_list[param_value_list.Count - 1] = new expression_list();
                                ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Add(new ident("$param" + ind));
                                ((method_call)(((assign)st.subnodes[0]).from)).parameters.expressions.Insert(ind, new ident("$param" + ind));
                                ((method_call)(((assign)st.subnodes[0]).from)).parameters.expressions.RemoveAt(ind + 1);
                            }
                    }
                }
                ////////////////
                body_variant_list.Add(st);
                //guard_list.Add(LRParser.GetReductionSyntaxNode(5));
                guard_list.Add(((ArrayList)body_list[g_ind])[0]);
                if (list_params_temp.Count != 0)
                {
                    list_params.Add(list_params_temp.Clone());
                    list_params_temp.Clear();
                }
            }
        }
        else
        {
            int i = 0;
            while (i < func_name.Count && ((ident)func_name[i]).name != _ident.name)
                i++;
            if (i == func_name.Count)
            {
                func_name.Add(_ident);
            }
        }
        list_params1.Clear();
        //int kk = last_list_method_calls.Count;
        //kk = last_function_lambda_definitions.Count;
        for (int i = 0; i < last_function_lambda_definitions.Count; i++)
        {
            for (int j = 0; j < ((function_lambda_definition)last_function_lambda_definitions[i]).formal_parameters.params_list.Count; j++)
            {
                string name_param = ((function_lambda_definition)last_function_lambda_definitions[i]).formal_parameters.params_list[j].idents.idents[0].name;
                int k = 0;
                while (k < last_list_method_calls.Count && ((ident)((method_call)last_list_method_calls[k]).dereferencing_value).name != name_param)
                    k++;
                if (k < last_list_method_calls.Count)
                {
                    function_lambda_definition fld = find_func_lambda_after(((function_lambda_definition)last_function_lambda_definitions[i]).lambda_name);
                    fld.formal_parameters.params_list[j].vars_type = func_type(((method_call)last_list_method_calls[k]).parameters.expressions.Count);
                }
            }
        }
        last_list_method_calls.Clear();
        last_function_lambda_definitions.Clear();
    }
    return null;
}
    case (int)RuleConstants.RULE_LIST_PARAM1:
//<list_param1> ::= <list_param> <empty>
{
    bool b = false;
    if (list_param.Count == 1)
    {
        list_params_temp.Add(new ArrayList());
        let_where_list_params.Add(new ArrayList());//
        if (list_param[0] is new_expr && ((string_const)((new_expr)list_param[0]).params_list.expressions[1]).Value == "empty")
            b = true;
        list_param.Clear();
    }
    else
    {
        list_params_temp.Add(list_param.Clone());
        let_where_list_params.Add(list_param.Clone());//
    }
    expression_list _expression_list = new expression_list();
    if (list_param.Count == 0)
    {
        if (b)
        {
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            el.expressions.Add(new int32_const(0));
            literal lt;
            string text = "empty_list";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            _expression_list.expressions.Add(newexpr);
        }
        else
        {
            _expression_list.source_context = ((expression)LRParser.GetReductionSyntaxNode(0)).source_context;
            _expression_list.expressions.Add((expression)LRParser.GetReductionSyntaxNode(0));
        }
    }
    else
    {
        ident id = new ident();
        for (int i = 0; i < list_param.Count; i++)
        {
            if (list_param[i] is ident)
                id.name += ((ident)list_param[i]).name;
            else
            {
                errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "идентификатор"));
                return null;
            }
        }
        _expression_list.source_context = ((expression)id).source_context;
        _expression_list.expressions.Add((expression)id);
        list_param.Clear();
    }
    list_params1.Clear();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
        list_params1.Add(_expression_list.expressions[i]);
    last_list_method_calls_lambda.Clear();
    return _expression_list;
}
    case (int)RuleConstants.RULE_BODY_WHERE:
    //<body_where> ::= <body_func> <where_var>
{
    //guard_list.Add(LRParser.GetReductionSyntaxNode(0));
    if (LRParser.GetReductionSyntaxNode(1) != null)
    {
        ArrayList ar = (ArrayList)LRParser.GetReductionSyntaxNode(1);
        for (int ii = 0; ii < ar.Count; ii++)
            where_funcs.Add(ar[ii]);

        statement_list _statement_list = (statement_list)LRParser.GetReductionSyntaxNode(0);
        //////////////////////////////////////////////for guard
        formal_parameters _formal_parametres = null;
        //////////////////////////
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.source_context = idtype1.source_context;
        _named_type_reference1.names.Add(idtype1);
        /////////////////////////////
        lambda_num++;
        function_lambda_definition _procedure_definition = new function_lambda_definition();
        _procedure_definition.formal_parameters = _formal_parametres;
        _procedure_definition.return_type = (type_definition)_named_type_reference1;
        _procedure_definition.ident_list = null;
        _procedure_definition.proc_body = null;
        _procedure_definition.parameters = null;
        _procedure_definition.lambda_name = "__lam_where__" + lambda_num;
        //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, null, null, null, "lambda_where" + lambda_num);
        _procedure_definition.proc_body = _statement_list;
        procedure_definition pr = lambda(_procedure_definition);
        //_function_lambda_definitions.Add(_procedure_definition);////////////////
        ((block)pr.proc_body).defs = new declarations();
        int start = 0;
        int k = where_funcs.Count - 1;
        while (k > 0 && ((procedure_definition)where_funcs[k]).proc_header.name.meth_name.name.Contains("__lambda__"))
            k--;
        int kk = 0;
        while (k > 0 && kk < ar.Count - 1 && !((procedure_definition)where_funcs[k]).proc_header.name.meth_name.name.Contains("__lambda__"))
        {
            k--;
            kk++;
        }
        start = k;
        int i = start;
        int n = where_funcs.Count;
        if (start >= 0)
            while (i < n)
            {
                ((block)pr.proc_body).defs.defs.Add((procedure_definition)where_funcs[start]);
                where_funcs.RemoveAt(start);
                i++;
            }
        /////////////////////////////////lambda
        if (lambda_stack.Count > 0 && ((ArrayList)lambda_stack[lambda_stack.Count-1]).Count==0)
            lambda_stack.RemoveAt(lambda_stack.Count - 1);
        if (lambda_stack.Count > 0)
        {
            if (((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count > 0)
            {
                if (((block)pr.proc_body).defs == null)
                    ((block)pr.proc_body).defs = new declarations();
                for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
                    ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)lambda_stack[lambda_stack.Count - 1])[ii]);
                for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
                    _function_lambda_definitions.RemoveAt(_function_lambda_definitions.Count - 1);
            }
            //lambda_stack.RemoveAt(lambda_stack.Count - 1);
        }
        //////////////////////////////////
        where_funcs.Add(pr);
        //if (let_flag.Count > 0)
        //let_func_last.Add(pr);
        expression_list el = new expression_list();
        //where_fact_params.Clear();
        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
        assign _assign = new assign((addressed_value)new ident("result"), new ident(_procedure_definition.lambda_name), Operators.Assignment);

        statement_list _statement_list1 = new statement_list();
        _statement_list1.subnodes.Add(_assign);
        return _statement_list1;
    }
    else
    {
        //////////////////////////////////////////////for guard
        statement_list _statement_list = (statement_list)LRParser.GetReductionSyntaxNode(0);
        return _statement_list;
    }
}
	case (int)RuleConstants.RULE_WHERE_VAR :
	//<where_var> ::= 
	//NONTERMINAL:<where_var> ::= 
	return null;
	//ENDNONTERMINAL
    case (int)RuleConstants.RULE_WHERE_VAR_TKWHERE:
    //<where_var> ::= 'tkWhere' <inits>
    {
        token_where_count--;
        //let_where_funcs_main.RemoveAt(let_where_funcs_main.Count-1);
        let_where_funcs.Clear();
        return LRParser.GetReductionSyntaxNode(1);
    }
    case (int)RuleConstants.RULE_INITS:
//<inits> ::= <init> <empty>
{
    ArrayList ar = new ArrayList();
    ar.Add(LRParser.GetReductionSyntaxNode(0));
    return ar;
}
    case (int)RuleConstants.RULE_INITS_TKSEMICOLON:
//<inits> ::= <inits> 'tkSemiColon' <init>
{
    ArrayList ar = (ArrayList)LRParser.GetReductionSyntaxNode(0);
    ar.Add(LRParser.GetReductionSyntaxNode(2));
    return ar;
}
    case (int)RuleConstants.RULE_INIT_TKIDENT:
//<init> ::= 'tkIdent' <params_where> <guard_body_list> <where_var>
{
    expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(1);
    /*statement_list _statement_list = (statement_list)LRParser.GetReductionSyntaxNode(4);*/
    statement_list _statement_list = new statement_list();
    ArrayList ar_main = (ArrayList)LRParser.GetReductionSyntaxNode(2);
    ////////////////////////////for list
    statement_list stmt_l = new statement_list();
    int start = let_where_list_params.Count;
    if (_expression_list !=null)
        start = let_where_list_params.Count - _expression_list.expressions.Count;
    int i_ex = 0;
    for (int ll = start; ll < let_where_list_params.Count; ll++)
    {
        for (int l = 0; l < ((ArrayList)let_where_list_params[ll]).Count; l++)
        {
            ident_list il1 = new ident_list();
            il1.idents.Add(new ident(((ident)((ArrayList)let_where_list_params[ll])[l]).name));
            named_type_reference _n_t_r = new named_type_reference();
            ident it = new ident("datatype");
            _n_t_r.names.Add(it);

            var_def_statement _var_def_statement = new var_def_statement(il1, (type_definition)_n_t_r, null, definition_attribute.None, false);
            var_statement _var_statement = new var_statement(_var_def_statement);
            stmt_l.subnodes.Add(_var_statement);
        }
        if (((ArrayList)let_where_list_params[ll]).Count > 0)
        {
            op_type_node _op_type_node = new op_type_node(Operators.Assignment);
            dot_node _dot_node = new dot_node(null, (addressed_value)(new ident("head")));
            ident id = _expression_list.expressions[i_ex] as ident;
            /*for (int i1 = 0; i1 < ((ArrayList)let_where_list_params[ll]).Count; i1++)
                id.name += ((ident)((ArrayList)let_where_list_params[ll])[i1]).name;*/
            if (id.name != null)
            {
                _dot_node.left = (addressed_value)(id);
                object o = null;
                method_call _method_call = new method_call(o as expression_list);
                if (_method_call is dereference)
                    ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                assign _assign1 = new assign(((ident)((ArrayList)let_where_list_params[ll])[((ArrayList)let_where_list_params[ll]).Count - 1]) as addressed_value, _method_call as expression, _op_type_node.type);
                stmt_l.subnodes.Add(_assign1);

                ///
                for (int i1 = ((ArrayList)let_where_list_params[ll]).Count - 2; i1 > 0; i1--)
                {
                    _dot_node = new dot_node((addressed_value)id, (addressed_value)(new ident("tail")));
                    for (int j1 = 0; j1 < ((ArrayList)let_where_list_params[ll]).Count - 2 - i1; j1++)
                    {
                        _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("tail")));
                    }
                    _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("head")));

                    _method_call = new method_call(o as expression_list);
                    if (_method_call is dereference)
                        ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                    _assign1 = new assign(((ident)((ArrayList)let_where_list_params[ll])[i1]) as addressed_value, _method_call as expression, _op_type_node.type);
                    stmt_l.subnodes.Add(_assign1);
                }

                _dot_node = new dot_node((addressed_value)id, (addressed_value)(new ident("tail")));

                for (int j1 = 0; j1 < ((ArrayList)let_where_list_params[ll]).Count - 2; j1++)
                {
                    _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("tail")));
                }
                _method_call = new method_call(o as expression_list);
                if (_method_call is dereference)
                    ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                _assign1 = new assign(((ident)((ArrayList)let_where_list_params[ll])[0]) as addressed_value, _method_call as expression, _op_type_node.type);
                stmt_l.subnodes.Add(_assign1);
            }
        }
        i_ex++;
    }
    for (int ll = 0; ll < let_where_list_params.Count - start; ll++)
        list_params_temp.RemoveAt(list_params_temp.Count - 1);
    for (int i = stmt_l.subnodes.Count - 1; i >= 0; i--)
        _statement_list.subnodes.Insert(0, stmt_l.subnodes[i]);
    if (_expression_list != null)
        for (int i = 0; i < _expression_list.expressions.Count; i++)
            let_where_list_params.RemoveAt(let_where_list_params.Count - 1);
    ////////////////////////////
    formal_parameters _formal_parametres = null;
    ident_list i_l = new ident_list();
    if (_expression_list != null)
    {
        for (int i = 0; i < _expression_list.expressions.Count; i++)
            i_l.idents.Add((ident)_expression_list.expressions[i]);
        /////////////////////////////
        _formal_parametres = new formal_parameters();
        for (int i = 0; i < i_l.idents.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_expression_list.expressions[i];
            _ident_list.idents.Add(id);
            string name_param = id.name;
            typed_parameters _typed_parametres = null;
            int k = 0;
            while (k < last_list_method_calls_lambda.Count && ((ident)((method_call)last_list_method_calls_lambda[k]).dereferencing_value).name != name_param)
                k++;
            if (k < last_list_method_calls_lambda.Count)
                _typed_parametres = new typed_parameters(_ident_list, func_type(((method_call)last_list_method_calls_lambda[k]).parameters.expressions.Count), parametr_kind.none, null);
            else
            {
                named_type_reference _named_type_reference = new named_type_reference();

                ident idtype = new ident("datatype");
                _named_type_reference.names.Add(idtype);

                _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
                parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);
            }
            _formal_parametres.params_list.Add(_typed_parametres);
        }
    }
    //////////////////////////
    named_type_reference _named_type_reference1 = new named_type_reference();
    ident idtype1 = new ident("datatype");
    _named_type_reference1.source_context = idtype1.source_context;
    _named_type_reference1.names.Add(idtype1);
    /////////////////////////////
    function_lambda_definition _procedure_definition = new function_lambda_definition();
    _procedure_definition.formal_parameters = _formal_parametres;
    _procedure_definition.return_type = (type_definition)_named_type_reference1;
    _procedure_definition.ident_list = i_l;
    _procedure_definition.proc_body = null;
    _procedure_definition.parameters = _expression_list;
    _procedure_definition.lambda_name = ((ident)LRParser.GetReductionSyntaxNode(0)).name;
    //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _expression_list, ((ident)LRParser.GetReductionSyntaxNode(0)).name);
    object rt = _expression_list;
    ////////////////////////////////////////for guard
    for (int i = 0; i < ar_main.Count; i++)
        if (((ArrayList)ar_main[i])[0] != null)
        {
            if_node _if_node = new if_node();
            _if_node.condition = _ob((expression)((ArrayList)ar_main[i])[0]);
            _if_node.then_body = new statement_list();
            _if_node.then_body = (statement)((ArrayList)ar_main[i])[1];
            procedure_call _exit = new procedure_call(new ident("exit") as addressed_value);
            ((statement_list)_if_node.then_body).subnodes.Add(_exit);
            _statement_list.subnodes.Add(_if_node);
        }
        else
        {
            _statement_list.subnodes.Add((statement)((ArrayList)ar_main[i])[1]);
            procedure_call _exit = new procedure_call(new ident("exit") as addressed_value);
            _statement_list.subnodes.Add(_exit);
        }
    //////////////////////////////////////////
    _procedure_definition.proc_body = _statement_list;
    parsertools.create_source_context(_procedure_definition, _expression_list, rt);
    procedure_definition pr = lambda(_procedure_definition);
    ///////////////////////////
    ///////////////////////////
    if (LRParser.GetReductionSyntaxNode(3) != null)
    {
        if (((block)pr.proc_body).defs == null)
            ((block)pr.proc_body).defs = new declarations();
        for (int i = 0; i < ((ArrayList)LRParser.GetReductionSyntaxNode(3)).Count; i++)
            ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)LRParser.GetReductionSyntaxNode(3))[i]);
    }
    if (let_where_funcs.Count > 0)
    {
        if (((block)pr.proc_body).defs == null)
            ((block)pr.proc_body).defs = new declarations();
        for (int i = 0; i < let_where_funcs.Count; i++)
            ((block)pr.proc_body).defs.defs.Add((procedure_definition)let_where_funcs[i]);
        if (let_where_funcs_main.Count+1 > token_where_count)
        {
            if (((block)pr.proc_body).defs == null)
                ((block)pr.proc_body).defs = new declarations();
            for (int i = 0; i < last_where_funcs.Count; i++)
                ((block)pr.proc_body).defs.defs.Add((procedure_definition)last_where_funcs[i]);
            for (int i = 0; i < last_where_funcs.Count; i++)
                if (let_funcs.Count > 0)
                    let_funcs.RemoveAt(let_funcs.Count - 1);
            last_where_funcs.Clear();
        }
        let_where_funcs.Clear();
        let_func_last.Clear();
        let_flag.Clear();
    }
    else
        if (let_where_funcs_main.Count > 2 && let_where_funcs_main.Count>token_where_count)
        {
            ArrayList ar = new ArrayList();
            ar = (let_where_funcs_main[let_where_funcs_main.Count - 1] as ArrayList).Clone() as ArrayList;

            if (((block)pr.proc_body).defs == null)
                ((block)pr.proc_body).defs = new declarations();
            for (int i = 0; i < ar.Count; i++)
                ((block)pr.proc_body).defs.defs.Add((procedure_definition)ar[i]);
            let_where_funcs.Clear();
            let_func_last.Clear();
            let_flag.Clear();
            let_where_funcs_main.RemoveAt(let_where_funcs_main.Count-1);
            for (int i = 0; i < ar.Count; i++)
                if (let_funcs.Count > 0)
                    let_funcs.RemoveAt(let_funcs.Count - 1);
        }
    ///////////////////////////lambda
    if (lambda_stack.Count > 0)
    {
        if (((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count > 0)
        {
            if (((block)pr.proc_body).defs == null)
                ((block)pr.proc_body).defs = new declarations();
            for (int i = 0; i < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; i++)
                ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)lambda_stack[lambda_stack.Count - 1])[i]);
            for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
                _function_lambda_definitions.RemoveAt(_function_lambda_definitions.Count - 1);
        }
        int number = ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count;
        for (int i = 0; i < number;i++ )
            lambda_stack.RemoveAt(lambda_stack.Count - 1);
    }
    ///////////////////////////
    return pr;
}
        case (int)RuleConstants.RULE_PARAMS_WHERE :
	//<params_where> ::= 
	//NONTERMINAL:<params_where> ::= 
	return null;
	//ENDNONTERMINAL
	case (int)RuleConstants.RULE_PARAMS_WHERE2 :
	//<params_where> ::= <param> <empty>
{
            							bool b = false;
    if (list_param.Count == 1)
    {
        list_params_temp.Add(new ArrayList());
        let_where_list_params.Add(new ArrayList());//
        if (list_param[0] is new_expr && ((string_const)((new_expr)list_param[0]).params_list.expressions[1]).Value == "empty")
            b = true;
        list_param.Clear();
    }
    else
    {
        list_params_temp.Add(list_param.Clone());
        let_where_list_params.Add(list_param.Clone());//
    }
    expression_list _expression_list = new expression_list();
    if (list_param.Count == 0)
    {
        if (b)
        {
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            el.expressions.Add(new int32_const(0));
            literal lt;
            string text = "empty_list";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            _expression_list.expressions.Add(newexpr);
        }
        else
        {
            _expression_list.source_context = ((expression)LRParser.GetReductionSyntaxNode(0)).source_context;
            _expression_list.expressions.Add((expression)LRParser.GetReductionSyntaxNode(0));
        }
    }
    else
    {
        ident id = new ident();
        for (int i = 0; i < list_param.Count; i++)
        {
            if (list_param[i] is ident)
                id.name += ((ident)list_param[i]).name;
            else
            {
                errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "идентификатор"));
                return null;
            }
        }
        _expression_list.source_context = ((expression)id).source_context;
        _expression_list.expressions.Add((expression)id);
        list_param.Clear();
    }
    list_params1.Clear();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
        list_params1.Add(_expression_list.expressions[i]);
    last_list_method_calls_lambda.Clear();
    return _expression_list;
        							}
	case (int)RuleConstants.RULE_PARAMS_WHERE3 :
	//<params_where> ::= <params_where> <param>

								{
            							bool b = false;
    if (list_param.Count == 1)
    {
        list_params_temp.Add(new ArrayList());
        let_where_list_params.Add(new ArrayList());//
        if (list_param[0] is new_expr && ((string_const)((new_expr)list_param[0]).params_list.expressions[1]).Value == "empty")
            b = true;
        list_param.Clear();
    }
    else
    {
        list_params_temp.Add(list_param.Clone());
        let_where_list_params.Add(list_param.Clone());
    }
    expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(0);
    if (list_param.Count == 0)
    {
        if (!b)
        {
            _expression_list.expressions.Add(LRParser.GetReductionSyntaxNode(1) as expression);
        }
        else
        {
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            el.expressions.Add(new int32_const(0));
            literal lt;
            string text = "empty_list";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            _expression_list.expressions.Add(newexpr);
        }
    }
    else
    {
        ident id = new ident();
        for (int i = 0; i < list_param.Count; i++)
        {
            if (list_param[i] is ident)
                id.name += ((ident)list_param[i]).name;
            else
            {
                errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "идентификатор"));
                return null;
            }
        }
        _expression_list.expressions.Add((expression)id);
        list_param.Clear();
    }
    list_params1.Clear();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
        list_params1.Add(_expression_list.expressions[i]);
    last_list_method_calls_lambda.Clear();
    return _expression_list;
        							}
	case (int)RuleConstants.RULE_PARAMS :
	//<params> ::= 
	//NONTERMINAL:<params> ::= 
	return null;
	//ENDNONTERMINAL
	case (int)RuleConstants.RULE_PARAMS2 :
	//<params> ::= <param> <empty>
{
    //let_flag.Add(1);
            							bool b = false;
    if (list_param.Count == 1)
    {
        list_params_temp.Add(new ArrayList());
        let_where_list_params.Add(new ArrayList());//
        if (list_param[0] is new_expr && ((string_const)((new_expr)list_param[0]).params_list.expressions[1]).Value == "empty")
            b = true;
        list_param.Clear();
    }
    else
    {
        list_params_temp.Add(list_param.Clone());
        let_where_list_params.Add(list_param.Clone());//
    }
    expression_list _expression_list = new expression_list();
    if (list_param.Count == 0)
    {
        if (b)
        {
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            el.expressions.Add(new int32_const(0));
            literal lt;
            string text = "empty_list";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            _expression_list.expressions.Add(newexpr);
        }
        else
        {
            _expression_list.source_context = ((expression)LRParser.GetReductionSyntaxNode(0)).source_context;
            _expression_list.expressions.Add((expression)LRParser.GetReductionSyntaxNode(0));
        }
    }
    else
    {
        ident id = new ident();
        for (int i = 0; i < list_param.Count; i++)
        {
            if (list_param[i] is ident)
                id.name += ((ident)list_param[i]).name;
            else
            {
                errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "идентификатор"));
                return null;
            }
        }
        _expression_list.source_context = ((expression)id).source_context;
        _expression_list.expressions.Add((expression)id);
        list_param.Clear();
    }
    list_params1.Clear();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
        list_params1.Add(_expression_list.expressions[i]);
    last_list_method_calls_lambda.Clear();
    return _expression_list;
        							}
	case (int)RuleConstants.RULE_PARAMS3 :
	//<params> ::= <params> <param>

								{
            							bool b = false;
    if (list_param.Count == 1)
    {
        list_params_temp.Add(new ArrayList());
        let_where_list_params.Add(new ArrayList());//
        if (list_param[0] is new_expr && ((string_const)((new_expr)list_param[0]).params_list.expressions[1]).Value == "empty")
            b = true;
        list_param.Clear();
    }
    else
    {
        list_params_temp.Add(list_param.Clone());
        let_where_list_params.Add(list_param.Clone());//
    }
    expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(0);
    if (list_param.Count == 0)
    {
        if (!b)
        {
            _expression_list.expressions.Add(LRParser.GetReductionSyntaxNode(1) as expression);
        }
        else
        {
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            el.expressions.Add(new int32_const(0));
            literal lt;
            string text = "empty_list";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            _expression_list.expressions.Add(newexpr);
        }
    }
    else
    {
        ident id = new ident();
        for (int i = 0; i < list_param.Count; i++)
        {
            if (list_param[i] is ident)
                id.name += ((ident)list_param[i]).name;
            else
            {
                errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "идентификатор"));
                return null;
            }
        }
        _expression_list.expressions.Add((expression)id);
        list_param.Clear();
    }
    list_params1.Clear();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
        list_params1.Add(_expression_list.expressions[i]);
    last_list_method_calls_lambda.Clear();
    return _expression_list;
        							}
								
	case (int)RuleConstants.RULE_PARAM :
	//<param> ::= <list_param>
return LRParser.GetReductionSyntaxNode(0);
    case (int)RuleConstants.RULE_LIST_PARAM_TKIDENT:
//<list_param> ::= 'tkIdent' <empty>
{
    list_param.Add(LRParser.GetReductionSyntaxNode(0));
    return LRParser.GetReductionSyntaxNode(0);
}
    case (int)RuleConstants.RULE_LIST_PARAM :
	//<list_param> ::= <simple_type_expr> <empty>
{
    list_param.Add(LRParser.GetReductionSyntaxNode(0));
    return LRParser.GetReductionSyntaxNode(0);
}
    case (int)RuleConstants.RULE_LIST_PARAM_TKSQUAREOPEN_TKSQUARECLOSE:
//<list_param> ::= 'tkSquareOpen' 'tkSquareClose'
{
    ArrayList list_elements = new ArrayList();//(ArrayList)LRParser.GetReductionSyntaxNode(1);
    //////////////////////////////////////////////////////////proverka na type
    if (list_elements != null)
    {
        ArrayList types = new ArrayList();
        for (int i = 0; i < list_elements.Count; i++)
        {
            string tp = "";
            if (list_elements[i] is new_expr)
            {
                tp = ((string_const)((new_expr)list_elements[i]).params_list.expressions[1]).Value;
                if (!types.Contains(tp))
                    types.Add(tp);
            }
        }
        if ((types.Count == 2 && !(types.Contains("integer") && types.Contains("real"))) || types.Count > 2)
        {
            //errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "одинаковый тип элементов списка"));
            errors.Add(new PascalABCCompiler.Errors.Error("элементы списка имеют разный тип"));
            return null;
        }
    }
    //////////////////////////////////////////////////////////
    named_type_reference _named_type_reference1 = new named_type_reference();
    ident idtype1 = new ident("datatype_list");
    _named_type_reference1.source_context = idtype1.source_context;
    _named_type_reference1.names.Add(idtype1);
    expression_list el = new expression_list();
    if (list_elements == null)
        list_elements = new ArrayList();
    int32_const n = new int32_const(list_elements.Count);
    el.expressions.Add(n);
    if (list_elements.Count > 0)
    {
        el.expressions.Add(new string_const("list"));
    }
    else
        el.expressions.Add(new string_const("empty"));
    for (int i = 0; i < list_elements.Count; i++)
        el.expressions.Add(list_elements[i] as expression);
    named_type_reference ntr = _named_type_reference1;
    new_expr newexpr = new new_expr(ntr, el, false, null);
    parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
    list_param.Add(newexpr);
    return newexpr;
}
    case (int)RuleConstants.RULE_LIST_PARAM_TKBOTTOMMINUS:
//<list_param> ::= 'tkBottomMinus'
{
    ident _ident = new ident("$$$" + bottom_num);
    list_param.Add(_ident);
    bottom_num++;
    return _ident;
}
    case (int)RuleConstants.RULE_LIST_PARAM_TKIDENT_TKCOLON:
//<list_param> ::= 'tkIdent' 'tkColon' <list_param>
{  
								list_param.Add(LRParser.GetReductionSyntaxNode(0));
            							return LRParser.GetReductionSyntaxNode(0);
        							}
    case (int)RuleConstants.RULE_LIST_PARAM_TKBOTTOMMINUS_TKCOLON:
//<list_param> ::= 'tkBottomMinus' 'tkColon' <list_param>
{
    ident _ident = new ident("$$$" + bottom_num);
    list_param.Add(_ident);
    bottom_num++;
    return _ident;
}
    case (int)RuleConstants.RULE_LIST_PARAM_TKROUNDOPEN_TKROUNDCLOSE:
//<list_param> ::= 'tkRoundOpen' <list_param> 'tkRoundClose'
{
    return LRParser.GetReductionSyntaxNode(1);
}
    case (int)RuleConstants.RULE_GUARD :
	//<guard> ::= 
	//NONTERMINAL:<guard> ::= 
	return null;
	//ENDNONTERMINAL
	case (int)RuleConstants.RULE_GUARD_TKSPLIT :
	//<guard> ::= 'tkSplit' <expr>
    return LRParser.GetReductionSyntaxNode(1);
    case (int)RuleConstants.RULE_GUARD_TKSPLIT_TKOTHERWISE:
    //<guard> ::= 'tkSplit' 'tkOtherwise'
    {
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.names.Add(idtype1);
        /////
        expression_list el = new expression_list();
        el.expressions.Add(new ident("true") as expression);
        literal lt;
        string text = "boolean";
        lt = new string_const(text);
        el.expressions.Add(lt as expression);
        /////
        named_type_reference ntr = _named_type_reference1;
        new_expr newexpr = new new_expr(ntr, el, false, null);
        parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
        return newexpr;
    }
	case (int)RuleConstants.RULE_MAIN_FUNC_TKMAINIDENT1_TKASSIGN :
	//<main_func> ::= 'tkMainIdent1' 'tkAssign' <body_func>
    {
			block _block=new block(null, null);
			
							 	statement_list sl=null;
                                if (LRParser.GetReductionSyntaxNode(2) is statement_list)
                                {
                                    sl = LRParser.GetReductionSyntaxNode(2) as statement_list;
                                    ///////////////////////
                                    ident_list il = new ident_list();
                                    il.idents.Add(new ident("result"));
                                    named_type_reference _named_type_reference1 = new named_type_reference();
                                    ident idtype1 = new ident("datatype");
                                    _named_type_reference1.source_context = idtype1.source_context;
                                    _named_type_reference1.names.Add(idtype1);

                                    var_def_statement _var_def_statement = new var_def_statement(il, (type_definition)_named_type_reference1, null, definition_attribute.None, false);
                                    parsertools.create_source_context(_var_def_statement, il, _named_type_reference1);
                                    var_statement _var_statement = new var_statement(_var_def_statement);
                                    parsertools.create_source_context(_var_statement, null, _var_def_statement);
                                    sl.subnodes.Insert(0,_var_statement);
                                    /////////////////////////
                                }
                                else
                                {
                                    sl = new statement_list();
                                    ///////////////////////
                                    ident_list il = new ident_list();
                                    il.idents.Add(new ident("result"));
                                    named_type_reference _named_type_reference1 = new named_type_reference();
                                    ident idtype1 = new ident("datatype");
                                    _named_type_reference1.source_context = idtype1.source_context;
                                    _named_type_reference1.names.Add(idtype1);

                                    var_def_statement _var_def_statement = new var_def_statement(il, (type_definition)_named_type_reference1, null, definition_attribute.None, false);
                                    parsertools.create_source_context(_var_def_statement, il, _named_type_reference1);
                                    var_statement _var_statement = new var_statement(_var_def_statement);
                                    parsertools.create_source_context(_var_statement, null, _var_def_statement);
                                    sl.subnodes.Add(_var_statement);
                                    /////////////////////////
                                    sl.subnodes.Add(LRParser.GetReductionSyntaxNode(2) as statement);
                                    if (!(LRParser.GetReductionSyntaxNode(2) is empty_statement))
                                        parsertools.assign_source_context(sl, LRParser.GetReductionSyntaxNode(2));
                                }
								_block.program_code=sl;
								
			return _block;
		}
								
	case (int)RuleConstants.RULE_BODY_FUNC :
	//<body_func> ::= <stmt>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_STMTS :
	//<stmts> ::= <stmt> <empty> <empty>
         
		{
			statement_list _statement_list=new statement_list();
			
							_statement_list.subnodes.Add((statement)LRParser.GetReductionSyntaxNode(0));
							parsertools.assign_source_context(_statement_list,LRParser.GetReductionSyntaxNode(0)); 
			return _statement_list;
		}

	case (int)RuleConstants.RULE_STMTS_TKSEMICOLON :
	//<stmts> ::= <stmts> 'tkSemiColon' <stmt>
         
		{
			statement_list _statement_list;
			 _statement_list=(statement_list)LRParser.GetReductionSyntaxNode(0);
							_statement_list.subnodes.Add((statement)LRParser.GetReductionSyntaxNode(2));
							parsertools.create_source_context(_statement_list,_statement_list,parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(2),LRParser.GetReductionSyntaxNode(1))); 
			return _statement_list;
		}
    case (int)RuleConstants.RULE_STMTS1:
        //<stmts1> ::= <stmt> <empty> <empty>
        {
            statement_list _statement_list = new statement_list();

            _statement_list.subnodes.Add((statement)LRParser.GetReductionSyntaxNode(0));
            parsertools.assign_source_context(_statement_list, LRParser.GetReductionSyntaxNode(0));
            return _statement_list;
        }
    case (int)RuleConstants.RULE_STMTS12:
        //<stmts1> ::= <stmts1> <stmt>
        {
            statement_list _statement_list;
            _statement_list = (statement_list)LRParser.GetReductionSyntaxNode(0);
            _statement_list.subnodes.Add((statement)LRParser.GetReductionSyntaxNode(1));
            parsertools.create_source_context(_statement_list, _statement_list, parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(1), 
                LRParser.GetReductionSyntaxNode(1)));
            return _statement_list;
        } 
	case (int)RuleConstants.RULE_EXPR_TKEQUAL :
	//<expr> ::= <expr> 'tkEqual' <add_expr>
         
		{
			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_EXPR_TKNOTEQUAL:
        //<expr> ::= <expr> 'tkNotEqual' <add_expr>
        {
            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_EXPR_TKMORE :
	//<expr> ::= <expr> 'tkMore' <add_expr>
         
		{
			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_EXPR_TKLESS :
	//<expr> ::= <expr> 'tkLess' <add_expr>
         
		{
			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_EXPR_TKMOREEQ :
	//<expr> ::= <expr> 'tkMoreEq' <add_expr>
         
		{
			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_EXPR_TKLESSEQ :
	//<expr> ::= <expr> 'tkLessEq' <add_expr>
         
		{
			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_EXPR :
	//<expr> ::= <add_expr>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_LIST_TKSQUAREOPEN_TKSQUARECLOSE :
	//<list> ::= 'tkSquareOpen' <list_elements> 'tkSquareClose'
{
		ArrayList list_elements = (ArrayList)LRParser.GetReductionSyntaxNode(1);
    //////////////////////////////////////////////////////////proverka na type
        if (list_elements != null)
        {
            ArrayList types = new ArrayList();
            for (int i = 0; i < list_elements.Count; i++)
            {
                string tp = "";
                if (list_elements[i] is new_expr)
                {
                    tp = ((string_const)((new_expr)list_elements[i]).params_list.expressions[1]).Value;
                    if (!types.Contains(tp))
                        types.Add(tp);
                }
            }
            if ((types.Count == 2 && !(types.Contains("integer") && types.Contains("real"))) || types.Count > 2)
            {
                //errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "одинаковый тип элементов списка"));
                errors.Add(new PascalABCCompiler.Errors.Error("элементы списка имеют разный тип"));
                return null;
            }
        }
    //////////////////////////////////////////////////////////
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype_list");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            if (list_elements == null)
                list_elements = new ArrayList();
            int32_const n = new int32_const(list_elements.Count);
            el.expressions.Add(n);
            if (list_elements.Count > 0)
            {
                el.expressions.Add(new string_const("list"));
            }
            else
                el.expressions.Add(new string_const("empty"));
            for (int i = 0; i < list_elements.Count;i++ )
                el.expressions.Add(list_elements[i] as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
            return newexpr;
		}
	case (int)RuleConstants.RULE_LIST_TKSQUAREOPEN_TKDOT_TKDOT_TKSQUARECLOSE :
	//<list> ::= 'tkSquareOpen' <list_elements> 'tkDot' 'tkDot' <simple_expr> 'tkSquareClose'
{ArrayList list_elements = (ArrayList)LRParser.GetReductionSyntaxNode(1);
//////////////////////////////////////////////////////////proverka na type
ArrayList types = new ArrayList();
for (int i = 0; i < list_elements.Count; i++)
{
    if (list_elements[i] is new_expr)
    {
        string tp = ((string_const)((new_expr)list_elements[i]).params_list.expressions[1]).Value;
        if (!types.Contains(tp))
            types.Add(tp);
    }
}
if (LRParser.GetReductionSyntaxNode(4) is new_expr)
{
    new_expr ex_last = (new_expr)LRParser.GetReductionSyntaxNode(4);
    string tp_last = ((string_const)ex_last.params_list.expressions[1]).Value;
    if (!types.Contains(tp_last))
        types.Add(tp_last);
}
if ((types.Count == 2 && !(types.Contains("integer") && types.Contains("real"))) || types.Count > 2)
{
    //errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "одинаковый тип элементов списка"));
    errors.Add(new PascalABCCompiler.Errors.Error("элементы списка имеют разный тип"));
    return null;
}
if (list_elements.Count > 2)
{
    errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "."));
    return null;
}
//////////////////////////////////////////////////////////
    named_type_reference _named_type_reference1 = new named_type_reference();
		      ident idtype1 = new ident("datatype_list");
		      _named_type_reference1.source_context = idtype1.source_context;
		      _named_type_reference1.names.Add(idtype1);
			expression_list el = new expression_list();
            el.expressions.Add(list_elements[0] as expression);
            if (list_elements.Count>1)
                el.expressions.Add(list_elements[1] as expression);
            el.expressions.Add(LRParser.GetReductionSyntaxNode(4) as expression);
            el.expressions.Add(new string_const("list"));
	named_type_reference ntr = _named_type_reference1;
			new_expr newexpr = new new_expr(ntr, el, false, null);
			parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
			return newexpr;
											}
	case (int)RuleConstants.RULE_LIST_TKSQUAREOPEN_TKDOT_TKDOT_TKSQUARECLOSE2 :
	//<list> ::= 'tkSquareOpen' <list_elements> 'tkDot' 'tkDot' 'tkSquareClose'
{ArrayList list_elements = (ArrayList)LRParser.GetReductionSyntaxNode(1);
//////////////////////////////////////////////////////////proverka na type
ArrayList types = new ArrayList();
for (int i = 0; i < list_elements.Count; i++)
{
    if (list_elements[i] is new_expr) 
    {
        string tp = ((string_const)((new_expr)list_elements[i]).params_list.expressions[1]).Value;
        if (!types.Contains(tp))
            types.Add(tp);
    }
}
if (types.Count == 2 && !(types.Contains("integer") && types.Contains("real")))
{
    //errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "одинаковый тип элементов списка"));
    errors.Add(new PascalABCCompiler.Errors.Error("элементы списка имеют разный тип"));
    return null;
}
if (list_elements.Count > 2)
{
    errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "."));
    return null;
}
//////////////////////////////////////////////////////////
    named_type_reference _named_type_reference1 = new named_type_reference();
             ident idtype1 = new ident("datatype_list");
             _named_type_reference1.source_context = idtype1.source_context;
             _named_type_reference1.names.Add(idtype1);
             expression_list el = new expression_list();
             el.expressions.Add(list_elements[0] as expression);
             el.expressions.Add(list_elements[1] as expression);
             named_type_reference _named_type_reference11 = new named_type_reference();
             ident idtype11 = new ident("datatype");
             _named_type_reference11.names.Add(idtype11);
             expression_list ell = new expression_list();
             new_expr ee = list_elements[0] as new_expr;
             ell.expressions.Add(ee.params_list.expressions[0]);
             literal lt;
             string text = "nil";
             lt = new string_const(text);
             ell.expressions.Add(lt as expression);
             named_type_reference ntrr = _named_type_reference11; 
             new_expr newexprr = new new_expr(ntrr, ell, false, null);
             el.expressions.Add(newexprr);
             el.expressions.Add(new string_const("list"));
             named_type_reference ntr = _named_type_reference1;
             new_expr newexpr = new new_expr(ntr, el, false, null);
             parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
             return newexpr;}
    case (int)RuleConstants.RULE_LIST:
    //<list> ::= <list_constructor>
    return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_LIST_TKCOLON :
	//<list> ::= <simple_expr> 'tkColon' <empty> <simple_expr>
{expression_list el = new expression_list();
    el.expressions.Add(LRParser.GetReductionSyntaxNode(3) as expression);
    dot_node _dot_node = new dot_node(null, new ident("colon"));
    _dot_node.left = (addressed_value)LRParser.GetReductionSyntaxNode(0);
    method_call _method_call = new method_call(el);
    _method_call.dereferencing_value = (addressed_value)_dot_node;
    return _method_call;}
    case (int)RuleConstants.RULE_LIST_CONSTRUCTOR_TKSQUAREOPEN_TKSPLIT_TKSQUARECLOSE:
//<list_constructor> ::= 'tkSquareOpen' <simple_expr> 'tkSplit' <generators> <conditions_comma> 'tkSquareClose'
{
    ArrayList generators=(ArrayList)LRParser.GetReductionSyntaxNode(3);
    ArrayList conditions = (ArrayList)LRParser.GetReductionSyntaxNode(4);
    //////////////////////////////////////////////////////////////////////////
    statement_list body = new statement_list();
    rec_num = 0;
    for (int i = 0; i < generators.Count; i++)
    {
        ident id = null;
        if (((ArrayList)generators[i])[0] is new_expr)
        {
            constructor_rec_var(body, ((ArrayList)generators[i])[0] as new_expr);
        }
        else
        {
            id = (ident)((ArrayList)generators[i])[0];
            ident_list _ident_list1 = new ident_list();
            _ident_list1.idents.Add(id);
            string name_param2 = id.name;
            typed_parameters _typed_parametres2 = null;
            named_type_reference _named_type_reference3 = new named_type_reference();
            ident idtype3 = new ident("datatype");
            _named_type_reference3.names.Add(idtype3);
            var_def_statement _var_def_statement2 = new var_def_statement(_ident_list1, (type_definition)_named_type_reference3, null, definition_attribute.None, false);
            var_statement _var_statement2 = new var_statement(_var_def_statement2);
            body.subnodes.Add(_var_statement2);
        }
    }
    ///////////////////////////////////////////////////////////////////////result
    named_type_reference _named_type_reference2 = new named_type_reference();
    ident idtype2 = new ident("datatype_list");
    _named_type_reference2.names.Add(idtype2);
    expression_list el2 = new expression_list();
    int32_const n = new int32_const(0);
    el2.expressions.Add(n);
    el2.expressions.Add(new string_const("list"));
    named_type_reference ntr = _named_type_reference2;
    new_expr newexpr = new new_expr(ntr, el2, false, null);
    assign _result = new assign();
    _result.operator_type = Operators.Assignment;
    _result.to = new ident("result");
    _result.from = newexpr;
    body.subnodes.Add(_result);
    //////////////////////////////////////////////////////////////////////if
    if_node _if_node = new if_node();
    if (conditions != null)
    {
        expression b_e = (expression)conditions[conditions.Count - 1];
        for (int i = conditions.Count - 2; i >= 0; i--)
        {
            bin_expr b_e1 = new bin_expr();
            b_e1.operation_type = Operators.LogicalAND;
            b_e1.left = (expression)conditions[i];
            b_e1.right = b_e;
            b_e = b_e1;
        }
        _if_node.condition = _ob(b_e);
    }
    //////////////////////////////////////////////////////////////////////assign
    statement_list stmt_list=new statement_list();
    rec_num = 0;
    for (int i = 0; i < generators.Count; i++)
    {
        if (((ArrayList)generators[i])[0] is new_expr)
        {
            constructor_rec_ass(stmt_list, ((ArrayList)generators[i])[0] as new_expr, _index((expression)((ArrayList)generators[i])[1], new ident("$i" + i)));
        }
        else
        {
            assign _assign = new assign();
            _assign.operator_type = Operators.Assignment;
            _assign.to = (ident)((ArrayList)generators[i])[0];
            _assign.from = _index((expression)((ArrayList)generators[i])[1], new ident("$i" + i));
            stmt_list.subnodes.Add(_assign);
        }
    }
    if (conditions != null)
    {
        _if_node.then_body = _add(new ident("result"), (expression)LRParser.GetReductionSyntaxNode(1));
        stmt_list.subnodes.Add(_if_node);
    }
    else
        stmt_list.subnodes.Add(_add(new ident("result"), (expression)LRParser.GetReductionSyntaxNode(1)));
    //////////////////////////////////////////////////////////////////////for
    statement _for_stmt = stmt_list;
    for (int i = generators.Count - 1; i >= 0; i--)
    {
        for_node _for_node = new for_node();
        _for_node.cycle_type = for_cycle_type.to;
        _for_node.loop_variable = new ident("$i"+i);
        named_type_reference _named_type_reference = new named_type_reference();
        ident idtype = new ident("integer");
        _named_type_reference.names.Add(idtype);
        _for_node.type_name = (type_definition)_named_type_reference;
        _for_node.initial_value = new int32_const(0);
        _for_node.finish_value = _count((expression)((ArrayList)generators[i])[1]);
        _for_node.increment_value = new int32_const(1);
        _for_node.statements = _for_stmt;
        _for_stmt = _for_node;
    }
    body.subnodes.Add(_for_stmt);
    ///////////////////////////////////////////////////////////////////////////////////////////////////////lambda
    formal_parameters _formal_parametres = null;
    //////////////////////////
    named_type_reference _named_type_reference1 = new named_type_reference();
    ident idtype1 = new ident("datatype");
    _named_type_reference1.source_context = idtype1.source_context;
    _named_type_reference1.names.Add(idtype1);
    /////////////////////////////
    lambda_num++;
    function_lambda_definition _procedure_definition = new function_lambda_definition();
    _procedure_definition.formal_parameters = _formal_parametres;
    _procedure_definition.return_type = (type_definition)_named_type_reference1;
    _procedure_definition.ident_list = null;
    _procedure_definition.proc_body = null;
    _procedure_definition.parameters = null;
    _procedure_definition.lambda_name = "__lambda__" + lambda_num;
    //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, null, null, null, "lambda" + lambda_num);
    _procedure_definition.proc_body = body;
    procedure_definition pr = lambda(_procedure_definition);
    //_function_lambda_definitions.Add(_procedure_definition);////////////////
    let_funcs.Add(pr);
    let_where_funcs.Add(pr);
    if (let_flag.Count > 0)
        let_func_last.Add(pr);
    expression_list el = new expression_list();
    let_fact_params.Clear();
    return new ident(_procedure_definition.lambda_name);
}
    case (int)RuleConstants.RULE_GENERATORS:
        //<generators> ::= <generator> <empty>
        {
            ArrayList ar = new ArrayList();
            ar.Add(LRParser.GetReductionSyntaxNode(0));
            return ar;
        }
    case (int)RuleConstants.RULE_GENERATORS_TKCOMMA:
        //<generators> ::= <generators> 'tkComma' <generator>
        {
            ArrayList ar = (ArrayList)LRParser.GetReductionSyntaxNode(0);
            ar.Add(LRParser.GetReductionSyntaxNode(2));
            return ar;
        }
    case (int)RuleConstants.RULE_GENERATOR_TKARROWGEN:
        //<generator> ::= <simple_expr> 'tkArrowGen' <simple_expr>
        {
            ArrayList ar = new ArrayList();
            ar.Add(LRParser.GetReductionSyntaxNode(0));
            ar.Add(LRParser.GetReductionSyntaxNode(2));
            return ar;
        }
    case (int)RuleConstants.RULE_CONDITIONS_COMMA:
        //<conditions_comma> ::= <empty>
        {
            return null;
        }
    case (int)RuleConstants.RULE_CONDITIONS_COMMA_TKCOMMA:
        //<conditions_comma> ::= 'tkComma' <conditions>
        {
            return LRParser.GetReductionSyntaxNode(1);
        }
    case (int)RuleConstants.RULE_CONDITIONS:
        //<conditions> ::= <condition> <empty>
        {
            ArrayList ar = new ArrayList();
            ar.Add(LRParser.GetReductionSyntaxNode(0));
            return ar;
        }
    case (int)RuleConstants.RULE_CONDITIONS_TKCOMMA:
        //<conditions> ::= <conditions> 'tkComma' <condition>
        {
            ArrayList ar = (ArrayList)LRParser.GetReductionSyntaxNode(0);
            ar.Add(LRParser.GetReductionSyntaxNode(2));
            return ar;
        }
    case (int)RuleConstants.RULE_CONDITION:
        //<condition> ::= <expr>
        return LRParser.GetReductionSyntaxNode(0);
    case (int)RuleConstants.RULE_CORTEG_TKROUNDOPEN_TKCOMMA_TKROUNDCLOSE:
//<corteg> ::= 'tkRoundOpen' <simple_expr> 'tkComma' <list_elements> 'tkRoundClose'
        {
            //new_expr first_el = (new_expr)LRParser.GetReductionSyntaxNode(1);
            ArrayList list_elements = (ArrayList)LRParser.GetReductionSyntaxNode(3);
            list_elements.Insert(0, LRParser.GetReductionSyntaxNode(1));
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype_list");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            if (list_elements == null)
                list_elements = new ArrayList();
            int32_const n = new int32_const(list_elements.Count);
            el.expressions.Add(n);
            if (list_elements.Count > 0)
            {
                el.expressions.Add(new string_const("corteg"));
            }
            else
                el.expressions.Add(new string_const("empty"));
            for (int i = 0; i < list_elements.Count; i++)
                el.expressions.Add(list_elements[i] as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
            return newexpr;
        }
	case (int)RuleConstants.RULE_LIST_ELEMENTS :
	//<list_elements> ::= <empty>
return null;
	case (int)RuleConstants.RULE_LIST_ELEMENTS2 :
	//<list_elements> ::= <simple_expr> <empty>
{
                 ArrayList list_elements = new ArrayList();
                 list_elements.Add(LRParser.GetReductionSyntaxNode(0));
                 return list_elements;
             }
	case (int)RuleConstants.RULE_LIST_ELEMENTS_TKCOMMA :
	//<list_elements> ::= <list_elements> 'tkComma' <simple_expr>
{
                 ((ArrayList)LRParser.GetReductionSyntaxNode(0)).Add(LRParser.GetReductionSyntaxNode(2));
                 return LRParser.GetReductionSyntaxNode(0);
             }
	case (int)RuleConstants.RULE_ADD_EXPR_TKAND :
	//<add_expr> ::= <add_expr> 'tkAnd' <mult_expr>
         
		{
			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_ADD_EXPR :
	//<add_expr> ::= <add_expr> <addop> <mult_expr>
         
		{
			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_ADD_EXPR2 :
	//<add_expr> ::= <mult_expr>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_MULT_EXPR_TKOR :
	//<mult_expr> ::= <mult_expr> 'tkOr' <negate_expr>
         
		{
			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_MULT_EXPR :
	//<mult_expr> ::= <mult_expr> <multop> <negate_expr>
         
		{
			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_MULT_EXPR2 :
	//<mult_expr> ::= <negate_expr>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_NEGATE_EXPR_TKMINUS :
	//<negate_expr> ::= 'tkMinus' <simple_expr>
         
		{
			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_NEGATE_EXPR_TKNOT :
	//<negate_expr> ::= 'tkNot' <simple_expr>
         
		{
			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_NEGATE_EXPR :
	//<negate_expr> ::= <simple_expr>
return LRParser.GetReductionSyntaxNode(0);
    case (int)RuleConstants.RULE_SIMPLE_EXPR:
//<simple_expr> ::= <simple_type_expr>
return LRParser.GetReductionSyntaxNode(0);
    case (int)RuleConstants.RULE_SIMPLE_TYPE_EXPR_TKINT:
//<simple_type_expr> ::= 'tkInt'

{
            named_type_reference _named_type_reference1 = new named_type_reference();

            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);

            /////
            expression_list el = new expression_list();
            el.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);
            literal lt;
            string text = "integer";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            /////
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false,null);
            parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
            return newexpr;
        }
    case (int)RuleConstants.RULE_SIMPLE_TYPE_EXPR_TKDOUBLE:
//<simple_type_expr> ::= 'tkDouble'
{
            named_type_reference _named_type_reference1 = new named_type_reference();

            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);

            /////
            expression_list el = new expression_list();
            el.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);
            literal lt;
            string text = "real";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            /////
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false,null);
            parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
            return newexpr;
        }
    case (int)RuleConstants.RULE_SIMPLE_TYPE_EXPR_TKBOOL:
//<simple_type_expr> ::= 'tkBool'
{
            named_type_reference _named_type_reference1 = new named_type_reference();

            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);

            /////
            expression_list el = new expression_list();
            el.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);
            literal lt;
            string text = "boolean";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            /////
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false,null);
            parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
            return newexpr;
        }
    case (int)RuleConstants.RULE_SIMPLE_TYPE_EXPR_TKCHAR:
//<simple_type_expr> ::= 'tkChar'
{
            named_type_reference _named_type_reference1 = new named_type_reference();

            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);

            /////
            expression_list el = new expression_list();
            el.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);
            literal lt;
            string text = "char";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            /////
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false,null);
            parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
            return newexpr;
        }
    case (int)RuleConstants.RULE_SIMPLE_TYPE_EXPR_TKSTRING:
//<simple_type_expr> ::= 'tkString'
{
            named_type_reference _named_type_reference1 = new named_type_reference();

            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);

            /////
            expression_list el = new expression_list();
            el.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);
            literal lt;
            string text = "string";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            /////
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false,null);
            parsertools.create_source_context(newexpr, new ident("new"), parsertools.sc_not_null(el, _named_type_reference1));
            return newexpr;
        }
	case (int)RuleConstants.RULE_SIMPLE_EXPR_TKROUNDOPEN_TKROUNDCLOSE :
	//<simple_expr> ::= 'tkRoundOpen' <expr> 'tkRoundClose'
return LRParser.GetReductionSyntaxNode(1);
    case (int)RuleConstants.RULE_SIMPLE_EXPR2:
//<simple_expr> ::= <infix_expr> <empty>
{
    if (LRParser.GetReductionSyntaxNode(0) is ArrayList)
    {
        ////////////////////////////////////////////////////////ident_params
        ArrayList arr = (ArrayList)LRParser.GetReductionSyntaxNode(0);
        ident _ident = (ident)arr[0];
        expression_list el = new expression_list();
        for (int ii = 1; ii < arr.Count; ii++)
            el.expressions.Add((expression)arr[ii]);
        ////////////////////////////////////////////////////////
        //expression_list el = LRParser.GetReductionSyntaxNode(2) as expression_list;
        ////////////////////////////for curring
        int n = el.expressions.Count;
        int fld_params_count = find_count_params(_ident.name);
        ////////////////////////////
        if (fld_params_count - n > 0)
        {
            expression_list _expression_list = el;
            expression_list _params = new expression_list();
            expression_list _params_el = new expression_list();
            for (int i = 0; i < list_params1.Count; i++)
                if (list_params1[i] is ident)
                {
                    _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                    _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
                }
            for (int i = 1; i <= fld_params_count - n; i++)
                _expression_list.expressions.Add(new ident("$$" + i));
            for (int i = 1; i <= fld_params_count - n; i++)
            {
                _params.expressions.Add(new ident("$$" + i));
                _params_el.expressions.Add(new ident("$$" + i));
            }
            method_call _method_call = new method_call(_expression_list);
            if (_method_call is dereference)
                ((dereference)_method_call).dereferencing_value = (addressed_value)_ident;

            op_type_node _op_type_node = new op_type_node(Operators.Assignment);
            assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

            statement_list _statement_list = new statement_list();
            _statement_list.subnodes.Add(_assign);
            ////////////////////////////
            ident_list i_l = new ident_list();
            for (int i = 1; i <= fld_params_count - n; i++)
                i_l.idents.Add(new ident("$$" + i));
            /////////////////////////////
            formal_parameters _formal_parametres = new formal_parameters();
            for (int i = 0; i < _params.expressions.Count; i++)
            {
                ident_list _ident_list = new ident_list();
                ident id = (ident)_params.expressions[i];
                _ident_list.idents.Add(id);
                named_type_reference _named_type_reference = new named_type_reference();

                ident idtype = new ident("datatype");
                _named_type_reference.names.Add(idtype);

                typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
                parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

                _formal_parametres.params_list.Add(_typed_parametres);
            }
            //////////////////////////
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            /////////////////////////////
            lambda_num++;
            function_lambda_definition _procedure_definition = new function_lambda_definition();
            _procedure_definition.formal_parameters = _formal_parametres;
            _procedure_definition.return_type = (type_definition)_named_type_reference1;
            _procedure_definition.ident_list = i_l;
            _procedure_definition.proc_body = null;
            _procedure_definition.parameters = _params_el;
            _procedure_definition.lambda_name = "__lambda__" + lambda_num;
            //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
            object rt = _expression_list;
            _procedure_definition.proc_body = _statement_list;
            _function_lambda_definitions_after.Add(_procedure_definition);
            _function_lambda_definitions_after.Add(_ident.name);////////////////
            last_function_lambda_definitions.Add(_procedure_definition);
            return new ident(_procedure_definition.lambda_name);
        }
        else
        {
            method_call _method_call = new method_call(el);

            if (_method_call is dereference)
            {
                ((dereference)_method_call).dereferencing_value = (addressed_value)_ident;
                parsertools.create_source_context(_method_call, _ident, _method_call);
            }
            list_method_calls.Add(_method_call);
            last_list_method_calls.Add(_method_call);
            last_list_method_calls_lambda.Add(_method_call);
            return _method_call;

        }
    }
    else
        return LRParser.GetReductionSyntaxNode(0);
}
	case (int)RuleConstants.RULE_SIMPLE_EXPR3 :
	//<simple_expr> ::= <variable>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_SIMPLE_EXPR_TKLET_TKIN :
	//<simple_expr> ::= 'tkLet' <def_vars> 'tkIn' <body_func>
{//////////////////////////
    expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(1);
    statement_list _statement_list = (statement_list)LRParser.GetReductionSyntaxNode(3);
    //////////////////////////
    formal_parameters _formal_parametres = null;
    //////////////////////////
    named_type_reference _named_type_reference1 = new named_type_reference();
    ident idtype1 = new ident("datatype");
    _named_type_reference1.source_context = idtype1.source_context;
    _named_type_reference1.names.Add(idtype1);
    /////////////////////////////
    lambda_num++;
    function_lambda_definition _procedure_definition = new function_lambda_definition();
    _procedure_definition.formal_parameters = _formal_parametres;
    _procedure_definition.return_type = (type_definition)_named_type_reference1;
    _procedure_definition.ident_list = null;
    _procedure_definition.proc_body = null;
    _procedure_definition.parameters = _expression_list;
    _procedure_definition.lambda_name = "__lambda__" + lambda_num;
    //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, null, null, _expression_list, "lambda" + lambda_num);
    object rt = _expression_list;
    _procedure_definition.proc_body = _statement_list;
    parsertools.create_source_context(_procedure_definition, _expression_list, rt);
    procedure_definition pr = lambda(_procedure_definition);
    //_function_lambda_definitions.Add(_procedure_definition);////////////////
    ((block)pr.proc_body).defs = new declarations();
    int start=0;
    int k = let_funcs.Count-1;
    while (k>0 && ((procedure_definition)let_funcs[k]).proc_header.name.meth_name.name.Contains("__lambda__"))
        k--;
    int kk = 0;
    while (k > 0 && kk < _expression_list.expressions.Count-1 && !((procedure_definition)let_funcs[k]).proc_header.name.meth_name.name.Contains("__lambda__"))
    {
        k--;
        kk++;
    }
    start = k;
    int i = start;
    int n = let_funcs.Count;
    while (i < n)
    {
        if (let_where_funcs.Count > 0)
            if (start - (let_funcs.Count - let_where_funcs.Count) >= 0)
                let_where_funcs.RemoveAt(start - (let_funcs.Count - let_where_funcs.Count));
            else
                let_where_funcs.RemoveAt(let_where_funcs.Count - 1);
        ((block)pr.proc_body).defs.defs.Add((procedure_definition)let_funcs[start]);
        let_funcs.RemoveAt(start);
        i++;
    }
    ///////////////////////////lambda
    if (((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count > 0)
    {
        if (((block)pr.proc_body).defs==null)
            ((block)pr.proc_body).defs = new declarations();
        for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
            ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)lambda_stack[lambda_stack.Count - 1])[ii]);
        for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
            _function_lambda_definitions.RemoveAt(_function_lambda_definitions.Count-1);
    }
    lambda_stack.RemoveAt(lambda_stack.Count - 1);
    //lambda_stack.RemoveAt(lambda_stack.Count - 1);
    /*if (((block)pr.proc_body).defs == null)
        ((block)pr.proc_body).defs = new declarations();
    for (int ii = 0; ii < _function_lambda_definitions.Count; ii++)
        ((block)pr.proc_body).defs.defs.Add(lambda((function_lambda_definition)_function_lambda_definitions[ii]));
    _function_lambda_definitions.Clear();*/
    ///////////////////////////
    let_funcs.Add(pr);
    let_where_funcs.Add(pr);
    if (let_flag.Count>0)
        let_func_last.Add(pr);
    expression_list el = new expression_list();
    let_fact_params.Clear();
    /////////////////////
    if (let_stack.Count > 0)
        ((ArrayList)let_stack[let_stack.Count - 1]).Add(pr);
    /*else
    {
        let_funcs.Add(pr);
        let_where_funcs.Add(pr);
    }*/
    /////////////////////
    return new ident(_procedure_definition.lambda_name);
}
	case (int)RuleConstants.RULE_SIMPLE_EXPR4 :
	//<simple_expr> ::= <list>
return LRParser.GetReductionSyntaxNode(0);
    case (int)RuleConstants.RULE_SIMPLE_EXPR5:
    //<simple_expr> ::= <corteg>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_SIMPLE_EXPR6 :
	//<simple_expr> ::= <lambda_func> <empty>
return LRParser.GetReductionSyntaxNode(0);
	//case (int)RuleConstants.RULE_SIMPLE_EXPR_TKROUNDOPEN_TKROUNDCLOSE_TKROUNDOPEN_TKROUNDCLOSE :
	//<simple_expr> ::= 'tkRoundOpen' <lambda_func> 'tkRoundClose' 'tkRoundOpen' <params_value> 'tkRoundClose'
    case (int)RuleConstants.RULE_SIMPLE_EXPR_TKROUNDOPEN_TKROUNDOPEN_TKROUNDCLOSE_TKROUNDCLOSE:
//<simple_expr> ::= 'tkRoundOpen' 'tkRoundOpen' <lambda_func> 'tkRoundClose' <params_value> 'tkRoundClose'
{
            function_lambda_definition fld = find_func_lambda_name(((ident)LRParser.GetReductionSyntaxNode(2)).name);
            //function_lambda_definition fld = find_lambda_funcs(((ident)LRParser.GetReductionSyntaxNode(1)).name);
            //lambda_funcs.RemoveAt(lambda_funcs.Count-1);
            expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(4);
            function_lambda_definition _lambda_definition = fld;
            function_lambda_call _lambda_call = new function_lambda_call(_lambda_definition, _expression_list);
            return _lambda_call;
        }
	/*case (int)RuleConstants.RULE_SIMPLE_EXPR_TKROUNDOPEN_TKROUNDCLOSE2 :
	//<simple_expr> ::= <simple_expr> 'tkRoundOpen' <params_value> 'tkRoundClose'
{
		if (LRParser.GetReductionSyntaxNode(0) is function_lambda_call)
            {
                expression_list _expression_list = new expression_list();
                expression_list el_new = (expression_list)LRParser.GetReductionSyntaxNode(2);
                function_lambda_call _lambda_definition_call = (function_lambda_call)LRParser.GetReductionSyntaxNode(0);
                function_lambda_definition fld = _lambda_definition_call.f_lambda_def;
                for (int i = 0; i < _lambda_definition_call.parameters.expressions.Count; i++)
                    _expression_list.expressions.Add(_lambda_definition_call.parameters.expressions[i]);
                for (int i = 0; i < el_new.expressions.Count; i++)
                    _expression_list.expressions.Add(el_new.expressions[i]);
                function_lambda_call _lambda_call = new function_lambda_call(fld, _expression_list);
                return _lambda_call;
            }
            else
                return null;}*/
	case (int)RuleConstants.RULE_VARIABLE_EXPR :
	//<variable_expr> ::= <simple_expr>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_DEF_VARS :
	//<def_vars> ::= <def_var> <empty>
{
            expression_list el=new expression_list();
            el.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);
            return el;
        }
	case (int)RuleConstants.RULE_DEF_VARS_TKSEMICOLON :
	//<def_vars> ::= <def_vars> 'tkSemiColon' <def_var>
{
            expression_list el=(expression_list)LRParser.GetReductionSyntaxNode(0);
            el.expressions.Add(LRParser.GetReductionSyntaxNode(2) as expression);
            return el;

        }
    case (int)RuleConstants.RULE_DEF_VAR_TKIDENT:
//<def_var> ::= 'tkIdent' <params> <guard_body_list> <where_var>
{
    expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(1);
    /*statement_list _statement_list = (statement_list)LRParser.GetReductionSyntaxNode(4);*/
    statement_list _statement_list = new statement_list();
    ArrayList ar_main = (ArrayList)LRParser.GetReductionSyntaxNode(2);
    ////////////////////////////for list
    statement_list stmt_l = new statement_list();
    int start = let_where_list_params.Count;
    if (_expression_list != null)
        start = let_where_list_params.Count - _expression_list.expressions.Count;
    int i_ex = 0;
    for (int ll = start; ll < let_where_list_params.Count; ll++)
    {
        for (int l = 0; l < ((ArrayList)let_where_list_params[ll]).Count; l++)
        {
            ident_list il1 = new ident_list();
            il1.idents.Add(new ident(((ident)((ArrayList)let_where_list_params[ll])[l]).name));
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.names.Add(idtype1);

            var_def_statement _var_def_statement = new var_def_statement(il1, (type_definition)_named_type_reference1, null, definition_attribute.None, false);
            var_statement _var_statement = new var_statement(_var_def_statement);
            stmt_l.subnodes.Add(_var_statement);
        }
        if (((ArrayList)let_where_list_params[ll]).Count > 0)
        {
            op_type_node _op_type_node = new op_type_node(Operators.Assignment);
            dot_node _dot_node = new dot_node(null, (addressed_value)(new ident("head")));
            ident id = _expression_list.expressions[i_ex] as ident;
            /*for (int i1 = 0; i1 < ((ArrayList)let_where_list_params[ll]).Count; i1++)
                id.name += ((ident)((ArrayList)let_where_list_params[ll])[i1]).name;*/
            if (id.name != null)
            {
                _dot_node.left = (addressed_value)(id);
                object o = null;
                method_call _method_call = new method_call(o as expression_list);
                if (_method_call is dereference)
                    ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                assign _assign1 = new assign(((ident)((ArrayList)let_where_list_params[ll])[((ArrayList)let_where_list_params[ll]).Count - 1]) as addressed_value, _method_call as expression, _op_type_node.type);
                stmt_l.subnodes.Add(_assign1);

                ///
                for (int i1 = ((ArrayList)let_where_list_params[ll]).Count - 2; i1 > 0; i1--)
                {
                    _dot_node = new dot_node((addressed_value)id, (addressed_value)(new ident("tail")));
                    for (int j1 = 0; j1 < ((ArrayList)let_where_list_params[ll]).Count - 2 - i1; j1++)
                    {
                        _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("tail")));
                    }
                    _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("head")));

                    _method_call = new method_call(o as expression_list);
                    if (_method_call is dereference)
                        ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                    _assign1 = new assign(((ident)((ArrayList)let_where_list_params[ll])[i1]) as addressed_value, _method_call as expression, _op_type_node.type);
                    stmt_l.subnodes.Add(_assign1);
                }

                _dot_node = new dot_node((addressed_value)id, (addressed_value)(new ident("tail")));

                for (int j1 = 0; j1 < ((ArrayList)let_where_list_params[ll]).Count - 2; j1++)
                {
                    _dot_node = new dot_node(_dot_node, (addressed_value)(new ident("tail")));
                }
                _method_call = new method_call(o as expression_list);
                if (_method_call is dereference)
                    ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
                _assign1 = new assign(((ident)((ArrayList)let_where_list_params[ll])[0]) as addressed_value, _method_call as expression, _op_type_node.type);
                stmt_l.subnodes.Add(_assign1);
            }
        }
        i_ex++;
    }
    for (int ll = 0; ll < let_where_list_params.Count - start; ll++)
        list_params_temp.RemoveAt(list_params_temp.Count - 1);
    for (int i = stmt_l.subnodes.Count - 1; i >= 0; i--)
        _statement_list.subnodes.Insert(0, stmt_l.subnodes[i]);
    if (_expression_list != null)
        for (int i = 0; i < _expression_list.expressions.Count; i++)
            let_where_list_params.RemoveAt(let_where_list_params.Count - 1);
    ////////////////////////////
    formal_parameters _formal_parametres = null;
    ident_list i_l = new ident_list();
    if (_expression_list != null)
    {
        for (int i = 0; i < _expression_list.expressions.Count; i++)
            i_l.idents.Add((ident)_expression_list.expressions[i]);
        /////////////////////////////
        _formal_parametres = new formal_parameters();
        for (int i = 0; i < i_l.idents.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_expression_list.expressions[i];
            _ident_list.idents.Add(id);
            string name_param = id.name;
            typed_parameters _typed_parametres = null;
            int k = 0;
            while (k < last_list_method_calls_lambda.Count && ((ident)((method_call)last_list_method_calls_lambda[k]).dereferencing_value).name != name_param)
                k++;
            if (k < last_list_method_calls_lambda.Count)
                _typed_parametres = new typed_parameters(_ident_list, func_type(((method_call)last_list_method_calls_lambda[k]).parameters.expressions.Count), parametr_kind.none, null);
            else
            {
                named_type_reference _named_type_reference = new named_type_reference();

                ident idtype = new ident("datatype");
                _named_type_reference.names.Add(idtype);

                _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
                parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);
            }
            _formal_parametres.params_list.Add(_typed_parametres);
        }
    }
    //////////////////////////
    named_type_reference _n_t_r = new named_type_reference();
    ident it = new ident("datatype");
    _n_t_r.names.Add(it);
    /////////////////////////////
    //lambda_num++;
    function_lambda_definition _procedure_definition = new function_lambda_definition();
    _procedure_definition.formal_parameters = _formal_parametres;
    _procedure_definition.return_type = (type_definition)_n_t_r;
    _procedure_definition.ident_list = i_l;
    _procedure_definition.proc_body = null;
    _procedure_definition.parameters = _expression_list;
    _procedure_definition.lambda_name = ((ident)LRParser.GetReductionSyntaxNode(0)).name;
    //new function_lambda_definition(_formal_parametres, (type_definition)_n_t_r, i_l, null, _expression_list, ((ident)LRParser.GetReductionSyntaxNode(0)).name);
    object rt = _expression_list;
    ////////////////////////////////////////////////for guard
    for (int i = 0; i < ar_main.Count;i++ )
        if (((ArrayList)ar_main[i])[0] != null)
        {
            if_node _if_node = new if_node();
            _if_node.condition = _ob((expression)((ArrayList)ar_main[i])[0]);
            _if_node.then_body = new statement_list();
            _if_node.then_body = (statement)((ArrayList)ar_main[i])[1];
            procedure_call _exit = new procedure_call(new ident("exit") as addressed_value);
            ((statement_list)_if_node.then_body).subnodes.Add(_exit);
            _statement_list.subnodes.Add(_if_node);
        }
        else
        {
            _statement_list.subnodes.Add((statement)((ArrayList)ar_main[i])[1]);
            procedure_call _exit = new procedure_call(new ident("exit") as addressed_value);
            _statement_list.subnodes.Add(_exit);
        }
    ////////////////////////////////////////////////
    _procedure_definition.proc_body = _statement_list;
    parsertools.create_source_context(_procedure_definition, _expression_list, rt);
    procedure_definition pr = lambda(_procedure_definition);
    ///////////////////////////
    /*if (let_func_last.Count > 0)
    {
        ((block)pr.proc_body).defs = new declarations();
        for (int i = 0; i < let_func_last.Count; i++)
            ((block)pr.proc_body).defs.defs.Add((procedure_definition)let_func_last[i]);
        for (int i = 0; i < let_func_last.Count; i++)
            if (let_where_funcs.Count > 0)
                let_where_funcs.RemoveAt(let_where_funcs.Count - 1);
        for (int i = 0; i < let_func_last.Count; i++)
            let_funcs.RemoveAt(let_funcs.Count - 1);
        let_func_last.Clear();
        let_flag.RemoveAt(let_flag.Count - 1);
    }
    else
        if ((let_flag.Count > 0 && _expression_list != null) || let_funcs.Count == 0)
            let_flag.Clear();*/
    if (((ArrayList)let_stack[let_stack.Count - 1]).Count > 0)
    {
        ((block)pr.proc_body).defs = new declarations();
        for (int i = 0; i < ((ArrayList)let_stack[let_stack.Count - 1]).Count; i++)
            ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)let_stack[let_stack.Count - 1])[i]);
        for (int i = 0; i < ((ArrayList)let_stack[let_stack.Count - 1]).Count; i++)
            if (let_where_funcs.Count > 0)
                let_where_funcs.RemoveAt(let_where_funcs.Count - 1);
        for (int i = 0; i < ((ArrayList)let_stack[let_stack.Count - 1]).Count; i++)
            if (let_funcs.Count > 0)
                let_funcs.RemoveAt(let_funcs.Count - 1);
        let_func_last.Clear();
        if (let_flag.Count>0)
            let_flag.RemoveAt(let_flag.Count - 1);
    }
    let_stack.RemoveAt(let_stack.Count - 1);
    ///////////////////////////////////////////////////////////////////
    if (LRParser.GetReductionSyntaxNode(3) != null)
    {
        if (((block)pr.proc_body).defs == null)
            ((block)pr.proc_body).defs = new declarations();
        for (int j = 0; j < ((ArrayList)LRParser.GetReductionSyntaxNode(3)).Count; j++)
            ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)LRParser.GetReductionSyntaxNode(3))[j]);
        ArrayList ar = ((ArrayList)let_where_funcs_main[let_where_funcs_main.Count - 1]).Clone() as ArrayList;
        for (int j = 0; j < ar.Count; j++)
            last_where_funcs.Add(ar[j]);
        let_where_funcs_main.RemoveAt(let_where_funcs_main.Count - 1);
    }
    ///////////////////////////lambda
    if (((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count > 0)
    {
        if (((block)pr.proc_body).defs == null)
            ((block)pr.proc_body).defs = new declarations();
        for (int i = 0; i < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; i++)
            ((block)pr.proc_body).defs.defs.Add((procedure_definition)((ArrayList)lambda_stack[lambda_stack.Count - 1])[i]);
        for (int ii = 0; ii < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; ii++)
            _function_lambda_definitions.RemoveAt(_function_lambda_definitions.Count - 1);
    }
    lambda_stack.RemoveAt(lambda_stack.Count - 1);
    ///////////////////////////
    let_funcs.Add(pr);
    let_where_funcs.Add(pr);
    //let_funcs1.Add(_procedure_definition);
    //_function_lambda_definitions.Add(_procedure_definition);////////////////
    let_fact_params.Add(_procedure_definition.lambda_name);
    return new ident(((ident)LRParser.GetReductionSyntaxNode(0)).name);
}
    case (int)RuleConstants.RULE_GUARD_BODY_LIST:
    //<guard_body_list> ::= <guard_body> <empty>
    {
        ArrayList ar = (ArrayList)LRParser.GetReductionSyntaxNode(0);
        ArrayList ar_main = new ArrayList();
        ar_main.Add(ar);
        return ar_main;
    }
    case (int)RuleConstants.RULE_GUARD_BODY_LIST2:
    //<guard_body_list> ::= <guard_body_list> <guard_body>
    {
        ArrayList ar_main = (ArrayList)LRParser.GetReductionSyntaxNode(0);
        ar_main.Add(LRParser.GetReductionSyntaxNode(1));
        return ar_main;
    }
    case (int)RuleConstants.RULE_GUARD_BODY_TKASSIGN:
    //<guard_body> ::= <guard> 'tkAssign' <body_func>
    {
        ArrayList ar = new ArrayList();
        ar.Add(LRParser.GetReductionSyntaxNode(0));
        ar.Add(LRParser.GetReductionSyntaxNode(2));
        return ar;
    }
    case (int)RuleConstants.RULE_VARIABLE_TKIDENT:
//<variable> ::= 'tkIdent'
{
    if (token_where==1)
        token_where = 2;
    if (((ident)LRParser.GetReductionSyntaxNode(0)).name=="pi")
    {
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.names.Add(idtype1);
        expression_list ell = new expression_list();
        ell.expressions.Add(LRParser.GetReductionSyntaxNode(0) as expression);
        ell.expressions.Add(new string_const("real") as expression);
        named_type_reference ntr = _named_type_reference1;
        new_expr newexpr = new new_expr(ntr, ell, false, null);
        return newexpr;
    }
    else
        return LRParser.GetReductionSyntaxNode(0);
}
    case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKIDENT_TKROUNDCLOSE:
//<variable> ::= 'tkRoundOpen' 'tkIdent' <params_value> 'tkRoundClose'
{
    expression_list el = LRParser.GetReductionSyntaxNode(2) as expression_list;
    ////////////////////////////for curring
    int n = el.expressions.Count;
    int fld_params_count = find_count_params(((ident)LRParser.GetReductionSyntaxNode(1)).name);
    ////////////////////////////
    if (fld_params_count - n > 0)
    {
        expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(2);
        expression_list _params = new expression_list();
        expression_list _params_el = new expression_list();
        for (int i = 0; i < list_params1.Count; i++)
            if (list_params1[i] is ident)
            {
                _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
            }
        for (int i = 1; i <= fld_params_count - n; i++)
            _expression_list.expressions.Add(new ident("$$" + i));
        for (int i = 1; i <= fld_params_count - n; i++)
        {
            _params.expressions.Add(new ident("$$" + i));
            _params_el.expressions.Add(new ident("$$" + i));
        }
        method_call _method_call = new method_call(_expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(1);

        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
        assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

        statement_list _statement_list = new statement_list();
        _statement_list.subnodes.Add(_assign);
        ////////////////////////////
        ident_list i_l = new ident_list();
        for (int i = 1; i <= fld_params_count - n; i++)
            i_l.idents.Add(new ident("$$" + i));
        /////////////////////////////
        formal_parameters _formal_parametres = new formal_parameters();
        for (int i = 0; i < _params.expressions.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_params.expressions[i];
            _ident_list.idents.Add(id);
            named_type_reference _named_type_reference = new named_type_reference();

            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);

            typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
            parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

            _formal_parametres.params_list.Add(_typed_parametres);
        }
        //////////////////////////
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.source_context = idtype1.source_context;
        _named_type_reference1.names.Add(idtype1);
        /////////////////////////////
        lambda_num++;
        function_lambda_definition _procedure_definition = new function_lambda_definition();
        _procedure_definition.formal_parameters = _formal_parametres;
        _procedure_definition.return_type = (type_definition)_named_type_reference1;
        _procedure_definition.ident_list = i_l;
        _procedure_definition.proc_body = null;
        _procedure_definition.parameters = _params_el;
        _procedure_definition.lambda_name = "__lambda__" + lambda_num;
        //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
        object rt = _expression_list;
        _procedure_definition.proc_body = _statement_list;
        _function_lambda_definitions_after.Add(_procedure_definition);
        _function_lambda_definitions_after.Add(((ident)LRParser.GetReductionSyntaxNode(1)).name);////////////////
        last_function_lambda_definitions.Add(_procedure_definition);
        return new ident(_procedure_definition.lambda_name);
    }
    else
    {
        method_call _method_call = null;
        string name = ((ident)LRParser.GetReductionSyntaxNode(1)).name;
        if (name == "cos" || name == "sin" || name == "tan")
        {
            bin_expr b_e = new bin_expr();
            b_e.operation_type = Operators.Plus;
            b_e.left = el.expressions[0];
            named_type_reference _named_type_reference2 = new named_type_reference();
            ident idtype2 = new ident("datatype");
            _named_type_reference2.names.Add(idtype2);
            expression_list ell2 = new expression_list();
            ell2.expressions.Add(new double_const(0.0));
            ell2.expressions.Add(new string_const("real") as expression);
            named_type_reference ntr2 = _named_type_reference2;
            b_e.right = new new_expr(ntr2, ell2, false, null);
            //////////////////////////////////
            dot_node d_n = new dot_node();
            d_n.left = (addressed_value)b_e;
            d_n.right = new ident("ob");
            expression_list el1 = new expression_list();
            el1.expressions.Add(d_n);
            method_call m_c = new method_call(el1);
            m_c.dereferencing_value = new ident("real");
            ///////////////////////////////////
            expression_list el2 = new expression_list();
            el2.expressions.Add(m_c);
            _method_call = new method_call(el2);
            _method_call.dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(1);
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.names.Add(idtype1);
            expression_list ell = new expression_list();
            ell.expressions.Add(_method_call as expression);
            ell.expressions.Add(new string_const("real") as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, ell, false, null);
            return newexpr;
        }
        else
        {
            _method_call = new method_call(el);
            
            if (_method_call is dereference)
            {
                ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(1);
                parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(1), _method_call);
            }
            list_method_calls.Add(_method_call);
            last_list_method_calls.Add(_method_call);
            last_list_method_calls_lambda.Add(_method_call);
            return _method_call;
        }

                                                    }
									}
    //case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKROUNDCLOSE_TKROUNDOPEN_TKROUNDCLOSE:
//<variable> ::= 'tkRoundOpen' <variable> 'tkRoundClose' 'tkRoundOpen' <params_value> 'tkRoundClose'
    case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKROUNDCLOSE:
//<variable> ::= 'tkRoundOpen' <variable> <params_value> 'tkRoundClose'
{
    if (LRParser.GetReductionSyntaxNode(1) is ident)
    {
        expression_list el = LRParser.GetReductionSyntaxNode(2) as expression_list;
        int n = el.expressions.Count;
        int fld_params_count = find_count_params_lambda(((ident)LRParser.GetReductionSyntaxNode(1)).name);
        if (_function_lambda_definitions_after.Count > 0)
        {
            function_lambda_definition fld = (function_lambda_definition)_function_lambda_definitions_after[_function_lambda_definitions_after.Count - 2];
            for (int i = 0; i < fld.formal_parameters.params_list.Count; i++)
                if (!fld.formal_parameters.params_list[i].idents.idents[0].name.Contains("$"))
                    n++;
        }
        ////////////////////////////
        if (fld_params_count - n > 0)
        {
            expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(2);
            expression_list _params = new expression_list();
            expression_list _params_el = new expression_list();
            for (int i = 0; i < list_params1.Count; i++)
                if (list_params1[i] is ident)
                {
                    _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                    _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
                }
            for (int i = 1; i <= fld_params_count - n; i++)
                _expression_list.expressions.Add(new ident("$$" + i));
            for (int i = 1; i <= fld_params_count - n; i++)
            {
                _params.expressions.Add(new ident("$$" + i));
                _params_el.expressions.Add(new ident("$$" + i));
            }
            method_call _method_call = new method_call(_expression_list);
            if (_method_call is dereference)
                ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(1);

            op_type_node _op_type_node = new op_type_node(Operators.Assignment);
            assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

            statement_list _statement_list = new statement_list();
            _statement_list.subnodes.Add(_assign);
            ////////////////////////////
            ident_list i_l = new ident_list();
            for (int i = 1; i <= fld_params_count - n; i++)
                i_l.idents.Add(new ident("$$" + i));
            /////////////////////////////
            formal_parameters _formal_parametres = new formal_parameters();
            for (int i = 0; i < _params.expressions.Count; i++)
            {
                ident_list _ident_list = new ident_list();
                ident id = (ident)_params.expressions[i];
                _ident_list.idents.Add(id);
                named_type_reference _named_type_reference = new named_type_reference();

                ident idtype = new ident("datatype");
                _named_type_reference.names.Add(idtype);

                typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
                parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

                _formal_parametres.params_list.Add(_typed_parametres);
            }
            //////////////////////////
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            /////////////////////////////
            lambda_num++;
            function_lambda_definition _procedure_definition = new function_lambda_definition();
            _procedure_definition.formal_parameters = _formal_parametres;
            _procedure_definition.return_type = (type_definition)_named_type_reference1;
            _procedure_definition.ident_list = i_l;
            _procedure_definition.proc_body = null;
            _procedure_definition.parameters = _params_el;
            _procedure_definition.lambda_name = "__lambda__" + lambda_num;
            //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
            object rt = _expression_list;
            _procedure_definition.proc_body = _statement_list;
            _function_lambda_definitions_after.Add(_procedure_definition);
            _function_lambda_definitions_after.Add(((ident)LRParser.GetReductionSyntaxNode(1)).name);////////////////
            last_function_lambda_definitions.Add(_procedure_definition);
            return new ident(_procedure_definition.lambda_name);
        }
        else
        {
            for (int i = list_params1.Count - 1; i >= 0; i--)
                if (list_params1[i] is ident)
                {
                    el.expressions.Insert(0, (new ident(((ident)list_params1[i]).name)));
                }

            method_call _method_call = new method_call(el);
            if (_method_call is dereference)
            {
                ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(1);
            }
            list_method_calls.Add(_method_call);
            last_list_method_calls.Add(_method_call);
            last_list_method_calls_lambda.Add(_method_call);
            return _method_call;
        }
    }
    else
    {
        if (LRParser.GetReductionSyntaxNode(1) is method_call)
        {
            method_call mc = LRParser.GetReductionSyntaxNode(1) as method_call;
            expression_list el = LRParser.GetReductionSyntaxNode(2) as expression_list;
            expression_list _expression_list = new expression_list();
            for (int i = 0; i < mc.parameters.expressions.Count; i++)
                _expression_list.expressions.Add(mc.parameters.expressions[i]);
            for (int i = 0; i < el.expressions.Count; i++)
                _expression_list.expressions.Add(el.expressions[i]);
            method_call _method_call = new method_call(_expression_list);
            if (_method_call is dereference)
                ((dereference)_method_call).dereferencing_value = (addressed_value)(new ident(((ident)mc.dereferencing_value).name));
            list_method_calls.RemoveAt(list_method_calls.Count - 1);
            list_method_calls.Add(_method_call);
            last_list_method_calls.Add(_method_call);
            last_list_method_calls_lambda.RemoveAt(last_list_method_calls_lambda.Count - 1);
            last_list_method_calls_lambda.Add(_method_call);
            return _method_call;
        }
        else
            return null;
    }
}
    case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE:
//<variable> ::= 'tkRoundtkOpen' 'tkQuote' 'tkIdent' 'tkQuote' <params_value> 'tkRoundClose'
{
    expression_list el = LRParser.GetReductionSyntaxNode(4) as expression_list;
    ////////////////////////////for curring
    int n = el.expressions.Count;
    int fld_params_count = find_count_params(((ident)LRParser.GetReductionSyntaxNode(2)).name);
    ////////////////////////////
    if (fld_params_count - n > 0)
    {
        expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(4);
        expression_list _params = new expression_list();
        expression_list _params_el = new expression_list();
        for (int i = 0; i < list_params1.Count; i++)
            if (list_params1[i] is ident)
            {
                _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
            }
        for (int i = 1; i <= fld_params_count - n; i++)
            _expression_list.expressions.Insert(0,new ident("$$" + i));
        for (int i = 1; i <= fld_params_count - n; i++)
        {
            _params.expressions.Add(new ident("$$" + i));
            _params_el.expressions.Add(new ident("$$" + i));
        }
        method_call _method_call = new method_call(_expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(2);

        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
        assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

        statement_list _statement_list = new statement_list();
        _statement_list.subnodes.Add(_assign);
        ////////////////////////////
        ident_list i_l = new ident_list();
        for (int i = 1; i <= fld_params_count - n; i++)
            i_l.idents.Add(new ident("$$" + i));
        /////////////////////////////
        formal_parameters _formal_parametres = new formal_parameters();
        for (int i = 0; i < _params.expressions.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_params.expressions[i];
            _ident_list.idents.Add(id);
            named_type_reference _named_type_reference = new named_type_reference();

            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);

            typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
            parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

            _formal_parametres.params_list.Add(_typed_parametres);
        }
        //////////////////////////
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.source_context = idtype1.source_context;
        _named_type_reference1.names.Add(idtype1);
        /////////////////////////////
        lambda_num++;
        function_lambda_definition _procedure_definition = new function_lambda_definition();
        _procedure_definition.formal_parameters = _formal_parametres;
        _procedure_definition.return_type = (type_definition)_named_type_reference1;
        _procedure_definition.ident_list = i_l;
        _procedure_definition.proc_body = null;
        _procedure_definition.parameters = _params_el;
        _procedure_definition.lambda_name = "__lambda__" + lambda_num;
        //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
        object rt = _expression_list;
        _procedure_definition.proc_body = _statement_list;
        _function_lambda_definitions_after.Add(_procedure_definition);
        _function_lambda_definitions_after.Add(((ident)LRParser.GetReductionSyntaxNode(2)).name);////////////////
        last_function_lambda_definitions.Add(_procedure_definition);
        return new ident(_procedure_definition.lambda_name);
    }
    else
    {
        method_call _method_call = null;
        string name = ((ident)LRParser.GetReductionSyntaxNode(2)).name;
        _method_call = new method_call(el);
        if (_method_call is dereference)
        {
            ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(2);
            parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(2), _method_call);
        }
        list_method_calls.Add(_method_call);
        last_list_method_calls.Add(_method_call);
        last_list_method_calls_lambda.Add(_method_call);
        return _method_call;
    }
}
    //case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE_TKROUNDOPEN_TKROUNDCLOSE:
//<variable> ::= 'tkRoundOpen' 'tkQuote' 'tkIdent' 'tkQuote' <params_value> 'tkRoundClose' 'tkRoundOpen' <params_value> 'tkRoundClose'
    /*case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE2:
//<variable> ::= 'tkRoundOpen' 'tkQuote' 'tkIdent' 'tkQuote' <params_value> 'tkRoundClose' <params_value>
{
    ////////////////////////////////////////////////////////ident_params
    ident _ident = (ident)LRParser.GetReductionSyntaxNode(2);
    expression_list el = new expression_list();
    el.expressions.Add(((expression_list)LRParser.GetReductionSyntaxNode(6)).expressions[0]);
    el.expressions.Add(((expression_list)LRParser.GetReductionSyntaxNode(4)).expressions[0]);
    ////////////////////////////////////////////////////////
    //expression_list el = LRParser.GetReductionSyntaxNode(2) as expression_list;
    ////////////////////////////for curring
    int n = el.expressions.Count;
    int fld_params_count = find_count_params(_ident.name);
    ////////////////////////////
    if (fld_params_count - n > 0)
    {
        expression_list _expression_list = el;
        expression_list _params = new expression_list();
        expression_list _params_el = new expression_list();
        for (int i = 0; i < list_params1.Count; i++)
            if (list_params1[i] is ident)
            {
                _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
            }
        for (int i = 1; i <= fld_params_count - n; i++)
            _expression_list.expressions.Add(new ident("$$" + i));
        for (int i = 1; i <= fld_params_count - n; i++)
        {
            _params.expressions.Add(new ident("$$" + i));
            _params_el.expressions.Add(new ident("$$" + i));
        }
        method_call _method_call = new method_call(_expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)_ident;

        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
        assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

        statement_list _statement_list = new statement_list();
        _statement_list.subnodes.Add(_assign);
        ////////////////////////////
        ident_list i_l = new ident_list();
        for (int i = 1; i <= fld_params_count - n; i++)
            i_l.idents.Add(new ident("$$" + i));
        /////////////////////////////
        formal_parameters _formal_parametres = new formal_parameters();
        for (int i = 0; i < _params.expressions.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_params.expressions[i];
            _ident_list.idents.Add(id);
            named_type_reference _named_type_reference = new named_type_reference();

            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);

            typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
            parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

            _formal_parametres.params_list.Add(_typed_parametres);
        }
        //////////////////////////
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.source_context = idtype1.source_context;
        _named_type_reference1.names.Add(idtype1);
        /////////////////////////////
        lambda_num++;
        function_lambda_definition _procedure_definition = new function_lambda_definition();
        _procedure_definition.formal_parameters = _formal_parametres;
        _procedure_definition.return_type = (type_definition)_named_type_reference1;
        _procedure_definition.ident_list = i_l;
        _procedure_definition.proc_body = null;
        _procedure_definition.parameters = _params_el;
        _procedure_definition.lambda_name = "__lambda__" + lambda_num;
        //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
        object rt = _expression_list;
        _procedure_definition.proc_body = _statement_list;
        _function_lambda_definitions_after.Add(_procedure_definition);
        _function_lambda_definitions_after.Add(_ident.name);////////////////
        last_function_lambda_definitions.Add(_procedure_definition);
        return new ident(_procedure_definition.lambda_name);
    }
    else
    {
        method_call _method_call = new method_call(el);

        if (_method_call is dereference)
        {
            ((dereference)_method_call).dereferencing_value = (addressed_value)_ident;
            parsertools.create_source_context(_method_call, _ident, _method_call);
        }
        list_method_calls.Add(_method_call);
        last_list_method_calls.Add(_method_call);
        last_list_method_calls_lambda.Add(_method_call);
        return _method_call;

    }
}*/
    /*case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE:
//<variable> ::= 'tkRoundOpen' <params_value> 'tkQuote' 'tkIdent' 'tkQuote' 'tkRoundClose'
{
    expression_list el = LRParser.GetReductionSyntaxNode(1) as expression_list;
    ////////////////////////////for curring
    int n = el.expressions.Count;
    int fld_params_count = find_count_params(((ident)LRParser.GetReductionSyntaxNode(3)).name);
    ////////////////////////////
    if (fld_params_count - n > 0)
    {
        expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(1);
        expression_list _params = new expression_list();
        expression_list _params_el = new expression_list();
        for (int i = 0; i < list_params1.Count; i++)
            if (list_params1[i] is ident)
            {
                _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
            }
        for (int i = 1; i <= fld_params_count - n; i++)
            _expression_list.expressions.Add(new ident("$$" + i));
        for (int i = 1; i <= fld_params_count - n; i++)
        {
            _params.expressions.Add(new ident("$$" + i));
            _params_el.expressions.Add(new ident("$$" + i));
        }
        method_call _method_call = new method_call(_expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(3);

        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
        assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

        statement_list _statement_list = new statement_list();
        _statement_list.subnodes.Add(_assign);
        ////////////////////////////
        ident_list i_l = new ident_list();
        for (int i = 1; i <= fld_params_count - n; i++)
            i_l.idents.Add(new ident("$$" + i));
        /////////////////////////////
        formal_parameters _formal_parametres = new formal_parameters();
        for (int i = 0; i < _params.expressions.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_params.expressions[i];
            _ident_list.idents.Add(id);
            named_type_reference _named_type_reference = new named_type_reference();

            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);

            typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
            parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

            _formal_parametres.params_list.Add(_typed_parametres);
        }
        //////////////////////////
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.source_context = idtype1.source_context;
        _named_type_reference1.names.Add(idtype1);
        /////////////////////////////
        lambda_num++;
        function_lambda_definition _procedure_definition = new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
        object rt = _expression_list;
        _procedure_definition.proc_body = _statement_list;
        _function_lambda_definitions_after.Add(_procedure_definition);
        _function_lambda_definitions_after.Add(((ident)LRParser.GetReductionSyntaxNode(3)).name);////////////////
        last_function_lambda_definitions.Add(_procedure_definition);
        return new ident(_procedure_definition.lambda_name);
    }
    else
    {
        method_call _method_call = null;
        string name = ((ident)LRParser.GetReductionSyntaxNode(3)).name;
        _method_call = new method_call(el);
        if (_method_call is dereference)
        {
            ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(3);
            parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(3), _method_call);
        }
        list_method_calls.Add(_method_call);
        last_list_method_calls.Add(_method_call);
        last_list_method_calls_lambda.Add(_method_call);
        return _method_call;
    }
}
    case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE_TKROUNDOPEN_TKROUNDCLOSE:
//<variable> ::= 'tkRoundOpen' <params_value> 'tkQuote' 'tkIdent' 'tkQuote' 'tkRoundClose' 'tkRoundOpen' <params_value> 'tkRoundClose'
{
    ////////////////////////////////////////////////////////ident_params
    ident _ident = (ident)LRParser.GetReductionSyntaxNode(3);
    expression_list el = new expression_list();
    el.expressions.Add(((expression_list)LRParser.GetReductionSyntaxNode(1)).expressions[0]);
    el.expressions.Add(((expression_list)LRParser.GetReductionSyntaxNode(7)).expressions[0]);
    ////////////////////////////////////////////////////////
    //expression_list el = LRParser.GetReductionSyntaxNode(2) as expression_list;
    ////////////////////////////for curring
    int n = el.expressions.Count;
    int fld_params_count = find_count_params(_ident.name);
    ////////////////////////////
    if (fld_params_count - n > 0)
    {
        expression_list _expression_list = el;
        expression_list _params = new expression_list();
        expression_list _params_el = new expression_list();
        for (int i = 0; i < list_params1.Count; i++)
            if (list_params1[i] is ident)
            {
                _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
            }
        for (int i = 1; i <= fld_params_count - n; i++)
            _expression_list.expressions.Add(new ident("$$" + i));
        for (int i = 1; i <= fld_params_count - n; i++)
        {
            _params.expressions.Add(new ident("$$" + i));
            _params_el.expressions.Add(new ident("$$" + i));
        }
        method_call _method_call = new method_call(_expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)_ident;

        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
        assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

        statement_list _statement_list = new statement_list();
        _statement_list.subnodes.Add(_assign);
        ////////////////////////////
        ident_list i_l = new ident_list();
        for (int i = 1; i <= fld_params_count - n; i++)
            i_l.idents.Add(new ident("$$" + i));
        /////////////////////////////
        formal_parameters _formal_parametres = new formal_parameters();
        for (int i = 0; i < _params.expressions.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_params.expressions[i];
            _ident_list.idents.Add(id);
            named_type_reference _named_type_reference = new named_type_reference();

            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);

            typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
            parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

            _formal_parametres.params_list.Add(_typed_parametres);
        }
        //////////////////////////
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.source_context = idtype1.source_context;
        _named_type_reference1.names.Add(idtype1);
        /////////////////////////////
        lambda_num++;
        function_lambda_definition _procedure_definition = new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
        object rt = _expression_list;
        _procedure_definition.proc_body = _statement_list;
        _function_lambda_definitions_after.Add(_procedure_definition);
        _function_lambda_definitions_after.Add(_ident.name);////////////////
        last_function_lambda_definitions.Add(_procedure_definition);
        return new ident(_procedure_definition.lambda_name);
    }
    else
    {
        method_call _method_call = new method_call(el);

        if (_method_call is dereference)
        {
            ((dereference)_method_call).dereferencing_value = (addressed_value)_ident;
            parsertools.create_source_context(_method_call, _ident, _method_call);
        }
        list_method_calls.Add(_method_call);
        last_list_method_calls.Add(_method_call);
        last_list_method_calls_lambda.Add(_method_call);
        return _method_call;

    }
}*/
    /*case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE:
    //<variable> ::= 'tkRoundOpen' <params_value> 'tkQuote' 'tkIdent' 'tkQuote' <params_value> 'tkRoundClose'
    return null;
    case (int)RuleConstants.RULE_VARIABLE_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE_TKROUNDOPEN_TKROUNDCLOSE:
    //<variable> ::= 'tkRoundOpen' <params_value> 'tkQuote' 'tkIdent' 'tkQuote' <params_value> 'tkRoundClose' 'tkRoundOpen' <params_value> 'tkRoundClose'
    return null;*/
    case (int)RuleConstants.RULE_INFIX_EXPR_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE:
//<infix_expr> ::= 'tkRoundOpen' <simple_expr> 'tkQuote' 'tkIdent' 'tkQuote' <simple_expr> 'tkRoundClose'
{
    ArrayList ar = new ArrayList();
    ar.Add(LRParser.GetReductionSyntaxNode(3));
    ar.Add(LRParser.GetReductionSyntaxNode(1));
    ar.Add(LRParser.GetReductionSyntaxNode(5));
    return ar;
}
    case (int)RuleConstants.RULE_INFIX_EXPR_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE2:
//<infix_expr> ::= 'tkRoundOpen' <simple_expr> 'tkQuote' 'tkIdent' 'tkQuote' 'tkRoundClose'
{
    expression_list el = new expression_list();
    el.expressions.Add((expression)LRParser.GetReductionSyntaxNode(1));
    ////////////////////////////for curring
    int n = el.expressions.Count;
    int fld_params_count = find_count_params(((ident)LRParser.GetReductionSyntaxNode(3)).name);
    ////////////////////////////
    if (fld_params_count - n > 0)
    {
        expression_list _expression_list = new expression_list();
        _expression_list.expressions.Add((expression)LRParser.GetReductionSyntaxNode(1));
        expression_list _params = new expression_list();
        expression_list _params_el = new expression_list();
        for (int i = 0; i < list_params1.Count; i++)
            if (list_params1[i] is ident)
            {
                _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
            }
        for (int i = 1; i <= fld_params_count - n; i++)
            _expression_list.expressions.Add(new ident("$$" + i));
        for (int i = 1; i <= fld_params_count - n; i++)
        {
            _params.expressions.Add(new ident("$$" + i));
            _params_el.expressions.Add(new ident("$$" + i));
        }
        method_call _method_call = new method_call(_expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(3);

        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
        assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

        statement_list _statement_list = new statement_list();
        _statement_list.subnodes.Add(_assign);
        ////////////////////////////
        ident_list i_l = new ident_list();
        for (int i = 1; i <= fld_params_count - n; i++)
            i_l.idents.Add(new ident("$$" + i));
        /////////////////////////////
        formal_parameters _formal_parametres = new formal_parameters();
        for (int i = 0; i < _params.expressions.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_params.expressions[i];
            _ident_list.idents.Add(id);
            named_type_reference _named_type_reference = new named_type_reference();

            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);

            typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
            parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

            _formal_parametres.params_list.Add(_typed_parametres);
        }
        //////////////////////////
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.source_context = idtype1.source_context;
        _named_type_reference1.names.Add(idtype1);
        /////////////////////////////
        lambda_num++;
        function_lambda_definition _procedure_definition = new function_lambda_definition();
        _procedure_definition.formal_parameters = _formal_parametres;
        _procedure_definition.return_type = (type_definition)_named_type_reference1;
        _procedure_definition.ident_list = i_l;
        _procedure_definition.proc_body = null;
        _procedure_definition.parameters = _params_el;
        _procedure_definition.lambda_name = "__lambda__" + lambda_num;
        //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
        object rt = _expression_list;
        _procedure_definition.proc_body = _statement_list;
        _function_lambda_definitions_after.Add(_procedure_definition);
        _function_lambda_definitions_after.Add(((ident)LRParser.GetReductionSyntaxNode(3)).name);////////////////
        last_function_lambda_definitions.Add(_procedure_definition);
        return new ident(_procedure_definition.lambda_name);
    }
    else
    {
        method_call _method_call = null;
        string name = ((ident)LRParser.GetReductionSyntaxNode(3)).name;
        _method_call = new method_call(el);
        if (_method_call is dereference)
        {
            ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(3);
            parsertools.create_source_context(_method_call, LRParser.GetReductionSyntaxNode(3), _method_call);
        }
        list_method_calls.Add(_method_call);
        last_list_method_calls.Add(_method_call);
        last_list_method_calls_lambda.Add(_method_call);
        return _method_call;
    }
}
    //case (int)RuleConstants.RULE_INFIX_EXPR_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE_TKROUNDOPEN_TKROUNDCLOSE:
//<infix_expr> ::= 'tkRoundOpen' <simple_expr> 'tkQuote' 'tkIdent' 'tkQuote' 'tkRoundClose' 'tkRoundOpen' <params_value> 'tkRoundClose'
    //case (int)RuleConstants.RULE_INFIX_EXPR_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE3:
//<infix_expr> ::= 'tkRoundOpen' <simple_expr> 'tkQuote' 'tkIdent' 'tkQuote' 'tkRoundClose' <params_value>
    case (int)RuleConstants.RULE_INFIX_EXPR_TKROUNDOPEN_TKROUNDOPEN_TKQUOTE_TKIDENT_TKQUOTE_TKROUNDCLOSE_TKROUNDCLOSE:
//<infix_expr> ::= 'tkRoundOpen' 'tkRoundOpen' <simple_expr> 'tkQuote' 'tkIdent' 'tkQuote' 'tkRoundClose' <params_value> 'tkRoundClose'
{
    ////////////////////////////////////////////////////////ident_params
    ident _ident = (ident)LRParser.GetReductionSyntaxNode(4);
    expression_list el = new expression_list();
    el.expressions.Add((expression)LRParser.GetReductionSyntaxNode(2));
    el.expressions.Add(((expression_list)LRParser.GetReductionSyntaxNode(7)).expressions[0]);
    ////////////////////////////////////////////////////////
    //expression_list el = LRParser.GetReductionSyntaxNode(2) as expression_list;
    ////////////////////////////for curring
    int n = el.expressions.Count;
    int fld_params_count = find_count_params(_ident.name);
    ////////////////////////////
    if (fld_params_count - n > 0)
    {
        expression_list _expression_list = el;
        expression_list _params = new expression_list();
        expression_list _params_el = new expression_list();
        for (int i = 0; i < list_params1.Count; i++)
            if (list_params1[i] is ident)
            {
                _params.expressions.Add(new ident(((ident)list_params1[i]).name));
                _params_el.expressions.Add(new ident(((ident)list_params1[i]).name));
            }
        for (int i = 1; i <= fld_params_count - n; i++)
            _expression_list.expressions.Add(new ident("$$" + i));
        for (int i = 1; i <= fld_params_count - n; i++)
        {
            _params.expressions.Add(new ident("$$" + i));
            _params_el.expressions.Add(new ident("$$" + i));
        }
        method_call _method_call = new method_call(_expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)_ident;

        op_type_node _op_type_node = new op_type_node(Operators.Assignment);
        assign _assign = new assign((addressed_value)new ident("result"), _method_call as expression, _op_type_node.type);

        statement_list _statement_list = new statement_list();
        _statement_list.subnodes.Add(_assign);
        ////////////////////////////
        ident_list i_l = new ident_list();
        for (int i = 1; i <= fld_params_count - n; i++)
            i_l.idents.Add(new ident("$$" + i));
        /////////////////////////////
        formal_parameters _formal_parametres = new formal_parameters();
        for (int i = 0; i < _params.expressions.Count; i++)
        {
            ident_list _ident_list = new ident_list();
            ident id = (ident)_params.expressions[i];
            _ident_list.idents.Add(id);
            named_type_reference _named_type_reference = new named_type_reference();

            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);

            typed_parameters _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
            parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);

            _formal_parametres.params_list.Add(_typed_parametres);
        }
        //////////////////////////
        named_type_reference _named_type_reference1 = new named_type_reference();
        ident idtype1 = new ident("datatype");
        _named_type_reference1.source_context = idtype1.source_context;
        _named_type_reference1.names.Add(idtype1);
        /////////////////////////////
        lambda_num++;
        function_lambda_definition _procedure_definition = new function_lambda_definition();
        _procedure_definition.formal_parameters = _formal_parametres;
        _procedure_definition.return_type = (type_definition)_named_type_reference1;
        _procedure_definition.ident_list = i_l;
        _procedure_definition.proc_body = null;
        _procedure_definition.parameters = _params_el;
        _procedure_definition.lambda_name = "__lambda__" + lambda_num;
        //new function_lambda_definition(_formal_parametres, (type_definition)_named_type_reference1, i_l, null, _params_el, "lambda" + lambda_num);
        object rt = _expression_list;
        _procedure_definition.proc_body = _statement_list;
        _function_lambda_definitions_after.Add(_procedure_definition);
        _function_lambda_definitions_after.Add(_ident.name);////////////////
        last_function_lambda_definitions.Add(_procedure_definition);
        return new ident(_procedure_definition.lambda_name);
    }
    else
    {
        method_call _method_call = new method_call(el);

        if (_method_call is dereference)
        {
            ((dereference)_method_call).dereferencing_value = (addressed_value)_ident;
            parsertools.create_source_context(_method_call, _ident, _method_call);
        }
        list_method_calls.Add(_method_call);
        last_list_method_calls.Add(_method_call);
        last_list_method_calls_lambda.Add(_method_call);
        return _method_call;

    }
}
    case (int)RuleConstants.RULE_MULTOP_TKSTAR:
	//<multop> ::= 'tkStar'
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_MULTOP_TKSLASH :
	//<multop> ::= 'tkSlash'
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_ADDOP_TKPLUS :
	//<addop> ::= 'tkPlus'
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_ADDOP_TKMINUS :
	//<addop> ::= 'tkMinus'
return LRParser.GetReductionSyntaxNode(0);
	/*case (int)RuleConstants.RULE_STMT_TKPRINT :
	//<stmt> ::= 'tkPrint' <expr>
{
	if (!(LRParser.GetReductionSyntaxNode(1) is function_lambda_call))
    {
        dot_node _dot_node = new dot_node(null, (addressed_value)(new ident("print")));
        _dot_node.left = (addressed_value)LRParser.GetReductionSyntaxNode(1);
        object o = null;
        method_call _method_call = new method_call(o as expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
        procedure_call _procedure_call = new procedure_call(_method_call as addressed_value);
        return _procedure_call;
    }
    else
    {
        function_lambda_call flc = LRParser.GetReductionSyntaxNode(1) as function_lambda_call;
        method_call _method_call1 = new SyntaxTree.method_call(flc.parameters);
        ((dereference)_method_call1).dereferencing_value = (addressed_value)(new ident(flc.f_lambda_def.lambda_name));
        
        dot_node _dot_node = new dot_node(null, (addressed_value)(new ident("print")));
        _dot_node.left = (addressed_value)_method_call1;
        object o = null;
        method_call _method_call = new method_call(o as expression_list);
        if (_method_call is dereference)
            ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;
        procedure_call _procedure_call = new procedure_call(_method_call as addressed_value);
        return _procedure_call;
    }
}*/
    case (int)RuleConstants.RULE_STMT_TKIDENT_TKARROWGEN_TKIDENT:
//<stmt> ::= 'tkIdent' 'tkArrowGen' 'tkIdent'
{
    named_type_reference _named_type_reference1 = new named_type_reference();
    ident idtype1 = new ident("datatype");
    _named_type_reference1.source_context = idtype1.source_context;
    _named_type_reference1.names.Add(idtype1);
    ident_list il = new ident_list();
    il.idents.Add((ident)LRParser.GetReductionSyntaxNode(0));
    ////////////////////////////////////////
    named_type_reference _named_type_reference2 = new named_type_reference();
    _named_type_reference2.names.Add(new SyntaxTree.ident("datatype"));
    expression_list ell = new expression_list();
                 ////////////////////////////////////////
    dot_node _dot_node = new dot_node(null, (addressed_value)LRParser.GetReductionSyntaxNode(2)/*(new ident("getChar"))*/);
    /////*****************
    named_type_reference _named_type_reference3 = new named_type_reference();
    _named_type_reference3.names.Add(new SyntaxTree.ident("datatype"));
    expression_list ell3 = new expression_list();
    ell3.expressions.Add(new string_const("$null"));
    ell3.expressions.Add(new string_const("string") as expression);
    named_type_reference ntr3 = _named_type_reference2;
    new_expr ne3= new new_expr(ntr3, ell3, false, null);
    /////*****************
    _dot_node.left = (addressed_value)ne3;
    object o = null;
    method_call _method_call = new method_call(o as expression_list);
    if (_method_call is dereference)
        ((dereference)_method_call).dereferencing_value = (addressed_value)_dot_node;//LRParser.GetReductionSyntaxNode(2);
                  /////////////////////////////////
    /*ell.expressions.Add(_method_call);
    ell.expressions.Add(new string_const("string") as expression);
    named_type_reference ntr = _named_type_reference2;
    new_expr ne = new new_expr(ntr, ell, false, null);*/
    ////////////////////////////////////////
    var_def_statement _var_def_statement = new var_def_statement(il, (type_definition)_named_type_reference1, _method_call, definition_attribute.None, false);
    var_statement _var_statement = new var_statement(_var_def_statement);
    
    return _var_statement;
}
    case (int)RuleConstants.RULE_STMT_TKIF_TKTHEN_TKELSE:
	//<stmt> ::= 'tkIf' <expr> 'tkThen' <body_func> 'tkElse' <body_func>
{
            								if_node _if_node = new if_node(null, (statement)LRParser.GetReductionSyntaxNode(3), (statement)LRParser.GetReductionSyntaxNode(5));
            								parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(4), parsertools.sc_not_null(LRParser.GetReductionSyntaxNode(5), LRParser.GetReductionSyntaxNode(4)));
            
            								_if_node.condition = _ob((expression)LRParser.GetReductionSyntaxNode(1));
            								parsertools.create_source_context(_if_node, LRParser.GetReductionSyntaxNode(0), _if_node);
            								statement_list sl = new statement_list();
                                            			sl.subnodes.Add(_if_node);
                                            			return sl;
        								}
	case (int)RuleConstants.RULE_STMT_TKCASE_TKROUNDOPEN_TKROUNDCLOSE_TKOF :
	//<stmt> ::= 'tkCase' 'tkRoundOpen' <params1> 'tkRoundClose' 'tkOf' <case_variants>
return null;
    case (int)RuleConstants.RULE_STMT_TKDO_TKFIGUREOPEN_TKSEMICOLON_TKFIGURECLOSE :
	//<stmt> ::= 'tkDo' 'tkFigureOpen' <stmts> 'tkSemiColon' 'tkFigureClose'
return LRParser.GetReductionSyntaxNode(2);
    case (int)RuleConstants.RULE_STMT_TKDO:
//<stmt> ::= 'tkDo' <stmts1>
{
    return LRParser.GetReductionSyntaxNode(1);
}
	case (int)RuleConstants.RULE_STMT_TKRETURN :
	//<stmt> ::= 'tkReturn' <expr>
{
												statement_list _statement_list = new statement_list();

            										ident id = new ident("result");
            										op_type_node _op_type_node = new op_type_node(Operators.Assignment);
            										_op_type_node.source_context = parsertools.GetTokenSourceContext();

            										assign _assign = new assign((addressed_value)id, LRParser.GetReductionSyntaxNode(1) as expression, _op_type_node.type);
            										parsertools.create_source_context(_assign, id, LRParser.GetReductionSyntaxNode(1));
            
            										_statement_list.subnodes.Add((statement)_assign);
            										parsertools.assign_source_context(_statement_list, _assign);
            										return _statement_list;
										}
	case (int)RuleConstants.RULE_STMT :
	//<stmt> ::= <func_call>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_CASE_VARIANTS :
	//<case_variants> ::= <case_variant> <empty>
return LRParser.GetReductionSyntaxNode(0);
    case (int)RuleConstants.RULE_CASE_VARIANTS_TKSPLIT:
//<case_variants> ::= <case_variants> tkSplit <case_variant>
    return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_CASE_VARIANT_TKROUNDOPEN_TKROUNDCLOSE_TKARROW :
	//<case_variant> ::= 'tkRoundOpen' <params1> 'tkRoundClose' 'tkArrow' <body_func>
{
    												param_value_list.Add(LRParser.GetReductionSyntaxNode(1));
        											body_variant_list.Add(LRParser.GetReductionSyntaxNode(4));
    												return null;
											}
    case (int)RuleConstants.RULE_PARAMS1:
//<params1> ::= <param> <empty>
{
    //let_flag.Add(1);
    bool b = false;
    if (list_param.Count == 1)
    {
        list_params_temp.Add(new ArrayList());
        let_where_list_params.Add(new ArrayList());//
        if (list_param[0] is new_expr && ((string_const)((new_expr)list_param[0]).params_list.expressions[1]).Value == "empty")
            b = true;
        list_param.Clear();
    }
    else
    {
        list_params_temp.Add(list_param.Clone());
        let_where_list_params.Add(list_param.Clone());//
    }
    expression_list _expression_list = new expression_list();
    if (list_param.Count == 0)
    {
        if (b)
        {
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            el.expressions.Add(new int32_const(0));
            literal lt;
            string text = "empty_list";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            _expression_list.expressions.Add(newexpr);
        }
        else
        {
            _expression_list.source_context = ((expression)LRParser.GetReductionSyntaxNode(0)).source_context;
            _expression_list.expressions.Add((expression)LRParser.GetReductionSyntaxNode(0));
        }
    }
    else
    {
        ident id = new ident();
        for (int i = 0; i < list_param.Count; i++)
        {
            if (list_param[i] is ident)
                id.name += ((ident)list_param[i]).name;
            else
            {
                errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "идентификатор"));
                return null;
            }
        }
        _expression_list.source_context = ((expression)id).source_context;
        _expression_list.expressions.Add((expression)id);
        list_param.Clear();
    }
    list_params1.Clear();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
        list_params1.Add(_expression_list.expressions[i]);
    last_list_method_calls_lambda.Clear();
    return _expression_list;
}
    case (int)RuleConstants.RULE_PARAMS1_TKCOMMA:
//<params1> ::= <params1> 'tkComma' <param>
{
    bool b = false;
    if (list_param.Count == 1)
    {
        list_params_temp.Add(new ArrayList());
        let_where_list_params.Add(new ArrayList());//
        if (list_param[0] is new_expr && ((string_const)((new_expr)list_param[0]).params_list.expressions[1]).Value == "empty")
            b = true;
        list_param.Clear();
    }
    else
    {
        list_params_temp.Add(list_param.Clone());
        let_where_list_params.Add(list_param.Clone());//
    }
    expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(0);
    if (list_param.Count == 0)
    {
        if (!b)
        {
            _expression_list.expressions.Add(LRParser.GetReductionSyntaxNode(2) as expression);
        }
        else
        {
            named_type_reference _named_type_reference1 = new named_type_reference();
            ident idtype1 = new ident("datatype");
            _named_type_reference1.source_context = idtype1.source_context;
            _named_type_reference1.names.Add(idtype1);
            expression_list el = new expression_list();
            el.expressions.Add(new int32_const(0));
            literal lt;
            string text = "empty_list";
            lt = new string_const(text);
            el.expressions.Add(lt as expression);
            named_type_reference ntr = _named_type_reference1;
            new_expr newexpr = new new_expr(ntr, el, false, null);
            _expression_list.expressions.Add(newexpr);
        }
    }
    else
    {
        ident id = new ident();
        for (int i = 0; i < list_param.Count; i++)
        {
            if (list_param[i] is ident)
                id.name += ((ident)list_param[i]).name;
            else
            {
                errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "идентификатор"));
                return null;
            }
        }
        _expression_list.expressions.Add((expression)id);
        list_param.Clear();
    }
    list_params1.Clear();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
        list_params1.Add(_expression_list.expressions[i]);
    last_list_method_calls_lambda.Clear();
    return _expression_list;
}
	
	case (int)RuleConstants.RULE_FUNC_CALL :
	//<func_call> ::= <expr> <empty>
{
            										statement_list _statement_list = new statement_list();

            										ident id = new ident("result");
            										op_type_node _op_type_node = new op_type_node(Operators.Assignment);
            										_op_type_node.source_context = parsertools.GetTokenSourceContext();
                                                    expression from = (expression)LRParser.GetReductionSyntaxNode(0);
                                                    if (LRParser.GetReductionSyntaxNode(0) is ident && 
                                                        (find_func_name(((ident)LRParser.GetReductionSyntaxNode(0)).name) || find_count_params_lambda(((ident)LRParser.GetReductionSyntaxNode(0)).name) >= 0))
                                                    {
                                                        //expression_list el = LRParser.GetReductionSyntaxNode(2) as expression_list;
                                                        //int n = el.expressions.Count;
                                                        expression_list el = new expression_list();
                                                        int fld_params_count = 0;
                                                        if (find_func_name(((ident)LRParser.GetReductionSyntaxNode(0)).name))
                                                            fld_params_count = find_count_params(((ident)LRParser.GetReductionSyntaxNode(0)).name);
                                                        else
                                                            fld_params_count = find_count_params_lambda(((ident)LRParser.GetReductionSyntaxNode(0)).name);
                                                        if (fld_params_count != 0)
                                                            for (int i = 0; i < fld_params_count; i++)
                                                            {
                                                                string param_name = find_name_params_lambda(((ident)LRParser.GetReductionSyntaxNode(0)).name, i);
                                                                if (param_name.Contains("$"))
                                                                {
                                                                    named_type_reference _named_type_reference1 = new named_type_reference();
                                                                    _named_type_reference1.names.Add(new SyntaxTree.ident("datatype"));
                                                                    expression_list ell = new expression_list();
                                                                    ell.expressions.Add(new string_const("$null") as expression);
                                                                    ell.expressions.Add(new string_const("string") as expression);
                                                                    named_type_reference ntr = _named_type_reference1;
                                                                    new_expr newexpr = new new_expr(ntr, ell, false, null);
                                                                    el.expressions.Add(newexpr);
                                                                }
                                                                else
                                                                {
                                                                    el.expressions.Add(new ident(param_name));
                                                                }
                                                            }
                                                        method_call _method_call = new method_call(el);
                                                        
                                                        if (_method_call is dereference)
                                                            ((dereference)_method_call).dereferencing_value = (addressed_value)LRParser.GetReductionSyntaxNode(0);
                                                        from = _method_call;
                                                    }
                                                    if (LRParser.GetReductionSyntaxNode(0) is ident)
                                                    {
                                                        function_lambda_definition fld = find_func_lambda_name(((ident)LRParser.GetReductionSyntaxNode(0)).name);
                                                        if (fld != null)
                                                        {
                                                            expression_list _expression_list1 = new expression_list();
                                                            function_lambda_call _lambda_call = new function_lambda_call(fld, _expression_list1);
                                                            from = _lambda_call;
                                                        }
                                                    }

            										assign _assign = new assign((addressed_value)id, from, _op_type_node.type);
            										parsertools.create_source_context(_assign, id, LRParser.GetReductionSyntaxNode(0));
            
            										_statement_list.subnodes.Add((statement)_assign);
            										parsertools.assign_source_context(_statement_list, _assign);
                                                    ////////////////////////////
                                                    if (LRParser.GetReductionSyntaxNode(0) is ident)
                                                    {
                                                        list_return_funcs.Add(find_count_params(((ident)LRParser.GetReductionSyntaxNode(0)).name));
                                                    }
                                                    ////////////////////////////
            										return _statement_list;
							}
	case (int)RuleConstants.RULE_PARAMS_VALUE :
	//<params_value> ::= <param_value> <empty>
{
            						expression_list _expression_list = new expression_list();
                                    if (LRParser.GetReductionSyntaxNode(0) != null)
                                        _expression_list.expressions.Add((expression)LRParser.GetReductionSyntaxNode(0));
                                    else
                                        _expression_list.expressions.Add(null);
                                    return _expression_list;
        						}
	case (int)RuleConstants.RULE_PARAMS_VALUE2 :
	//<params_value> ::= <params_value> <param_value>
{
            expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(0);
            parsertools.create_source_context(_expression_list, _expression_list, LRParser.GetReductionSyntaxNode(1));
            _expression_list.expressions.Add(LRParser.GetReductionSyntaxNode(1) as expression);
            return _expression_list;
        }
    case (int)RuleConstants.RULE_PARAM_VALUE:
//<param_value> ::= <expr> <empty>
return LRParser.GetReductionSyntaxNode(0);
	case (int)RuleConstants.RULE_LAMBDA_FUNC_TKLEFTSLASH_TKARROW :
	//<lambda_func> ::= 'tkLeftSlash' <params> 'tkArrow' <body_func>

{
    expression_list _expression_list = (expression_list)LRParser.GetReductionSyntaxNode(1);
    statement_list _statement_list = (statement_list)LRParser.GetReductionSyntaxNode(3);
    ////////////////////////////
    ident_list i_l = new ident_list();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
        i_l.idents.Add((ident)_expression_list.expressions[i]);
    /////////////////////////////
    formal_parameters _formal_parametres = new formal_parameters();
    for (int i = 0; i < _expression_list.expressions.Count; i++)
    {
        ident_list _ident_list = new ident_list();
        ident id = (ident)_expression_list.expressions[i];
        _ident_list.idents.Add(id);
        string name_param = id.name;
        typed_parameters _typed_parametres = null;
        int k = 0;
        while (k < last_list_method_calls_lambda.Count && ((ident)((method_call)last_list_method_calls_lambda[k]).dereferencing_value).name != name_param)
            k++;
        if (k < last_list_method_calls_lambda.Count)
            _typed_parametres = new typed_parameters(_ident_list, func_type(((method_call)last_list_method_calls_lambda[k]).parameters.expressions.Count), parametr_kind.none, null);
        else
        {
            named_type_reference _named_type_reference = new named_type_reference();

            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);

            _typed_parametres = new typed_parameters(_ident_list, (type_definition)_named_type_reference, parametr_kind.none, null);
            parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference);
        }
        _formal_parametres.params_list.Add(_typed_parametres);
    }
    //////////////////////////
    named_type_reference _named_type_reference1 = new named_type_reference();
    ident idtype1 = new ident("datatype");
    _named_type_reference1.source_context = idtype1.source_context;
    _named_type_reference1.names.Add(idtype1);
    /////////////////////////////
    lambda_num++;
    function_lambda_definition _procedure_definition = new function_lambda_definition();
    _procedure_definition.formal_parameters = _formal_parametres;
    _procedure_definition.return_type = (type_definition)_named_type_reference1;
    _procedure_definition.ident_list = i_l;
    _procedure_definition.proc_body = null;
    _procedure_definition.parameters = _expression_list;
    _procedure_definition.lambda_name = "__lambda__" + lambda_num;
    //new function_lambda_definition(_formal_parametres,(type_definition)_named_type_reference1,i_l, null,_expression_list, "lambda"+lambda_num);
    object rt = _expression_list;
    _procedure_definition.proc_body = _statement_list;
    //////////////////////let & where
    if (let_stack.Count>0 && ((ArrayList)let_stack[let_stack.Count - 1]).Count > 0)
    {
        _procedure_definition.defs = new List<object>();
        for (int i = 0; i < ((ArrayList)let_stack[let_stack.Count - 1]).Count; i++)
            _procedure_definition.defs.Add((procedure_definition)((ArrayList)let_stack[let_stack.Count - 1])[i]);
        if (let_where_funcs_main.Count + 1 > token_where_count)
        {
            for (int i = 0; i < last_where_funcs.Count; i++)
                //if (((procedure_definition)last_where_funcs[i]).proc_header.name.meth_name.name.Contains("lambda"))
                _procedure_definition.defs.Add((procedure_definition)last_where_funcs[i]);
            for (int i = 0; i < last_where_funcs.Count; i++)
                if (let_funcs.Count > 0)
                    let_funcs.RemoveAt(let_funcs.Count - 1);
            last_where_funcs.Clear();
        }
        for (int i = 0; i < ((ArrayList)let_stack[let_stack.Count - 1]).Count; i++)
            if (let_where_funcs.Count > 0)
                let_where_funcs.RemoveAt(let_where_funcs.Count - 1);
        for (int i = 0; i < ((ArrayList)let_stack[let_stack.Count - 1]).Count; i++)
            if (let_funcs.Count > 0)
                let_funcs.RemoveAt(let_funcs.Count - 1);
        let_func_last.Clear();
        if (let_flag.Count > 0)
            let_flag.RemoveAt(let_flag.Count - 1);
    }
    if (let_stack.Count>0)
        let_stack.RemoveAt(let_stack.Count - 1);
    /*if (let_where_funcs.Count > 0)
    {
        _procedure_definition.defs = new ArrayList();
        for (int i = 0; i < let_where_funcs.Count; i++)
            if (((procedure_definition)let_where_funcs[i]).proc_header.name.meth_name.name.Contains("lambda"))
                _procedure_definition.defs.Add(let_where_funcs[i]);
        if (let_where_funcs_main.Count + 1 > token_where_count)
        {
            for (int i = 0; i < last_where_funcs.Count; i++)
                //if (((procedure_definition)last_where_funcs[i]).proc_header.name.meth_name.name.Contains("lambda"))
                    _procedure_definition.defs.Add((procedure_definition)last_where_funcs[i]);
            for (int i = 0; i < last_where_funcs.Count; i++)
                if (let_funcs.Count > 0)
                    let_funcs.RemoveAt(let_funcs.Count - 1);
            last_where_funcs.Clear();
        }
        int j=0;
        while (j < let_where_funcs.Count)
            if (((procedure_definition)let_where_funcs[j]).proc_header.name.meth_name.name.Contains("lambda"))
                let_where_funcs.RemoveAt(j);
            else
                j++;
        //let_where_funcs.Clear();
        let_func_last.Clear();
        let_flag.Clear();
    }*/
    //////////////////////
    parsertools.create_source_context(_procedure_definition, _expression_list, rt);
    _function_lambda_definitions.Add(_procedure_definition);////////////////
    if (lambda_stack.Count > 0)
    {
        if (((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count > 0)
        {
            if (_procedure_definition.defs == null)
                _procedure_definition.defs = new List<object>();
            for (int i = 0; i < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; i++)
            {
                _procedure_definition.defs.Add((procedure_definition)((ArrayList)lambda_stack[lambda_stack.Count - 1])[i]);
                int j = 0;
                while (j < _function_lambda_definitions.Count && ((function_lambda_definition)_function_lambda_definitions[j]).lambda_name !=
                        ((procedure_definition)((ArrayList)lambda_stack[lambda_stack.Count - 1])[i]).proc_header.name.meth_name.name)
                    j++;
                if (j < _function_lambda_definitions.Count)
                    _function_lambda_definitions.RemoveAt(j);
            }
            //for (int i = 0; i < ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Count; i++)
                //_function_lambda_definitions.RemoveAt(_function_lambda_definitions.Count-1);
            lambda_stack.RemoveAt(lambda_stack.Count - 1);
        }
        if (lambda_stack.Count > 1 && ((ArrayList)lambda_stack[lambda_stack.Count - 2]).Count > 0)
        {
            ((ArrayList)lambda_stack[lambda_stack.Count - 2]).Add(lambda(_procedure_definition));
            lambda_stack.RemoveAt(lambda_stack.Count - 1);
        }
        else
            ((ArrayList)lambda_stack[lambda_stack.Count - 1]).Add(lambda(_procedure_definition));
    }
    //lambda_funcs.Add(_procedure_definition);

    //let_funcs.Add(lambda(_procedure_definition));
    //let_where_funcs.Add(lambda(_procedure_definition));

    return new ident(_procedure_definition.lambda_name);
}
	case (int)RuleConstants.RULE_EMPTY :
	//<empty> ::= 
	//NONTERMINAL:<empty> ::= 
	return null;
	//ENDNONTERMINAL
}
throw new RuleException("Unknown rule");
}  
        private void SubstituteForLoopVariables()
        {
            var forScopes =
                _capturedVarsTreeNodesDictionary.Where(n => n.Value is CapturedVariablesTreeNodeForScope)
                                                .Select(n => (CapturedVariablesTreeNodeForScope) n.Value)
                                                .ToList();

            foreach (var forScope in forScopes)
            {
                var forNode = forScope.CorrespondingSyntaxTreeNode as for_node;
                if (forNode != null)
                {
                    CapturedVariablesSubstitutionClassGenerator.ScopeClassDefinition generatedClass;
                    if (_generatedScopeClassesInfo.TryGetValue(forScope.ScopeIndex, out generatedClass))
                    {
                        var nodesToAdd = new List<statement>();
                        var enclosedStatementList = (statement_list) forScope.EnclosedUpperBlockScope.CorrespondingSyntaxTreeNode;
                        nodesToAdd.Add(generatedClass.GeneratedVarStatementForScope);
                        if (generatedClass.AssignNodeForUpperClassFieldInitialization != null)
                        {
                            nodesToAdd.Add(generatedClass.AssignNodeForUpperClassFieldInitialization);
                        }

                        var forNodeIndex = enclosedStatementList.subnodes.FindIndex(stmt => stmt == forNode);
                        enclosedStatementList.subnodes.InsertRange(forNodeIndex, nodesToAdd);


                        var substDotNode = new dot_node(new ident(generatedClass.GeneratedSubstitutingFieldName), new ident(forNode.loop_variable.name));
                        var assignNode = new assign(substDotNode, new ident(forNode.loop_variable.name));    // TODO: SourceContexts!!!!!
                        ((statement_list)forNode.statements).subnodes.Insert(0, assignNode); 
                    }
                    else
                    {
                        var si = forScope.SymbolInfoLoopVar;
                        var scopeWhereVarDefined = _capturedVarsTreeNodesDictionary[si.scope.ScopeNum];
                        var idRef = scopeWhereVarDefined
                            .VariablesDefinedInScope
                            .Find(var => var.SymbolInfo == si);                                                 //TODO: !!!!!!!!!!!!!!!!!!!!!!

                        var substKey = new SubstitutionKey(forNode.loop_variable.name, idRef.SyntaxTreeNodeWithVarDeclaration, forNode); 

                        if (_substitutionsInfo.ContainsKey(substKey)) // Если нашли замену, то переменная где-то захватывалась
                        {
                            forNode.create_loop_variable = true;
                            var substDotNode = _substitutionsInfo[substKey];

                            var assignNode = new assign(substDotNode, new ident(forNode.loop_variable.name));    // TODO: SourceContexts!!!!!
                            (((statement_list)forNode.statements).subnodes).Insert(0, assignNode);
                        }
                    }

                }
            }
        }
        private void SubstituteForEachLoopVariables()
        {
            var forEachScopes =
                _capturedVarsTreeNodesDictionary.Where(n => n.Value is CapturedVariablesTreeNodeForEachScope)
                                                .Select(n => (CapturedVariablesTreeNodeForEachScope)n.Value)
                                                .ToList();

            foreach (var forEachScope in forEachScopes)
            {
                var forEachNode = forEachScope.CorrespondingSyntaxTreeNode as foreach_stmt;
                if (forEachNode != null)
                {
                    CapturedVariablesSubstitutionClassGenerator.ScopeClassDefinition generatedClass;
                    if (_generatedScopeClassesInfo.TryGetValue(forEachScope.ScopeIndex, out generatedClass))
                    {
                        var nodesToAdd = new List<statement>();
                        var bodyStmtList = (statement_list)forEachNode.stmt;
                        nodesToAdd.Add(generatedClass.GeneratedVarStatementForScope);
                        if (generatedClass.AssignNodeForUpperClassFieldInitialization != null)
                        {
                            nodesToAdd.Add(generatedClass.AssignNodeForUpperClassFieldInitialization);
                        }

                        var substDotNode = new dot_node(new ident(generatedClass.GeneratedSubstitutingFieldName), new ident(forEachNode.identifier.name));
                        var assignNode = new assign(substDotNode, new ident(forEachNode.identifier.name));    // TODO: SourceContexts!!!!!
                        nodesToAdd.Add(assignNode);

                        bodyStmtList.subnodes.InsertRange(0, nodesToAdd);
                    }
                    else
                    {
                        var si = forEachScope.SymbolInfoLoopVar;
                        var scopeWhereVarDefined = _capturedVarsTreeNodesDictionary[si.scope.ScopeNum];
                        var idRef = scopeWhereVarDefined
                            .VariablesDefinedInScope
                            .Find(var => var.SymbolInfo == si);                                                 //TODO: !!!!!!!!!!!!!!!!!!!!!!

                        var substKey = new SubstitutionKey(forEachNode.identifier.name, idRef.SyntaxTreeNodeWithVarDeclaration, forEachNode);

                        if (_substitutionsInfo.ContainsKey(substKey)) // Если нашли замену, то переменная где-то захватывалась
                        {
                            if (forEachNode.type_name == null)  //Нужно, чтобы переменная цикла создалась в этом случае в контескте с этим же именем что и была
                            {
                                forEachNode.type_name = new no_type_foreach();
                            }

                            var substDotNode = _substitutionsInfo[substKey];

                            var assignNode = new assign(substDotNode, new ident(forEachNode.identifier.name));    // TODO: SourceContexts!!!!!
                            (((statement_list)forEachNode.stmt).subnodes).Insert(0, assignNode);
                        }
                    }

                }
            }
        }
示例#12
0
		public override void visit(dot_node _dot_node)
		{
			bool tmp = by_dot;
			by_dot = true;
			bool tmp2 = search_all;
			search_all = false;
			_dot_node.left.visit(this);
			search_all = tmp2;
			by_dot = tmp;
			if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcScope)
			{
				if (((returned_scope as ElementScope).sc as ProcScope).return_type != null) 
					returned_scope = new ElementScope(((returned_scope as ElementScope).sc as ProcScope).return_type);
				else 
					returned_scope = null;
			}
			else if (returned_scope != null && returned_scope is ProcScope)
			{
				if ((returned_scope as ProcScope).return_type == null) 
				{
					returned_scope = null;
				}
				else 
					returned_scope = new ElementScope((returned_scope as ProcScope).return_type);
			}
			else if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcType)
			{
				TypeScope ts = ((returned_scope as ElementScope).sc as ProcType).target.return_type;
				if (ts != null)
					returned_scope = new ElementScope(ts);
			}
			
			if (returned_scope != null)
			{
                if (!search_all)
                {
                    SymScope left_scope = returned_scope;

                    if (_dot_node.right is ident)
                    {
                        SymScope tmp_tn = returned_scope;
                        returned_scope = returned_scope.FindNameOnlyInType((_dot_node.right as ident).name);
                        if (returned_scope != null && returned_scope is ElementScope)
                        {
                            if (left_scope is ElementScope)
                                returned_scope = CheckForAccess(left_scope as ElementScope, returned_scope as ElementScope);
                            else if (left_scope is TypeScope)
                                returned_scope = CheckForAccess(left_scope as TypeScope, returned_scope as ElementScope);
                            return;
                        }
                        if (returned_scope != null && returned_scope is ProcScope && (returned_scope as ProcScope).return_type != null)
                        {
                            CompiledMethodScope tmp_sc = returned_scope as CompiledMethodScope;
                            returned_scope = new ElementScope(returned_scope as ProcScope);
                            if (tmp_sc != null)
                                returned_scope.topScope = tmp_sc.topScope;
                            if (left_scope is ElementScope)
                                returned_scope = CheckForAccess(left_scope as ElementScope, returned_scope as ElementScope);
                            else if (left_scope is TypeScope)
                                returned_scope = CheckForAccess(left_scope as TypeScope, returned_scope as ElementScope);
                            return;
                        }
                        if (tmp_tn is ElementScope && stv != null)
                        {
                            List<ProcScope> procs = stv.entry_scope.GetExtensionMethods((_dot_node.right as ident).name, (tmp_tn as ElementScope).sc as TypeScope);
                            if (procs.Count > 0)
                            {
                                foreach (ProcScope ps in procs)
                                {
                                    if (ps.parameters.Count == 0 || ps.parameters.Count == 1 && ps.is_extension && string.Compare(ps.parameters[0].Name,"self", true) == 0)
                                    {
                                        returned_scope = ps;
                                        return;
                                    }
                                }
                                returned_scope = procs[0];
                                return;
                            }
                        }
                    }
                }
                else
                {
                    SymScope left_scope = returned_scope;
                    returned_scopes = returned_scope.FindOverloadNamesOnlyInType((_dot_node.right as ident).name);
                    List<int> to_remove = new List<int>();
                    for (int i = 0; i < returned_scopes.Count; i++)
                    {
                        if (returned_scopes[i] is ElementScope && (returned_scopes[i] as ElementScope).sc is ProcType)
                        {
                            if (left_scope is ElementScope)
                                returned_scopes[i] = CheckForAccess(left_scope as ElementScope, returned_scopes[i] as ElementScope);
                            //if (ret_names[i] != null)
                            //ret_names[i] = ((ret_names[i] as ElementScope).sc as ProcType).target;
                        }
                        else if (left_scope is ElementScope && returned_scopes[i] is ProcScope && (returned_scopes[i] as ProcScope).IsStatic)
                        {
                            returned_scopes[i] = null;
                        }
                    }
                    returned_scopes.RemoveAll(x => x == null);
                    
                    if (returned_scope is ElementScope && stv != null)
                    {
                        List<ProcScope> procs = stv.entry_scope.GetExtensionMethods((_dot_node.right as ident).name,(returned_scope as ElementScope).sc as TypeScope);
                        for (int i = 0; i < procs.Count; i++)
                            returned_scopes.Add(procs[i]);
                    }
                    
                    search_all = false;
                }
			}
		}
		public void read_dot_node(dot_node _dot_node)
		{
			read_addressed_value_funcname(_dot_node);
			_dot_node.left = _read_node() as addressed_value;
			_dot_node.right = _read_node() as addressed_value;
		}
		public void visit(dot_node _dot_node)
		{
			read_dot_node(_dot_node);
		}
示例#15
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public closure_substituting_node(dot_node _substitution,SourceContext sc)
		{
			this._substitution=_substitution;
			source_context = sc;
		}
public method_call _ob(object dt)
    {
        token_info _token_info = new token_info(".");
        _token_info.source_context = parsertools.GetTokenSourceContext();
        ///////////
        ident id = new ident("ob");
        dot_node _dot_node = new dot_node(null, (addressed_value)id);
        parsertools.create_source_context(_dot_node, _token_info, id);
        _dot_node.left = (addressed_value)dt;
        parsertools.create_source_context(_dot_node, dt, _dot_node.right);
        /////////////////////////
        expression_list el = new expression_list();
        el.expressions.Add(_dot_node);
        method_call _method_call = new method_call(el);
        parsertools.create_source_context(_method_call, null, null);
        /////////////////////////
        ident id1 = new ident("boolean");
        /////////////////////////
        if (_method_call is dereference)
        {
            ((dereference)_method_call).dereferencing_value = (addressed_value)id1;
            parsertools.create_source_context(_method_call, id1, _method_call);
        }
        return _method_call;
    }
示例#17
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public closure_substituting_node(string _name,dot_node _substitution)
		{
			this._name=_name;
			this._substitution=_substitution;
		}
public method_call _count(expression dt)
{
    ident id = new ident("count");
    dot_node _dot_node = new dot_node(null, (addressed_value)id);
    _dot_node.left = (addressed_value)dt;
    method_call _method_call = new method_call();
    _method_call.dereferencing_value = _dot_node;
    return _method_call;
}
示例#19
0
        public static procedure_definition BuildToStringFuncForAutoClass(List<ident> names)
        {
            var pal = new procedure_attributes_list(proc_attribute.attr_override);
            var fp = new formal_parameters();
            var ff = new function_header("ToString", "string", fp, pal);

            var cleft = new char_const('(');
            var cright = new char_const(')');
            var ccomma = new char_const(',');
            bin_expr ex = new bin_expr(cleft, cright, Operators.Plus);
            for (var i = 0; i < names.Count; i++)
            { 
                var dn = new dot_node(names[i], new ident("ToString"));
                var asnode = new typecast_node(names[i], new named_type_reference("object"), op_typecast.as_op);
                var eqnode = new bin_expr(asnode, new nil_const(), Operators.Equal);
                var expr = new question_colon_expression(eqnode, new string_const("nil"), dn);
                ex.left = new bin_expr(ex.left, expr, Operators.Plus);
                if (i<names.Count-1)
                    ex.left = new bin_expr(ex.left, ccomma, Operators.Plus);
            }
            var ass = new assign("Result", ex);

            return BuildShortProcFuncDefinitionNoSC(ff, ass);
        }
public method_call _add(expression dt, expression param)
{
     ident id = new ident("add");
    dot_node _dot_node = new dot_node(null, null);
    expression_list el = new expression_list();
    el.expressions.Add(param);
    //method_call _method_call = new method_call(el);
    //_method_call.dereferencing_value = id;
    _dot_node.left = (addressed_value)dt;
    _dot_node.right = id;
    method_call _method_call = new method_call(el);
    _method_call.dereferencing_value = _dot_node;
    return _method_call;
}
        /*public override void visit(procedure_call pc)
        {
            ProcessNode(pc.func_name);
            var methCall = pc.func_name as method_call;
            if ((object)methCall != null)
            {
                foreach (var param in methCall.parameters.expressions)
                {
                    param.visit(this);
                }
            }
        }*/
        public override void visit(dot_node dn)
        {
            var rid = dn.right as ident;
            if ((object)rid != null && rid.name != Consts.Self)
                ProcessNode(dn.left);

            // Most nested
            // DotNode (DLeft, DRight) -> DotNode(DotNode("self", "<>__self"), DRight)

            // LEFT self -> captured self (self.captured_self)
            /*var id = dn.left as ident;
            if ((object)id != null && (id.name == "self" || CollectedClassFields.Contains(id.name)))
            {
                // Some magic for blocking back-traverse from BaseChangeVisitor redoin' work
                //var rid = dn.right as ident;
                //if ((object)rid != null && rid.name != Consts.Self)
                {
                    var newDotNode = new dot_node(new dot_node(new ident("self"), new ident(Consts.Self)), dn.right);
                    // Change right?
                    //var capturedRight = new dot_node(new ident(Consts.Self), dn.right);
                    //var newDotNode = new dot_node(dn.left, capturedRight);
                    Replace(dn, newDotNode);
                }

                // Some magic for blocking back-traverse from BaseChangeVisitor redoin' work
                //var rid = dn.right as ident;
                //if ((object)rid != null && rid.name != Consts.Self)
               // {
                //    var capturedSelf = new dot_node(new ident("self"), new ident(Consts.Self));
                //    Replace(dn.left, capturedSelf);
               // }
            }
            else
            {
                ProcessNode(dn.left);
            }*/

            //if (dn.right.GetType() != typeof(ident))
            //    ProcessNode(dn.right);
        }
public method_call _index(expression dt, expression param)
{
    token_info _token_info = new token_info(".");
    ident id = new ident("index");
    dot_node _dot_node = new dot_node(null, null);
    expression_list el = new expression_list();
    el.expressions.Add(param);
    _dot_node.left = (addressed_value)dt;
    _dot_node.right = id;
    method_call _method_call = new method_call(el);
    _method_call.dereferencing_value = _dot_node;
    return _method_call;
}
        private void indexer_as_expression_index(expression_node expr, SyntaxTree.expression_list parameters,
            motivation mot, location loc)
        {
            try_convert_typed_expression_to_function_call(ref expr);

            // SSM 10.01.16 Tuple t[i]
            var ent = expr.type as compiled_type_node;

            if (ent== null)
            {
                var eeee = expr.type as compiled_generic_instance_type_node;
                if (eeee!= null)
                    ent = eeee.original_generic as compiled_type_node;
            }

            if (ent != null)
            {
                var t = ent.compiled_type;
                if (t.FullName.StartsWith("System.Tuple"))
                {
                    expression eee = parameters.expressions[0];

                    if (parameters.expressions.Count > 1)
                        AddError(get_location(eee), "TUPLE_CAN_HAVE_ONLY_ONE_INDEX");

                    var cn = convert_strong_to_constant_node(eee);

                    var v = cn as int_const_node;

                    if (v != null)
                    {
                        if (v.constant_value<0 || v.constant_value >= t.GetGenericArguments().Count())
                            AddError(cn.location, "TUPLE_INDEX_OUT_OF_RANGE_{0}", t.GetGenericArguments().Count()-1);
                        var dn = new dot_node(new semantic_addr_value(expr), new ident("Item" + (v.constant_value + 1).ToString(), eee.source_context),new SourceContext(loc.begin_line_num,loc.begin_column_num,loc.end_line_num,loc.end_column_num));
                        visit(dn);
                        return;
                    }
                    else AddError(cn.location, "TUPLE_INDEX_MUST_BE_INTEGER_CONSTANT");
                }
            }
            // end SSM 09.01.16 Tuple t[i]

            if (expr.type.type_special_kind == SemanticTree.type_special_kind.array_kind)
            {
                internal_interface ii = expr.type.get_internal_interface(internal_interface_kind.unsized_array_interface);
                array_internal_interface aii = (array_internal_interface)ii;
                int rank = aii.rank;
                //TODO: Многомерные массивы.
                expression_node ind_expr = convert_strong(parameters.expressions[0]);
                ind_expr = additional_indexer_convertion(ind_expr, expr.type);
                simple_array_indexing sai = new simple_array_indexing(expr, ind_expr, aii.element_type, loc);
                if (rank == 1)
                for (int i = 1; i < parameters.expressions.Count; i++)
                {
                    ii = sai.type.get_internal_interface(internal_interface_kind.unsized_array_interface);
                    location lloc = get_location(parameters.expressions[i]);
                    if (ii == null)
                    {
                        AddError(lloc, "{0}_DIMENSIONAL_ARRAY_CAN_NOT_HAVE_{1}_AND_MORE_INDEXING", i, i+1);
                    }
                    aii = (array_internal_interface)ii;
                    ind_expr = convert_strong(parameters.expressions[i]);
                    ind_expr = additional_indexer_convertion(ind_expr, sai.type);
                    sai = new simple_array_indexing(sai, ind_expr, aii.element_type, lloc);
                }
                else
                {
                    if (rank != parameters.expressions.Count)
                        AddError(get_location(parameters), "{0}_DIMENSIONAL_ARRAY_CAN_NOT_HAVE_{1}_AND_MORE_INDEXING", rank, rank + 1);
                	List<expression_node> lst = new List<expression_node>();
                	for (int i = 0; i < parameters.expressions.Count; i++)
                	{
                    	location lloc = get_location(parameters.expressions[i]);
                    	ind_expr = convert_strong(parameters.expressions[i]);
                    	ind_expr = additional_indexer_convertion(ind_expr, sai.type);
                    	lst.Add(ind_expr);
                	}
                	sai = new simple_array_indexing(expr, lst[0], aii.element_type, get_location(parameters));
                	sai.expr_indices = lst.ToArray();
                }
                switch (mot)
                {
                    case motivation.address_reciving:
                        {
                            return_addressed_value(sai);
                            break;
                        }
                    case motivation.expression_evaluation:
                        {
                            return_value(sai);
                            break;
                        }
                    case motivation.semantic_node_reciving:
                        {
                            return_semantic_value(sai);
                            break;
                        }
                }
                return;
            }
            else if (expr.type.type_special_kind == SemanticTree.type_special_kind.short_string)
            {
            	if (parameters.expressions.Count != 1)
                    AddError(loc, "INVALID_PARAMETER_COUNT_IN_INDEXER");
            	expression_node ind_expr = convert_strong(parameters.expressions[0]);
            	ind_expr = additional_indexer_convertion(ind_expr, expr.type);
            	//expression_node en = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.GetCharInShortStringProcedure.sym_info as function_node,loc,ind_expr,new int_const_node((expr.type as short_string_type_node).Length,null));
            	switch (mot)
                {
                    case motivation.address_reciving:
                        {
                            simple_array_indexing sai = new simple_array_indexing(expr, ind_expr, SystemLibrary.SystemLibrary.char_type, loc);
                            return_addressed_value(sai);
                            //return_addressed_value(convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.SetCharInShortStringProcedure.sym_info as function_node,loc,expr,ind_expr) as common_namespace_function_call);
                            break;
                        }
                    case motivation.expression_evaluation:
                        {
            				return_value(convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.GetCharInShortStringProcedure.sym_info as function_node,loc,expr,ind_expr,new int_const_node((expr.type as short_string_type_node).Length,null)));
                            break;
                        }
                    case motivation.semantic_node_reciving:
                        {
            				return_semantic_value(convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.GetCharInShortStringProcedure.sym_info as function_node,loc,expr,ind_expr,new int_const_node((expr.type as short_string_type_node).Length,null)));
                            break;
                        }
                }
                return;
            	
            }
            /*else if (expr.type.type_special_kind == SemanticTree.type_special_kind.array_wrapper)
            {
            	internal_interface ii = expr.type.get_internal_interface(internal_interface_kind.bounded_array_interface);
                array_internal_interface aii = (array_internal_interface)ii;
                //TODO: Многомерные массивы.
                expression_node ind_expr = convert_strong(parameters.expressions[0]);
                ind_expr = additional_indexer_convertion(ind_expr, expr.type);
                simple_array_indexing sai = new simple_array_indexing(expr, ind_expr, aii.element_type, loc);
                for (int i = 1; i < parameters.expressions.Count; i++)
                {
                    ii = sai.type.get_internal_interface(internal_interface_kind.bounded_array_interface);
                    location lloc = get_location(parameters.expressions[i]);
                    if (ii == null)
                    {
                        throw new NDimensionalArrayCanNotHaveNPlusOneIndexer(lloc, expr, i);
                    }
                    aii = (array_internal_interface)ii;
                    ind_expr = convert_strong(parameters.expressions[i]);
                    ind_expr = create_simple_function_call(SystemLibrary.SystemLibrary.int_sub, cmc.location, ind_expr,
                                            new int_const_node(ii.ordinal_type_interface.ordinal_type_to_int(bai.ordinal_type_interface.lower_value),cmc.location));
                    ind_expr = additional_indexer_convertion(ind_expr, sai.type);
                    sai = new simple_array_indexing(sai, ind_expr, aii.element_type, lloc);
                }
                switch (mot)
                {
                    case motivation.address_reciving:
                        {
                            return_addressed_value(sai);
                            break;
                        }
                    case motivation.expression_evaluation:
                        {
                            return_value(sai);
                            break;
                        }
                    case motivation.semantic_node_reciving:
                        {
                            return_semantic_value(sai);
                            break;
                        }
                }
                return;
                
                 if (factparams[i].semantic_node_type == semantic_node_type.common_method_call)
                            {
                                common_method_call cmc = (common_method_call)factparams[i];
                                internal_interface ii = cmc.obj.type.get_internal_interface(internal_interface_kind.bounded_array_interface);
                                if (ii != null)
                                {
                                    if (cmc.function_node.name == compiler_string_consts.get_val_pascal_array_name)
                                    {
                                        bounded_array_interface bai = (bounded_array_interface)ii;
                                        class_field cf = bai.int_array;
                                        expression_node left = new class_field_reference(cf, cmc.obj, cmc.location);
                                        expression_node right = cmc.parameters[0];
                                        //right = convert_type(right, SystemLibrary.SystemLibrary.integer_type);
                                        right = convert_type(right, (ii as bounded_array_interface).ordinal_type_interface.elems_type);
                                        right = create_simple_function_call(SystemLibrary.SystemLibrary.int_sub, cmc.location, right,
                                            new int_const_node(bai.ordinal_type_interface.ordinal_type_to_int(bai.ordinal_type_interface.lower_value),cmc.location));
                                        factparams[i] = new simple_array_indexing(left, right, cmc.type, cmc.location);
                                        is_pascal_array_ref = true;
                                    }
                                }
                            }
            }*/
            if (expr.type.default_property_node == null)
            {
                if (expr.type.semantic_node_type != semantic_node_type.delegated_method)
                {
                    AddError(loc, "NO_DEFAULT_PROPERTY_TO_TYPE_{0}", expr.type.PrintableName);
                }
                else
                {
                    AddError(loc, "NO_DEFAULT_PROPERTY_TO_FUNCTION_TYPE");
                }
            }

            if (expr.type.default_property_node.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
            {
                AddError(new CanNotReferenceToStaticPropertyWithExpression(expr.type.default_property_node, loc, expr.type));
            }
            non_static_property_reference nspr = new non_static_property_reference(expr.type.default_property_node, expr, loc);
            indexer_as_property_indexes(nspr, parameters, mot, loc);
            //eto vrode rabotaet normalno. no imet v vidu
            if (expr.type.type_special_kind == SemanticTree.type_special_kind.array_wrapper)
            {
            	expression_node en = ret.get_expression();
                if (en is non_static_property_reference)
                {
                    non_static_property_reference cmc = (non_static_property_reference)en;
                    internal_interface ii = cmc.expression.type.get_internal_interface(internal_interface_kind.bounded_array_interface);
                    if (ii != null)
                    {
                        //if (cmc.function_node.name == compiler_string_consts.get_val_pascal_array_name)
                        {
                            bounded_array_interface bai = (bounded_array_interface)ii;
                            class_field cf = bai.int_array;
                            expression_node left = new class_field_reference(cf, cmc.expression, cmc.location);
                            expression_node right = cmc.fact_parametres[0];
                            //right = convert_type(right, SystemLibrary.SystemLibrary.integer_type);
                            right = convertion_data_and_alghoritms.convert_type(right, (ii as bounded_array_interface).ordinal_type_interface.elems_type);
                            right = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibrary.int_sub, cmc.location, right,
                                                new int_const_node(bai.ordinal_type_interface.ordinal_type_to_int(bai.ordinal_type_interface.lower_value), cmc.location));
                            en = new simple_array_indexing(left, right, cmc.type, cmc.location);
                            //is_pascal_array_ref = true;
                        }
                    }
                }
                else
                {
                    common_method_call cmc = (common_method_call)en;
                    internal_interface ii = cmc.obj.type.get_internal_interface(internal_interface_kind.bounded_array_interface);
                    if (ii != null)
                    {
                        //if (cmc.function_node.name == compiler_string_consts.get_val_pascal_array_name)
                        {
                            bounded_array_interface bai = (bounded_array_interface)ii;
                            class_field cf = bai.int_array;
                            expression_node left = new class_field_reference(cf, cmc.obj, cmc.location);
                            expression_node right = cmc.parameters[0];
                            //right = convert_type(right, SystemLibrary.SystemLibrary.integer_type);
                            right = convertion_data_and_alghoritms.convert_type(right, (ii as bounded_array_interface).ordinal_type_interface.elems_type);
                            right = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibrary.int_sub, cmc.location, right,
                                                new int_const_node(bai.ordinal_type_interface.ordinal_type_to_int(bai.ordinal_type_interface.lower_value), cmc.location));
                            en = new simple_array_indexing(left, right, cmc.type, cmc.location);
                            //is_pascal_array_ref = true;
                        }
                    }
                }
                return_value(en);
            }
            
            return;
        }
        public override void visit(dot_node _dot_node)
        {
            bool tmp = search_all;
        	search_all = false;
        	_dot_node.left.visit(this);
			search_all = tmp;
        	if (returned_scope != null)
			{
				if (_dot_node.right is ident)
				{
					if (!search_all)
					{
                        TypeScope ts = returned_scope as TypeScope;
                        if (returned_scope is ProcScope)
                            ts = (returned_scope as ProcScope).return_type;
						returned_scope = ts.FindNameOnlyInType((_dot_node.right as ident).name);
                        if (returned_scope == null)
                        {
                            List<ProcScope> meths = entry_scope.GetExtensionMethods((_dot_node.right as ident).name, ts);
                            if (meths.Count > 0)
                                returned_scope = meths[0];
                        }
                        if (returned_scope != null && returned_scope is ProcScope && (returned_scope as ProcScope).return_type != null)
						{
							if ((returned_scope as ProcScope).parameters.Count == 0)
                                returned_scope = (returned_scope as ProcScope).return_type;
							return;
						}
						else if (returned_scope is ElementScope)
						{
							this.cnst_val.prim_val = (returned_scope as ElementScope).cnst_val;
							returned_scope = (returned_scope as ElementScope).sc;
							return;
						}
						else if (returned_scope is TypeScope)
							is_type = true;
					}
					else
					{
                        returned_scopes = returned_scope.FindOverloadNamesOnlyInType((_dot_node.right as ident).name);
						search_all = false;
					}
				}
			}
        }
 public override void visit(matching_expression _matching_expression)
 {
     SyntaxTree.procedure_call pc = new SyntaxTree.procedure_call();
     SyntaxTree.method_call mc = new SyntaxTree.method_call();
     dot_node dot = new dot_node(new ident("PABCSystem"), new ident("KV"));
     mc.dereferencing_value = dot;
     pc.func_name = mc;
     pc.source_context = _matching_expression.source_context;
     SyntaxTree.expression_list exl = new PascalABCCompiler.SyntaxTree.expression_list();
     exl.Add(_matching_expression.left);
     exl.Add(_matching_expression.right);
     mc.parameters = exl;
     visit(pc);
 }
示例#26
0
 public override void visit(dot_node _dot_node)
 {
     _dot_node.left.visit(this);
     if (ret_tn != null)
     {
         IBaseScope left_scope = ret_tn;
         if (_dot_node.right is ident)
         {
             ret_tn = ret_tn.FindNameOnlyInType((_dot_node.right as ident).name);
         }
     }
     if (ret_tn != null && ret_tn.IsEqual(founded_scope))
         pos_list.Add(get_position(_dot_node.right));
 }
        public override void visit(SyntaxTree.dot_node _dot_node)
        {
            motivation mot = motivation_keeper.motivation;
            SyntaxTree.ident id_left = _dot_node.left as SyntaxTree.ident;
            SyntaxTree.ident id_right = _dot_node.right as SyntaxTree.ident;
#if (DEBUG)
            if (id_right == null)
            {
                throw new CompilerInternalError("Ident expected in left part of dot operator.");
            }
#endif

            //lroman
            if (_dot_node.left is closure_substituting_node)
            {
                var left = (closure_substituting_node)_dot_node.left;
                var dotNodeToVisit = new dot_node(left.substitution, _dot_node.right);
                visit(dotNodeToVisit);
                return;
            }

            if (id_left != null)
            {
                dot_node_as_ident_dot_ident(id_left, id_right, mot);
                return;
            }
            else
            {
                SyntaxTree.ident_with_templateparams iwt = _dot_node.left as SyntaxTree.ident_with_templateparams;
                if (iwt != null)
                {
                    type_node tn = ret.visit((SyntaxTree.syntax_tree_node)iwt) as type_node;
                    dot_node_as_type_ident(tn, id_right, mot);
                    return;
                }
                SyntaxTree.dot_node left_dot = _dot_node.left as SyntaxTree.dot_node;
                if (left_dot != null)
                {
                    dot_node_as_dot_node_dot_ident(left_dot, id_right, mot);
                    return;
                }
                expression_node en = convert_strong(_dot_node.left);
                dot_node_as_expression_dot_ident(en, id_right, mot, _dot_node.left);
                return;
            }
        }
示例#28
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public closure_substituting_node(dot_node _substitution)
		{
			this._substitution=_substitution;
		}
		public void write_dot_node(dot_node _dot_node)
		{
			write_addressed_value_funcname(_dot_node);
			if (_dot_node.left == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_dot_node.left.visit(this);
			}
			if (_dot_node.right == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_dot_node.right.visit(this);
			}
		}
        public override void visit(dot_node _dot_node)
        {
            bool tmp = search_all;
        	search_all = false;
        	_dot_node.left.visit(this);
			search_all = tmp;
        	if (ret_tn != null)
			{
				if (_dot_node.right is ident)
				{
					if (!search_all)
					{
						ret_tn = ret_tn.FindNameOnlyInType((_dot_node.right as ident).name);
						if (ret_tn != null && ret_tn is ProcScope && (ret_tn as ProcScope).return_type != null)
						{
							if ((ret_tn as ProcScope).parameters.Count == 0)
                                ret_tn = (ret_tn as ProcScope).return_type;
							return;
						}
						else if (ret_tn is ElementScope)
						{
							this.cnst_val.prim_val = (ret_tn as ElementScope).cnst_val;
							ret_tn = (ret_tn as ElementScope).sc;
							return;
						}
						else if (ret_tn is TypeScope)
							is_type = true;
					}
					else
					{
                        ret_names = ret_tn.FindOverloadNamesOnlyInType((_dot_node.right as ident).name);
						search_all = false;
					}
				}
			}
        }