예제 #1
0
        public override void visit(var_def_statement vd)
        {
            var idents = vd.vars.idents;

            var IdentsToDeleteInVarDef = idents.FindAll(id => idsToDelete.Contains(id.name)); // найти в операторе все идентификаторы для удаления
            if (IdentsToDeleteInVarDef.Count != 0)
            {
                deletedIdsToDeleteInLocalScope.UnionWith(IdentsToDeleteInVarDef.Select(id => id.name)); // добавить те идентификаторы, которые мы удаляем из данного описания

                BlockDeletedIds.Add(new var_def_statement(new ident_list(IdentsToDeleteInVarDef), vd.vars_type, vd.inital_value)); // добавить описание из удаленных в данном разделе описаний идентификаторов
                idents.RemoveAll(id => idsToDelete.Contains(id.name)); // удалить в операторе все идентификаторы для удаления

                if (idents.Count == 0)
                {
                    // Выше  - variable_definitions, еще выше - declarations
                    var uvdsl = UpperNodeAs<variable_definitions>();
                    uvdsl.var_definitions.Remove(vd);  
                    if (uvdsl.var_definitions.Count == 0)
                    {
                        var d = UpperNodeAs<declarations>(2);
                        d.defs.Remove(uvdsl);
                    }
                }                    
            }
        }
예제 #2
0
 /// <summary>
 /// Создать var-выражение с несколькими переменными
 /// </summary>
 /// <param name="type">Тип переменных</param>
 /// <param name="idents">Имена переменных</param>
 /// <returns></returns>
 public var_def_statement CreateVarDef(named_type_reference type, params string[] names)
 {
     var_def_statement res = new var_def_statement();
     foreach (string x in names)
         res.vars.Add(new ident(x));
     res.vars_type = type;
     return res;
 }
예제 #3
0
 /// <summary>
 /// Создать var-выражение
 /// </summary>
 /// <param name="name">Имя переменной</param>
 /// <param name="initialValue">Начальное значение</param>
 /// <returns></returns>
 public var_def_statement CreateVarDef(string name, expression initialValue)
 {
     ident_list list = new ident_list();
     list.idents.Add(new ident(name));
     var res = new var_def_statement();
     res.inital_value = initialValue;
     res.vars = list;
     return res;
 }
        public override void visit(var_def_statement varDefStmt)
        {
            _visitor.visit(varDefStmt);
            
            foreach (var id in varDefStmt.vars.idents)
            {
                var si = _visitor.context.find(id.name);
                _currentTreeNode.VariablesDefinedInScope.Add(new CapturedVariablesTreeNode.CapturedSymbolInfo(varDefStmt, si));
            }

            if (varDefStmt.inital_value != null)
            {
                ProcessNode(varDefStmt.inital_value);
            }
        }
예제 #5
0
		public void write_var_def_statement(var_def_statement _var_def_statement)
		{
			write_declaration(_var_def_statement);
			if (_var_def_statement.vars == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_var_def_statement.vars.visit(this);
			}
			if (_var_def_statement.vars_type == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_var_def_statement.vars_type.visit(this);
			}
			if (_var_def_statement.inital_value == null)
			{
				bw.Write((byte)0);
			}
			else
			{
				bw.Write((byte)1);
				_var_def_statement.inital_value.visit(this);
			}
			bw.Write((byte)_var_def_statement.var_attr);
			bw.Write(_var_def_statement.is_event);
		}
예제 #6
0
 public override void visit(var_def_statement defs)
 {
     indef = true;
     ProcessNode(defs.vars); // исключаем типы - просматриваем только имена переменных
     indef = false;
 }
예제 #7
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public var_statement(var_def_statement _var_def,SourceContext sc)
		{
			this._var_def=_var_def;
			source_context = sc;
		}
 public override void visit(var_def_statement varStmt)
 {
     syntaxTreeVisitor.visit(varStmt);
 }
예제 #9
0
 public static var_statement CreateVarStatementNode(string idName, string varTypeName, expression initValue)
 {
     var id = new ident(idName);
     var idlist = new ident_list(id);
     var varType = new named_type_reference(varTypeName, null);
     var vdef = new var_def_statement(idlist, varType, initValue, definition_attribute.None, false, null);
     return new var_statement(vdef, null);
 }
예제 #10
0
 public List<object> ident_list14(object lr1, object lr3)
 {
     List<object> ar = new List<object>();
     //named_type_reference n_t_r = (named_type_reference)lr3;
     var_def_statement vds = new var_def_statement();
     vds.vars = new ident_list();
     vds.vars.idents.Add((ident)lr1);
     vds.vars_type = (type_definition)lr3;
     ar.Add(vds);
     return ar;
 }
예제 #11
0
 public List<object> ident_list13(object lr1, object lr3, object lr5)
 {
     List<object> ar = (List<object>)lr5;
     //named_type_reference n_t_r = (named_type_reference)lr3;
     var_def_statement vds = new var_def_statement();
     vds.vars = new ident_list();
     vds.vars.idents.Add((ident)lr1);
     vds.vars_type = (type_definition)lr3;//n_t_r;
     ar.Insert(0, vds);
     return ar;
 }
        private void SubstituteTypesInCaseOfGenerics()
        {
            if (!IsInGenerics)
            {
                return;
            }

            /* TODO: нужно заменить в полях сгенерированных классов, параметрах и возвращаемом значении лямбд - у всех, с учетом того как чистятся все дженерики...
            /* Предусмотреть случай, когда захвата переменных не происходит, но мы все равно находимся в лямбде - это нужно сделать на FinishPhase в syntax_tree_visitor
            /* Не забыть про where секцию */

            var nestedLambdas = new List<CapturedVariablesTreeNodeLambdaScope>();
            foreach (var cl in _generatedScopeClassesInfo.Where(cd => !(cd.Value.CorrespondingTreeNode is CapturedVariablesTreeNodeClassScope)))
            {
                nestedLambdas.AddRange(cl.Value.NestedLambdas);
            }

            foreach (CapturedVariablesTreeNodeLambdaScope t in _lambdasToBeAddedAsMethods.Concat(nestedLambdas))
            {
                var lambdaDef = t.LambdaDefinition;
                if (lambdaDef.formal_parameters != null && lambdaDef.formal_parameters.params_list.Count > 0)
                {
                    for (var j = 0; j < lambdaDef.formal_parameters.params_list.Count; j++)
                    {
                        if (lambdaDef.formal_parameters.params_list[j].vars_type is lambda_inferred_type)
                        {
                            if ((lambdaDef.formal_parameters.params_list[j].vars_type as lambda_inferred_type).real_type is type_node)
                            {
                                lambdaDef.formal_parameters.params_list[j].vars_type = 
                                    LambdaHelper.ConvertSemanticTypeToSyntaxType((type_node)(lambdaDef.formal_parameters.params_list[j].vars_type as lambda_inferred_type).real_type);
                            }
                        }
                    }
                }

                if (lambdaDef.return_type is lambda_inferred_type)
                {
                    if ((lambdaDef.return_type as lambda_inferred_type).real_type is type_node)
                    {
                        lambdaDef.return_type = LambdaHelper.ConvertSemanticTypeToSyntaxType((type_node)(lambdaDef.return_type as lambda_inferred_type).real_type);
                    }
                }
            }
            
            foreach (var clDecl in _generatedScopeClassesInfo.Where(cd => !(cd.Value.CorrespondingTreeNode is CapturedVariablesTreeNodeClassScope)))
            {
                var fields =
                    ((class_definition) clDecl.Value.ClassDeclaration.type_def).body.class_def_blocks
                    .SelectMany(d => d.members)
                    .OfType<var_def_statement>();

                foreach (var field in fields)
                {
                    var semTypeNode = field.vars_type as semantic_type_node;
                    if (semTypeNode != null)
                    {
                        if (semTypeNode.type is type_node)
                        {
                            field.vars_type = LambdaHelper.ConvertSemanticTypeToSyntaxType((type_node) semTypeNode.type);
                        }
                    }
                }

                var constructors =
                    ((class_definition)clDecl.Value.ClassDeclaration.type_def).body.class_def_blocks
                    .SelectMany(d => d.members)
                    .OfType<procedure_definition>()
                    .Where(pr => pr.proc_header is constructor);

                foreach (var constructor in constructors)
                {
                    if (constructor.proc_header != null && constructor.proc_header.parameters != null && constructor.proc_header.parameters.params_list != null)
                    {
                        var pars = constructor.proc_header.parameters.params_list;
                        foreach (var p in pars)
                        {
                            var semTypeNode = p.vars_type as semantic_type_node;
                            if (semTypeNode != null)
                            {
                                if (semTypeNode.type is type_node)
                                {
                                    p.vars_type = LambdaHelper.ConvertSemanticTypeToSyntaxType((type_node)semTypeNode.type);
                                }
                            }
                        }
                    }
                }

                var upperField =
                    ((class_definition)clDecl.Value.ClassDeclaration.type_def).body.class_def_blocks
                    .SelectMany(d => d.members)
                    .OfType<var_def_statement>()
                    .FirstOrDefault(vds =>
                        {
                            if (vds.vars != null && vds.vars.idents != null)
                            {
                                if (vds.vars.idents.FirstOrDefault(id => id.name == clDecl.Value.GeneratedUpperClassFieldName) != null)
                                {
                                    return true;
                                }
                            }
                            return false;
                        });

                if (upperField != null)
                {
                    var genericParameters = AllGenericParameters;

                    if (_visitor.context._ctn != null && _visitor.context._ctn.generic_params != null)
                    {
                        var tr = upperField.vars_type as named_type_reference;
                        if (tr != null && tr.names != null && tr.names.Count == 1)
                        {
                            if (tr.names[0].name == _visitor.context._ctn.name)
                            {
                                genericParameters = ClassGenericParameters;
                            }
                        }
                    }

                    upperField.vars_type =
                        new template_type_reference(
                            (named_type_reference)upperField.vars_type,
                            new template_param_list(genericParameters.Select(l => SyntaxTreeBuilder.BuildSimpleType(l.name)).ToList()));
                }

                if (clDecl.Value.GeneratedVarStatementForScope != null)
                {
                    var oldInitialValueExpressions =
                        ((new_expr) clDecl.Value.GeneratedVarStatementForScope.var_def.inital_value).params_list;

                    var newVarDefSyntaxTreeNode = new var_def_statement(clDecl.Value.GeneratedSubstitutingFieldName, new template_type_reference(new named_type_reference(clDecl.Value.ClassDeclaration.type_name.name), new template_param_list(AllGenericParameters.Select(l => SyntaxTreeBuilder.BuildSimpleType(l.name)).ToList())));
                    newVarDefSyntaxTreeNode.inital_value =
                        new new_expr(new template_type_reference(new named_type_reference(clDecl.Value.ClassDeclaration.type_name.name), new template_param_list(AllGenericParameters.Select(l => SyntaxTreeBuilder.BuildSimpleType(l.name)).ToList())),
                                     oldInitialValueExpressions, null);

                    clDecl.Value.GeneratedVarStatementForScope.var_def = newVarDefSyntaxTreeNode;
                }

                clDecl.Value.ClassDeclaration.type_name = new template_type_name(clDecl.Value.ClassDeclaration.type_name.name, new ident_list(AllGenericParameters));

                if (WhereSection != null && WhereSection.defs != null && WhereSection.defs.Count != 0)
                {
                    ((class_definition) clDecl.Value.ClassDeclaration.type_def).where_section = WhereSection;
                }
            }
        }
        private void SubstituteVarDefInProcedure(statement_list statementList) //TODO: сейчас обрабатывается так, как будто блока объявлений declarations в функции нет. Нужно будет предусмотреть, но не только для функций, а еще для всех узлов где есть block, который содержит declarations
        {
            var classDefsTreeNode = _generatedScopeClassesInfo.Join(_capturedVarsTreeNodesDictionary,
                                                                     outer => outer.Key,
                                                                     inner => inner.Key,
                                                                     (outer, inner) => new
                                                                         {
                                                                             ClassDeclaration = outer.Value,
                                                                             TreeNode = inner.Value
                                                                         })
                                                               .Where(p => p.TreeNode is CapturedVariablesTreeNodeProcedureScope)
                                                               .Select(p => new
                                                                   {
                                                                       p.ClassDeclaration,
                                                                       TreeNode = (CapturedVariablesTreeNodeProcedureScope)p.TreeNode
                                                                   })
                                                               .FirstOrDefault();

            if (classDefsTreeNode == null)
            {
                return;
            }

            var variables = classDefsTreeNode
                        .TreeNode
                        .VariablesDefinedInScope
                        .Where(l => l.ReferencingLambdas.Count > 0)
                        .ToList();

            if (variables.Count == 0)
            {
                return;
            }

            CapturedVariablesSubstitutionClassGenerator.ScopeClassDefinition generatedClass;
            if (_generatedScopeClassesInfo.TryGetValue(classDefsTreeNode.TreeNode.ScopeIndex, out generatedClass))
            {
                var exprList = variables.Select(v => (expression)new ident(((IVAriableDefinitionNode) v.SymbolInfo.sym_info).name)).ToList();

                if (IsInGenerics)
                {
                    var newVarDefSyntaxTreeNode = new var_def_statement(generatedClass.GeneratedSubstitutingFieldName, new template_type_reference(new named_type_reference(generatedClass.ClassDeclaration.type_name.name), new template_param_list(AllGenericParameters.Select(l => SyntaxTreeBuilder.BuildSimpleType(l.name)).ToList())));
                    newVarDefSyntaxTreeNode.inital_value =
                        new new_expr(new template_type_reference(new named_type_reference(generatedClass.ClassDeclaration.type_name.name), new template_param_list(AllGenericParameters.Select(l => SyntaxTreeBuilder.BuildSimpleType(l.name)).ToList())),
                                        new expression_list(exprList), null);

                    generatedClass.GeneratedVarStatementForScope.var_def = newVarDefSyntaxTreeNode;
                }
                else
                {
                    generatedClass.GeneratedVarStatementForScope.var_def.inital_value =
                        new new_expr(SyntaxTreeBuilder.BuildSimpleType(generatedClass.ClassDeclaration.type_name.name),
                                     new expression_list(exprList), null);
                }

                var nodesToAdd = new List<statement>();
                nodesToAdd.Add(generatedClass.GeneratedVarStatementForScope);

                if (generatedClass.AssignNodeForUpperClassFieldInitialization != null)
                {
                    nodesToAdd.Add(generatedClass.AssignNodeForUpperClassFieldInitialization);
                }

                statementList.subnodes.InsertRange(0, nodesToAdd);
            }
        }
        private void SubstituteVariablesDeclarations()
        {
            var classDefsTreeNodes = _generatedScopeClassesInfo.Join(_capturedVarsTreeNodesDictionary,
                                                                     outer => outer.Key,
                                                                     inner => inner.Key,
                                                                     (outer, inner) => new
                                                                         {
                                                                             ClassDeclaration = outer.Value,
                                                                             TreeNode = inner.Value
                                                                         })
                                                               .Where(p => p.TreeNode is CapturedVariablesTreeNodeBlockScope)
                                                               .Select(p => new
                                                                   {
                                                                       p.ClassDeclaration,
                                                                       TreeNode = (CapturedVariablesTreeNodeBlockScope) p.TreeNode
                                                                   }); //TODO: Сейчас рассматриваются только захватываемые переменные, определенные внутри какого-либо блока. Рассмотреть остальные случаи.

            foreach (var classDefTreeNode in classDefsTreeNodes)
            {
                var statementListNode = classDefTreeNode.TreeNode.CorrespondingSyntaxTreeNode as statement_list; //TODO: Сейчас рассматриваются только захватываемые переменные, определенные внутри какого-либо блока. Рассмотреть остальные случаи.
                if (statementListNode != null)
                {
                    var variables = classDefTreeNode
                        .TreeNode
                        .VariablesDefinedInScope
                        .Where(var => var.ReferencingLambdas.Count > 0)
                        .GroupBy(var => var.SyntaxTreeNodeWithVarDeclaration)
                        .Select(gr => new
                            {
                                SyntaxTreeNodeWithVarDeclaration = gr.Key,
                                Vars = gr.ToList()
                            })
                        .ToList();

                    if (variables.Count == 0)
                    {
                        return;
                    }

                    var newStmtList = new statement_list();
                    newStmtList.Add(classDefTreeNode.ClassDeclaration.GeneratedVarStatementForScope);
                    if (classDefTreeNode.ClassDeclaration.AssignNodeForUpperClassFieldInitialization != null)
                    {
                        newStmtList.Add(classDefTreeNode.ClassDeclaration.AssignNodeForUpperClassFieldInitialization);
                    }

                    var stmtListQueue = new Queue<statement>(statementListNode.subnodes);
                    while (stmtListQueue.Count > 0)
                    {
                        var currentStatement = stmtListQueue.Dequeue();
                        var varStatement = currentStatement as var_statement;                                                   //TODO: пока что только локальные переменные, определенные внутри var_def_statement!!!!!!!!
                        if (varStatement != null &&
                            varStatement.var_def != null)
                        {
                            var varDefKey =
                                variables.FirstOrDefault(gr => gr.SyntaxTreeNodeWithVarDeclaration == varStatement.var_def);
                            if (varDefKey != null)
                            {
                                var varsToExclude =
                                    varDefKey.Vars.Select(var => ((IVAriableDefinitionNode) var.SymbolInfo.sym_info).name.ToLower()); //TODO: пока что только локальные переменные!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                                    
                                var newVarList = varStatement.var_def.vars.idents
                                    .Where(id => !varsToExclude.Contains(id.name.ToLower()))
                                    .ToList();

                                if (newVarList.Count > 0)
                                {
                                    var newVarDefStmt = new var_def_statement(new ident_list(newVarList), varStatement.var_def.vars_type)
                                        {
                                            inital_value = varStatement.var_def.inital_value
                                        };
                                    var newVarStmt = new var_statement(newVarDefStmt);
                                    newStmtList.Add(newVarStmt);
                                }

                                if (varStatement.var_def.inital_value != null)
                                {
                                    var initVal = varStatement.var_def.inital_value;
                                    string auxVarName = null;

                                    if (initVal is array_const)
                                    {
                                        auxVarName = LambdaHelper.GetAuxVarName();
                                        var newVarDefStmt = new var_def_statement(new ident_list(new ident(auxVarName)), varStatement.var_def.vars_type)
                                        {
                                            inital_value = initVal
                                        };
                                        var newVarStmt = new var_statement(newVarDefStmt);
                                        newStmtList.Add(newVarStmt);
                                    }

                                    foreach (var variable in varsToExclude)
                                    {
                                        var assignStmt =
                                            new assign(new dot_node(new ident(classDefTreeNode.ClassDeclaration.GeneratedSubstitutingFieldName),
                                                                    new ident(variable)),
                                                        auxVarName == null ? varStatement.var_def.inital_value : new ident(auxVarName));

                                        newStmtList.Add(assignStmt);
                                    }
                                }
                            }
                            else
                            {
                                newStmtList.Add(currentStatement);
                            }
                        }
                        else
                        {
                            newStmtList.Add(currentStatement);
                        }
                    }
                    
                    statementListNode.subnodes.Clear();
                    statementListNode.subnodes.AddRange(newStmtList.subnodes);
                }
            }
        }
예제 #15
0
        ///////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////
        //CreateNonTerminalObject
        ///////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        return _unit_module;
                    }

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

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

                        return _procedure_definition;
                    }

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

                        procedure_definition _procedure_definition = new procedure_definition(_procedure_header, _block);

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

                        return _procedure_definition;
                    }

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        statement_list var_statement_list = new statement_list();

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

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

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

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

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

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

                        statement_list var_statement_list = new statement_list();

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

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

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

                        return var_statement_list;
                    }

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

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

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

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

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

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

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

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


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

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

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

                        //return null;
                    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        return _empty_statement;
                    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        }
                    }

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

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

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

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

                        return _procedure_call;
                    }

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

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

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

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

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

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

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

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


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

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


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

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

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

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

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

                        return _bin_expr;
                    }

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

                        return _bin_expr;
                    }

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

                        return _bin_expr;
                    }

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

                        return _bin_expr;
                    }

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

                        return _bin_expr;
                    }

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

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

                        return _bin_expr;
                    }

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

                        return _bin_expr;
                    }

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

                        return _bin_expr;
                    }

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

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

                        return _bin_expr;
                    }

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

                        return _bin_expr;
                    }

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

                        return _bin_expr;
                    }

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

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

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

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

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

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

                        return _un_expr;
                    }

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

                        return _un_expr;
                    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            }
            throw new RuleException("Unknown rule");
        }
예제 #16
0
        public override void visit(var_def_statement _var_def_statement)
        {
        	try
        	{
        		returned_scope = null;
        		if (_var_def_statement.vars_type != null)
        			_var_def_statement.vars_type.visit(this);
        		if (_var_def_statement.vars_type == null && _var_def_statement.inital_value != null || _var_def_statement.inital_value is function_lambda_definition)
        		{
        			_var_def_statement.inital_value.visit(this);
        		}
           		// if (si == null) dn = compiled_type_node.get_type_node(PascalABCCompiler.NetHelper.NetHelper.FindType((_var_def_statement.vars_type as named_type_reference).names[0].name,unl));
           
            	if (returned_scope == null) return;
                if (returned_scope is ProcScope)
                {
                    if (_var_def_statement.vars_type != null)
                        returned_scope = new ProcType(returned_scope as ProcScope);
                    else
                        returned_scope = (returned_scope as ProcScope).return_type;
                }

            	if (_var_def_statement.vars != null)
            	foreach (ident s in _var_def_statement.vars.idents)
            	{
           			SymInfo si = new SymInfo(s.name, SymbolKind.Variable,s.name);
           			if (cur_scope is TypeScope) si.kind = SymbolKind.Field;
           			if (_var_def_statement.is_event) si.kind = SymbolKind.Event;
           			ElementScope es = new ElementScope(si, returned_scope,cur_scope);
           			if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_var_def_statement))
           			es.AddDocumentation(this.converter.controller.docs[_var_def_statement]);
           			es.acc_mod = cur_access_mod;
           			es.is_static = _var_def_statement.var_attr == definition_attribute.Static;
           			es.si.acc_mod = cur_access_mod;
           			es.loc = get_location(s);
           			cur_scope.AddName(s.name,es);
           			es.declaringUnit = cur_scope;
            	}
        	}
        	catch(Exception e)
        	{
        		
        	}
        }
예제 #17
0
        public override void visit(var_def_statement _var_def_statement)
        {
            if (for_refactoring && _var_def_statement.vars != null)
                foreach (ident s in _var_def_statement.vars.idents)
                {
                    IBaseScope ss = entry_scope.FindScopeByLocation(s.source_context.begin_position.line_num, s.source_context.begin_position.column_num);
                    if (ss != null && ss.IsEqual(founded_scope))
                        pos_list.Add(get_position(s));
                }

            if (_var_def_statement.vars_type != null)
                _var_def_statement.vars_type.visit(this);
            if (_var_def_statement.inital_value != null)
                _var_def_statement.inital_value.visit(this);
        }
예제 #18
0
        public statement MyStmt(expression ex, statement st)
        {
            // Проверить, что в ex - целый тип
            // Сделать специальный узел для проверки new semantic_check("Тип проверки",params syntax_node[] ob)
            // Включать этот узел первым для "сахарных" узлов синтаксического дерева
            var sc = new semantic_check("ExprIsInteger", ex);

            var id = new ident("#my");
            var idlist = new ident_list(id);
            var typ = new named_type_reference("integer");
            var one = new int32_const(1);
            var vdef = new var_def_statement(idlist, typ, one, definition_attribute.None, false, null);
            var vstat = new var_statement(vdef, null);

            var ass = new assign(new ident("#my"), one, Operators.AssignmentAddition);
            var stlistwhile = new statement_list(st);
            stlistwhile.Add(ass);

            var bin = new bin_expr(id, ex, Operators.LessEqual);

            var wh = new while_node(bin, stlistwhile, WhileCycleType.While);

            var stlist = new statement_list(sc);
            stlist.Add(vstat);
            stlist.Add(wh);
            return stlist;
        }
예제 #19
0
 public static var_statement CreateVarStatementNode(ident_list idlist, type_definition varType, expression initValue)
 {
     var vdef = new var_def_statement(idlist, varType, initValue, definition_attribute.None, false, null);
     return new var_statement(vdef, null);
 }
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");
}  
예제 #21
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public var_statement(var_def_statement _var_def)
		{
			this._var_def=_var_def;
		}
public var_statement var_st(string name, type_definition td)
{
    ident_list il = new ident_list();
    il.idents.Add(new ident(name));
    var_def_statement _var_def_statement = new var_def_statement(il, td, null, definition_attribute.None, false);
    return new var_statement(_var_def_statement);
}
        /*public override void Enter(syntax_tree_node st)
        {
            base.Enter(st);
            countNodesVisited++;

            // сокращение обходимых узлов. Как сделать фильтр по тем узлам, которые необходимо обходить? Например, все операторы (без выражений и описаний), все описания (без операторов)
            if (st.GetType()==typeof(assign) || st.GetType()==typeof(var_def_statement) || st is procedure_call || st is procedure_header || st is expression)
            {
                visitNode = false; // фильтр - куда не заходить 
            }
        }*/

        /*public override void visit(class_members cm)
        {
            foreach (var decl in cm.members)
            {
                if (decl is procedure_header || decl is procedure_definition)
                    decl.visit(this);
            }
            base.visit(cm);
        }*/

        type_declarations GenClassesForYield(procedure_definition pd,
            IEnumerable<var_def_statement> fields, // локальные переменные
            IDictionary<string, string> localsMap, // отображение для захваченных имен локальных переменных
            IDictionary<string, string> formalParamsMap//, // отображение для захваченных имен формальных параметров
            //IDictionary<var_def_statement, var_def_statement> localsCloneMap // отображение для оберток локальных переменных 
            ) 
        {
            var fh = (pd.proc_header as function_header);
            if (fh == null)
                throw new SyntaxError("Only functions can contain yields", "", pd.proc_header.source_context, pd.proc_header);
            var seqt = fh.return_type as sequence_type;
            if (seqt == null)
                throw new SyntaxError("Functions with yields must return sequences", "", fh.return_type.source_context, fh.return_type);

            // Теперь на месте функции генерируем класс

            // Захваченные локальные переменные
            var cm = class_members.Public;
            var capturedFields = fields.Select(vds =>
                                    {
                                        ident_list ids = new ident_list(vds.vars.idents.Select(id => new ident(localsMap[id.name])).ToArray());
                                        if (vds.vars_type == null) //&& vds.inital_value != null)
                                        {
                                            if (vds.inital_value != null)
                                            {
                                                //return new var_def_statement(ids, new yield_unknown_expression_type(localsCloneMap[vds], varsTypeDetectorHelper), null);
                                                return new var_def_statement(ids, new yield_unknown_expression_type(vds), null); // SSM - убрал localsCloneMap[vds] - заменил на vds - не знаю, зачем вообще это отображение делалось - всё равно оно было тождественным!!!
                                            }
                                            else
                                            {
                                                throw new SyntaxVisitorError("Variable defenition without type and value!",vds.source_context); // SSM - быть такого не может - грамматика не пропустит
                                            }
                                        }
                                        else
                                        {
                                            return new var_def_statement(ids, vds.vars_type, null);
                                        }
                                        
                                        //return new var_def_statement(ids, vds.vars_type, vds.inital_value);
                                    });

            foreach (var m in capturedFields)
                cm.Add(m);

            // Параметры функции
            List<ident> lid = new List<ident>();
            var pars = fh.parameters;
            if (pars != null)
                foreach (var ps in pars.params_list)
                {
                    if (ps.param_kind != parametr_kind.none)
                        throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_VAR_CONST_PARAMS_MODIFIERS", pars.source_context);
                    if (ps.inital_value != null)
                        throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_DEFAULT_PARAMETERS", pars.source_context);
                    //var_def_statement vds = new var_def_statement(ps.idents, ps.vars_type);
                    ident_list ids = new ident_list(ps.idents.list.Select(id => new ident(formalParamsMap[id.name])).ToArray());
                    var_def_statement vds = new var_def_statement(ids, ps.vars_type);
                    cm.Add(vds); // все параметры функции делаем полями класса
                    //lid.AddRange(vds.vars.idents);
                    lid.AddRange(ps.idents.list);
                }

            var stels = seqt.elements_type;

            var iteratorClassName = GetClassName(pd);

            // frninja 08/18/15 - Для захвата self
            if (iteratorClassName != null)
            {
                // frninja 20/04/16 - поддержка шаблонных классов
                var iteratorClassRef = CreateClassReference(iteratorClassName);

                cm.Add(new var_def_statement(YieldConsts.Self, iteratorClassRef));
            }

            var GetEnumeratorBody = new statement_list();

            // Системные поля и методы для реализации интерфейса IEnumerable
            cm.Add(new var_def_statement(YieldConsts.State, "integer"),
                new var_def_statement(YieldConsts.Current, stels),
                procedure_definition.EmptyDefaultConstructor,
                new procedure_definition("Reset"),
                new procedure_definition("MoveNext", "boolean", pd.proc_body),
                new procedure_definition("System.Collections.IEnumerator.get_Current", "object", new assign("Result", YieldConsts.Current)),
                //new procedure_definition("System.Collections.IEnumerable.GetEnumerator", "System.Collections.IEnumerator", new assign("Result", "Self"))
                new procedure_definition("System.Collections.IEnumerable.GetEnumerator", "System.Collections.IEnumerator", GetEnumeratorBody)
                );

            // frninja 20/04/16 - поддержка шаблонных классов
            var yieldClassName = NewYieldClassName();
            var yieldClassHelperName = yieldClassName + "Helper";

            var className = this.CreateHelperClassName(yieldClassName, iteratorClassName, pd);
            var classNameHelper = this.CreateHelperClassName(yieldClassHelperName, iteratorClassName, pd);
            

            var interfaces = new named_type_reference_list("System.Collections.IEnumerator", "System.Collections.IEnumerable");

            // frninja 24/04/16 - поддержка шаблонных классов
            //var td = new type_declaration(classNameHelper, this.CreateHelperClassDefinition(classNameHelper, pd, interfaces, cm));
                //SyntaxTreeBuilder.BuildClassDefinition(interfaces, cm));

            // Изменение тела процедуры
            

            // frninja 20/04/16 - поддержка шаблонных классов
            var stl = new statement_list(new var_statement("$res", new new_expr(this.CreateClassReference(className), new expression_list())));
            

            //stl.AddMany(lid.Select(id => new assign(new dot_node("$res", id), id)));
            stl.AddMany(lid.Select(id => new assign(new dot_node("$res", new ident(formalParamsMap[id.name])), id)));

            // frninja 08/12/15 - захват self
            if (iteratorClassName != null && !pd.proc_header.class_keyword)
            {
                stl.Add(new assign(new dot_node("$res", YieldConsts.Self), new ident("self")));
            }

            stl.Add(new assign("Result", "$res"));

            // New body
            pd.proc_body = new block(stl);

            if (iteratorClassName != null)
            {
                var cd = UpperTo<class_definition>();
                if (cd != null)
                {
                    // Если метод описан в классе 
                    // frninja 10/12/15 - заменить на function_header и перенести описание тела в declarations
                    Replace(pd, fh);
                    var decls = UpperTo<declarations>();
                    if (decls != null)
                    {
                        // frninja 12/05/16 - забыли копировать return
                        function_header nfh = ObjectCopier.Clone(fh);
                        //function_header nfh = new function_header();
                        //nfh.name = new method_name(fh.name.meth_name.name);

                        // Set className
                        nfh.name.class_name = iteratorClassName;
                        //nfh.parameters = fh.parameters;
                        //nfh.proc_attributes = fh.proc_attributes;
                        //nfh.return_type = fh.return_type;

                        procedure_definition npd = new procedure_definition(nfh, new block(stl));

                        // Update header
                        //pd.proc_header.className.class_name = GetClassName(pd);
                        // Add to decls
                        decls.Add(npd);
                    }
                }
            }

            // Второй класс

            var tpl = new template_param_list(stels);

            var IEnumeratorT = new template_type_reference("System.Collections.Generic.IEnumerator", tpl);

            var cm1 = cm.Add( //class_members.Public.Add(
                //procedure_definition.EmptyDefaultConstructor,
                new procedure_definition(new function_header("get_Current", stels), new assign("Result", YieldConsts.Current)),
                new procedure_definition(new function_header("GetEnumerator", IEnumeratorT), GetEnumeratorBody),
                new procedure_definition("Dispose")
            );


            // frninja 20/04/16 - поддержка шаблонных классов
            var interfaces1 = new named_type_reference_list(/*this.CreateClassReference(classNameHelper) as named_type_reference*/);
            var IEnumerableT = new template_type_reference("System.Collections.Generic.IEnumerable", tpl);

            interfaces1.Add(IEnumerableT).Add(IEnumeratorT);

            // frninja 24/04/16 - поддержка шаблонных классов

            // frninja 05/06/16 - фикс. Поддержка where секции
            var helperClassDefinition = this.CreateHelperClassDefinition(className, pd, interfaces1, cm1);
            helperClassDefinition.where_section = this.GetMethodWhereSection(pd);

            var td1 = new type_declaration(className, helperClassDefinition);
            //SyntaxTreeBuilder.BuildClassDefinition(interfaces1, cm1));


            var stl1 = new statement_list(new var_statement("$res", new new_expr(this.CreateClassReference(className), new expression_list())));
            

            stl1.AddMany(lid.Select(id => new assign(new dot_node("$res", new ident(formalParamsMap[id.name])), new ident(formalParamsMap[id.name]))));

            // Переприсваивание self 
            if (iteratorClassName != null && !pd.proc_header.class_keyword)
            {
                stl1.Add(new assign(new dot_node("$res", YieldConsts.Self), new ident(YieldConsts.Self)));
            }

            stl1.Add(new assign("Result", "$res"));


            GetEnumeratorBody.Add(new if_node(new bin_expr(new ident(YieldConsts.State), new int32_const(0), Operators.Equal),
                new assign("Result", "Self"),
                stl1));

            var cct = new type_declarations(/*td*/);
            cct.Add(td1);

            return cct;
        }
public void constructor_rec_var(statement_list body, new_expr n_e)
{
    ident id = null;
    string name_corteg = "";
    for (int ii = 2; ii < n_e.params_list.expressions.Count; ii++)
        if (n_e.params_list.expressions[ii] is ident)
            name_corteg += ((ident)n_e.params_list.expressions[ii]).name;
    if (name_corteg=="")
        name_corteg = "$$";
    name_corteg+=rec_num;
    rec_num++;
    id = new ident(name_corteg);
    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);
    for (int ii = 2; ii < n_e.params_list.expressions.Count; ii++)
    {
        if (n_e.params_list.expressions[ii] is ident)
        {
            ident id1 = (ident)n_e.params_list.expressions[ii];
            ident_list _ident_list = new ident_list();
            _ident_list.idents.Add(id1);
            typed_parameters _typed_parametres = null;
            named_type_reference _named_type_reference = new named_type_reference();
            ident idtype = new ident("datatype");
            _named_type_reference.names.Add(idtype);
            var_def_statement _var_def_statement = new var_def_statement(_ident_list, (type_definition)_named_type_reference, null, definition_attribute.None, false);
            var_statement _var_statement = new var_statement(_var_def_statement);
            body.subnodes.Add(_var_statement);
        }
        else
            constructor_rec_var(body, (new_expr)n_e.params_list.expressions[ii]);
    }
}
예제 #25
0
        public var_def_statement NewVarOrIdentifier(ident identifier, named_type_reference fptype, LexLocation loc)
        {
            var n_t_r = fptype;
			var vds = new var_def_statement();
			vds.vars = new ident_list();
			vds.vars.idents.Add(identifier);
			vds.vars_type = n_t_r;
            vds.source_context = loc;
			return vds;
        }
예제 #26
0
		private List<declaration> get_field_declaration(ICSharpCode.NRefactory.Ast.FieldDeclaration vd)
		{
			List<declaration> fields = new List<declaration>();
			bool is_static = (vd.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Static) == ICSharpCode.NRefactory.Ast.Modifiers.Static;
			foreach (ICSharpCode.NRefactory.Ast.VariableDeclaration vard in vd.Fields)
			{
				var_def_statement vds = new var_def_statement();
				vds.source_context = get_source_context(vd);
				vds.vars_type = get_type_reference(vard.TypeReference);
				ident_list idents = new ident_list();
				ident name = new ident(vard.Name);
				name.source_context = vds.source_context;
				idents.idents.Add(name);
				vds.vars = idents;
				if (is_static)
				vds.var_attr = definition_attribute.Static;
				fields.Add(vds);
			}
			return fields;
		}
예제 #27
0
		public void visit(var_def_statement _var_def_statement)
		{
			bw.Write((Int16)19);
			write_var_def_statement(_var_def_statement);
		}
예제 #28
0
		private void get_var_statement(statement_list sl, ICSharpCode.NRefactory.Ast.LocalVariableDeclaration var)
		{
			foreach (ICSharpCode.NRefactory.Ast.VariableDeclaration vd in var.Variables)
			{
				var_def_statement vds = new var_def_statement();
				vds.source_context = get_source_context(var);
				vds.vars_type = get_type_reference(vd.TypeReference);
				ident_list idents = new ident_list();
				ident name = new ident(vd.Name);
				name.source_context = get_source_context(var);
				idents.idents.Add(name);
				vds.vars = idents;
				sl.subnodes.Add(new var_statement(vds));
			}
		}
        /*public override void visit(class_members cm)
        {
            foreach (var decl in cm.members)
            {
                if (decl is procedure_header || decl is procedure_definition)
                    decl.visit(this);
            }
            base.visit(cm);
        }*/
        type_declarations GenClassesForYield(procedure_definition pd, IEnumerable<var_def_statement> fields,
            IDictionary<string, string> localsMap,
            IDictionary<string, string> formalParamsMap)
        {
            var fh = (pd.proc_header as function_header);
            if (fh == null)
                throw new SyntaxError("Only functions can contain yields", "", pd.proc_header.source_context, pd.proc_header);
            var seqt = fh.return_type as sequence_type;
            if (seqt == null)
                throw new SyntaxError("Functions with yields must return sequences", "", fh.return_type.source_context, fh.return_type);

            // Теперь на месте функции генерируем класс

            // Захваченные переменные
            var cm = class_members.Public;
            var capturedFields = fields.Select(vds =>
                                    {
                                        ident_list ids = new ident_list(vds.vars.idents.Select(id => new ident(localsMap[id.name])).ToArray());
                                        return new var_def_statement(ids, vds.vars_type, vds.inital_value);
                                    });

            foreach (var m in capturedFields)
                cm.Add(m);

            // Параметры функции
            List<ident> lid = new List<ident>();
            var pars = fh.parameters;
            if (pars != null)
                foreach (var ps in pars.params_list)
                {
                    if (ps.param_kind != parametr_kind.none)
                        throw new SyntaxError("Parameters of functions with yields must not have 'var', 'const' or 'params' modifier", "", pars.source_context, pars);
                    if (ps.inital_value != null)
                        throw new SyntaxError("Parameters of functions with yields must not have initial values", "", pars.source_context, pars);
                    //var_def_statement vds = new var_def_statement(ps.idents, ps.vars_type);
                    ident_list ids = new ident_list(ps.idents.list.Select(id => new ident(formalParamsMap[id.name])).ToArray());
                    var_def_statement vds = new var_def_statement(ids, ps.vars_type);
                    cm.Add(vds); // все параметры функции делаем полями класса
                    //lid.AddRange(vds.vars.idents);
                    lid.AddRange(ps.idents.list);
                }

            var stels = seqt.elements_type;

            // frninja 08/18/15 - Для захвата self
            if ((object)GetClassName(pd) != null)
                cm.Add(new var_def_statement(Consts.Self, GetClassName(pd).name));

            // Системные поля и методы для реализации интерфейса IEnumerable
            cm.Add(new var_def_statement(Consts.State, "integer"),
                new var_def_statement(Consts.Current, stels),
                procedure_definition.EmptyDefaultConstructor,
                new procedure_definition("Reset"),
                new procedure_definition("MoveNext", "boolean", pd.proc_body),
                new procedure_definition("get_Current", "object", new assign("Result", Consts.Current)),
                new procedure_definition("GetEnumerator", "System.Collections.IEnumerator", new assign("Result", "Self"))
                );

            var className = newClassName();
            var classNameHelper = className + "Helper";

            var interfaces = new named_type_reference_list("System.Collections.IEnumerator", "System.Collections.IEnumerable");
            var td = new type_declaration(classNameHelper, SyntaxTreeBuilder.BuildClassDefinition(interfaces, cm));

            // Изменение тела процедуры

            var stl = new statement_list(new var_statement("res", new new_expr(className)));
            //stl.AddMany(lid.Select(id => new assign(new dot_node("res", id), id)));
            stl.AddMany(lid.Select(id => new assign(new dot_node("res", new ident(formalParamsMap[id.name])), id)));

            // frninja 08/12/15 - захват self
            if ((object)GetClassName(pd) != null)
                stl.Add(new assign(new dot_node("res", Consts.Self), new ident("self")));

            stl.Add(new assign("Result", "res"));

            // New body
            pd.proc_body = new block(stl);

            if ((object)GetClassName(pd) != null)
            {
                // frninja 10/12/15 - заменить на function_header и перенести описание тела в declarations
                Replace(pd, fh);
                var decls = UpperTo<declarations>();
                if ((object)decls != null)
                {
                    function_header nfh = new function_header();
                    nfh.name = new method_name(fh.name.meth_name.name);
                    // Set name
                    nfh.name.class_name = GetClassName(pd);
                    nfh.parameters = fh.parameters;
                    nfh.proc_attributes = fh.proc_attributes;

                    procedure_definition npd = new procedure_definition(nfh, new block(stl));

                    // Update header
                    //pd.proc_header.name.class_name = GetClassName(pd);
                    // Add to decls
                    decls.Add(npd);
                }
            }

            // Второй класс

            var tpl = new template_param_list(stels);

            var IEnumeratorT = new template_type_reference("System.Collections.Generic.IEnumerator", tpl);

            var cm1 = class_members.Public.Add(
                procedure_definition.EmptyDefaultConstructor,
                new procedure_definition(new function_header("get_Current", stels), new assign("Result", Consts.Current)),
                new procedure_definition(new function_header("GetEnumerator", IEnumeratorT), new assign("Result", "Self")),
                new procedure_definition("Dispose")
            );

            var interfaces1 = new named_type_reference_list(classNameHelper);
            var IEnumerableT = new template_type_reference("System.Collections.Generic.IEnumerable", tpl);

            interfaces1.Add(IEnumerableT).Add(IEnumeratorT);

            var td1 = new type_declaration(className, SyntaxTreeBuilder.BuildClassDefinition(interfaces1, cm1));

            var cct = new type_declarations(td);
            cct.Add(td1);

            return cct;
        }
예제 #30
0
		private void add_module_members(unit_module mod, ICSharpCode.NRefactory.Ast.TypeDeclaration td)
		{
			foreach (ICSharpCode.NRefactory.Ast.INode node in td.Children)
			{
				if (node is ICSharpCode.NRefactory.Ast.FieldDeclaration)
				{
					ICSharpCode.NRefactory.Ast.FieldDeclaration vd = node as ICSharpCode.NRefactory.Ast.FieldDeclaration;
					if ((vd.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Dim) == ICSharpCode.NRefactory.Ast.Modifiers.Dim)
					foreach (ICSharpCode.NRefactory.Ast.VariableDeclaration vard in vd.Fields)
					{
						var_def_statement vds = new var_def_statement();
						vds.source_context = get_source_context(vd);
						vds.vars_type = get_type_reference(vard.TypeReference);
						ident_list idents = new ident_list();
						ident name = new ident(vard.Name);
						name.source_context = vds.source_context;
						idents.idents.Add(name);
						vds.vars = idents;
						mod.interface_part.interface_definitions.defs.Add(vds);
					}
					else if ((vd.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Const) == ICSharpCode.NRefactory.Ast.Modifiers.Const)
					foreach (ICSharpCode.NRefactory.Ast.VariableDeclaration vard in vd.Fields)
					{
						const_definition tcd = null;
						if (vard.TypeReference is ICSharpCode.NRefactory.Ast.TypeReference)
							tcd = new simple_const_definition();
						else
							tcd = new typed_const_definition();
						tcd.source_context = get_source_context(vd);
						if (tcd is typed_const_definition)
							(tcd as typed_const_definition).const_type = get_type_reference(vard.TypeReference);
						tcd.const_name = new ident(vard.Name);
						tcd.const_name.source_context = tcd.source_context;
						tcd.const_value = get_expression(vard.Initializer);
						mod.interface_part.interface_definitions.defs.Add(tcd);
					}
				}
				else if (node is ICSharpCode.NRefactory.Ast.TypeDeclaration)
				{
					mod.interface_part.interface_definitions.defs.Add(get_type_declaration(node as ICSharpCode.NRefactory.Ast.TypeDeclaration));
				}
				else if (node is ICSharpCode.NRefactory.Ast.MethodDeclaration)
				{
					ICSharpCode.NRefactory.Ast.MethodDeclaration meth = node as ICSharpCode.NRefactory.Ast.MethodDeclaration;
					if (!meth.Body.IsNull)
					mod.interface_part.interface_definitions.defs.Add(get_method_declaration(meth));
					else
					mod.interface_part.interface_definitions.defs.Add(get_method_header(meth));
				}
			}
		}