private static ident_list RestrictionsToIdentList(template_param_list restrictions)
        {
            var templates = new ident_list();

            templates.source_context = restrictions.source_context;
            for (int i = 0; i < restrictions.Count; i++)
            {
                templates.Add((restrictions.params_list[i] as named_type_reference).names[0]);
            }

            return(templates);
        }
Beispiel #2
0
        public void CreateUnpackedListOfAssignments(unpacked_list_of_ident_or_list ll, List <statement> res, ident prevname, SourceContext sc)
        {
            var idlist = new ident_list();

            foreach (var llelem in ll.lst)
            {
                if (llelem.lst != null)
                {
                    var id = CreateIdent(sc);
                    // надо у этого id установить souce_context
                    idlist.Add(id);
                    CreateUnpackedListOfAssignments(llelem.lst, res, id, sc);
                }
                else
                {
                    idlist.Add(llelem.id);
                }
            }
            idlist.source_context = sc;
            var ass = new assign_var_tuple(idlist, prevname, sc);

            res.Insert(0, ass);
        }
        public override void visit(procedure_definition _procedure_definition)
        {
            bool isConstrainted = _procedure_definition.proc_header.where_defs != null &&
                                  _procedure_definition.proc_header.where_defs.defs.Any(x => x is where_typeclass_constraint);

            if (!isConstrainted)
            {
                DefaultVisit(_procedure_definition);
                return;
            }

            var header           = _procedure_definition.proc_header;
            var headerTranslated = header.Clone() as procedure_header;

            headerTranslated.where_defs = new where_definition_list();

            var additionalTemplateArgs = new ident_list();

            for (int i = 0; i < header.where_defs.defs.Count; i++)
            {
                var where = header.where_defs.defs[i];

                if (where is where_typeclass_constraint)
                {
                    var typeclassWhere = where as where_typeclass_constraint;
                    var newName        = TypeclassRestrctionToTemplateName(typeclassWhere.restriction.name, typeclassWhere.restriction.restriction_args);
                    AddAttribute(
                        newName, "__TypeclassGenericParameter",
                        new expression_list(new string_const(GetInstanceSingletonName(newName.name))));
                    additionalTemplateArgs.Add(newName);

                    // Create name for template that replaces typeclass(for ex. SumTC)
                    headerTranslated.where_defs.defs.Add(
                        GetWhereRestriction(
                            new template_type_reference(new named_type_reference("I" + typeclassWhere.restriction.name), typeclassWhere.restriction.restriction_args),
                            newName));
                }
                else
                {
                    headerTranslated.where_defs.defs.Add(where);
                }
            }

            // Add new templates devoted to constraints to template list
            // TODO: template_args can be empty, if there is no <T> or smth, need to check
            headerTranslated.template_args.idents.AddRange(additionalTemplateArgs.idents);

            var blockProc = (_procedure_definition.proc_body as block);

            foreach (var arg in additionalTemplateArgs.idents)
            {
                blockProc.program_code.AddFirst(GetInstanceSingletonVarStatement(arg.name));
            }

            //var list = _procedure_definition.proc_body.DescendantNodes().OfType<typeclass_param_list>();
            foreach (var tcr in _procedure_definition.proc_body.DescendantNodes().OfType <ident_with_templateparams>())
            {
                if (tcr.template_params is typeclass_param_list)
                {
                    // TODO: Check tcr.name - typeclass from where
                    // TODO: Check - that there is such typeclass with such args at where
                    // TODO: Ensure that we don't replace another constraint funciton call
                    var str = tcr.template_params.params_list
                              .Select(x => (x as named_type_reference).names[0].name)
                              .Aggregate((tcr.name as ident).name, (x, y) => x + y);
                    var id     = new ident(str + "Instance");
                    var parent = tcr.Parent;
                    parent.ReplaceDescendant((addressed_value)tcr, (addressed_value)id, Desc.All);
                }
                //var id = new ident(TypeclassRestrctionToTemplateName(tcr) + "Instance");
            }

            var procedureDefTranslated = new procedure_definition(
                headerTranslated, _procedure_definition.proc_body,
                _procedure_definition.is_short_definition, _procedure_definition.source_context);

            procedureDefTranslated.proc_header.attributes = _procedure_definition.proc_header.attributes;
            AddAttribute(procedureDefTranslated.proc_header, "__TypeclassRestrictedFunctionAttribute");
            Replace(_procedure_definition, procedureDefTranslated);
            visit(procedureDefTranslated);
        }
        bool VisitInstanceDeclaration(type_declaration instanceDeclaration)
        {
            var instanceDefinition = instanceDeclaration.type_def as instance_definition;

            if (instanceDefinition == null)
            {
                return(false);
            }
            var instanceName = instanceDeclaration.type_name as typeclass_restriction;

            // If it is instance of derived typelass than it should have template parameters
            var templateArgs = new ident_list();
            where_definition_list whereSection = null;
            var originalTypeclass = instancesAndRestrictedFunctions.typeclasses[instanceName.name].type_def as typeclass_definition;
            var typeclassParents  = originalTypeclass.additional_restrictions;

            if (typeclassParents != null && typeclassParents.Count > 0)
            {
                whereSection = new where_definition_list();

                for (int i = 0; i < typeclassParents.Count; i++)
                {
                    ident template_name;
                    if (typeclassParents[i] is typeclass_reference tr)
                    {
                        string name = tr.names[0].name;
                        template_name = TypeclassRestrctionToTemplateName(name, tr.restriction_args);

                        whereSection.Add(GetWhereRestriction(
                                             TypeclassReferenceToInterfaceName(name, instanceName.restriction_args),
                                             template_name));
                    }
                    else
                    {
                        throw new NotImplementedException("Should be syntactic error");
                    }
                    templateArgs.Add(template_name);
                }
            }

            List <type_definition> templateLists = instanceName.restriction_args.params_list.Concat(templateArgs.idents.Select(x => new named_type_reference(x.name)).OfType <type_definition>()).ToList();
            var parents = new named_type_reference_list(new List <named_type_reference> {
                new template_type_reference(instanceName.name, new template_param_list(templateLists)),
                new template_type_reference("I" + instanceName.name, instanceName.restriction_args)
            });
            var instanceDefTranslated =
                SyntaxTreeBuilder.BuildClassDefinition(
                    parents,
                    null, instanceDefinition.body.class_def_blocks.ToArray());

            instanceDefTranslated.template_args  = templateArgs;
            instanceDefTranslated.where_section  = whereSection;
            instanceDefTranslated.source_context = instanceDefinition.source_context;

            for (int i = 0; i < instanceDefTranslated.body.class_def_blocks.Count; i++)
            {
                var cm = instanceDefTranslated.body.class_def_blocks[i].members;

                for (int j = 0; j < cm.Count; j++)
                {
                    procedure_header header = null;
                    if (cm[j] is procedure_header ph)
                    {
                        cm[j] = ph;
                    }
                    else if (cm[j] is procedure_definition pd)
                    {
                        header = pd.proc_header;
                    }
                    header.proc_attributes.Add(new procedure_attribute("override", proc_attribute.attr_override));
                    ConvertOperatorNameIdent(header);
                }
            }

            /*
             * {
             *  // Add constructor
             *  var cm = instanceDefTranslated.body.class_def_blocks[0];
             *  var def = new procedure_definition(
             *      new constructor(),
             *      new statement_list(new empty_statement()));
             *  def.proc_body.Parent = def;
             *  def.proc_header.proc_attributes = new procedure_attributes_list();
             *
             *  cm.Add(def);
             * }
             */
            var typeName = new ident(CreateInstanceName(instanceName.restriction_args as typeclass_param_list, instanceName.name), instanceName.source_context);

            var instanceDeclTranslated = new type_declaration(typeName, instanceDefTranslated, instanceDeclaration.source_context);

            instanceDeclTranslated.attributes = instanceDeclaration.attributes;
            AddAttribute(
                instanceDeclTranslated, "__TypeclassInstanceAttribute",
                new expression_list(new string_const(TypeclassRestrictionToString(instanceName))));
            AddAttribute(instanceDeclTranslated, "__TypeclassAttribute",
                         new expression_list(new string_const(TypeclassRestrictionToString(
                                                                  (originalTypeclass.Parent as type_declaration).type_name as typeclass_restriction))));

            Replace(instanceDeclaration, instanceDeclTranslated);
            visit(instanceDeclTranslated);

            return(true);
        }
        bool VisitTypeclassDeclaration(type_declaration typeclassDeclaration)
        {
            var typeclassDefinition = typeclassDeclaration.type_def as typeclass_definition;

            if (typeclassDefinition == null)
            {
                return(false);
            }

            var typeclassName = typeclassDeclaration.type_name as typeclass_restriction;

            // TODO: typeclassDefinition.additional_restrictions - translate to usual classes

            // Creating interface

            // Get members for typeclass interface
            var interfaceMembers = new List <class_members>();

            foreach (var cm in typeclassDefinition.body.class_def_blocks)
            {
                var cmNew = (class_members)cm.Clone();

                for (int i = 0; i < cmNew.members.Count; i++)
                {
                    var member = cmNew.members[i];
                    if (member is function_header || member is procedure_header)
                    {
                        cmNew.members[i] = member;
                    }
                    else if (member is procedure_definition procDef)
                    {
                        cmNew.members[i] = procDef.proc_header;
                    }
                    AddAttribute(cmNew.members[i], "__TypeclassMemberAttribute");
                    if (cmNew.members[i] is procedure_header ph)
                    {
                        ConvertOperatorNameIdent(ph);
                    }
                }

                interfaceMembers.Add(cmNew);
            }
            var interfaceInheritance = (named_type_reference_list)typeclassDefinition.additional_restrictions?.Clone();

            if (interfaceInheritance != null)
            {
                interfaceInheritance.source_context = null;
                for (int i = 0; i < interfaceInheritance.types.Count; i++)
                {
                    if (interfaceInheritance.types[i] is typeclass_reference tr)
                    {
                        interfaceInheritance.types[i] = TypeclassReferenceToInterfaceName(tr.names[0].name, tr.restriction_args);
                    }
                    else
                    {
                        throw new NotImplementedException("Syntactic Error");
                    }
                }
            }
            var typeclassInterfaceDef =
                SyntaxTreeBuilder.BuildClassDefinition(
                    interfaceInheritance,
                    null, interfaceMembers.ToArray());

            typeclassInterfaceDef.keyword = class_keyword.Interface;
            var typeclassInterfaceName = new template_type_name("I" + typeclassName.name, RestrictionsToIdentList(typeclassName.restriction_args));
            var typeclassInterfaceDecl = new type_declaration(typeclassInterfaceName, typeclassInterfaceDef);

            typeclassInterfaceDecl.attributes = typeclassDeclaration.attributes;
            AddAttribute(
                typeclassInterfaceDecl, "__TypeclassAttribute",
                new expression_list(new string_const(TypeclassRestrictionToString(typeclassName))));


            // Creating class

            var typeclassDefTranslated =
                SyntaxTreeBuilder.BuildClassDefinition(
                    new named_type_reference_list(new template_type_reference(typeclassInterfaceName.name, typeclassName.restriction_args)),
                    null, typeclassDefinition.body.class_def_blocks.ToArray());

            typeclassDefTranslated.attribute = class_attribute.Abstract;
            for (int i = 0; i < typeclassDefTranslated.body.class_def_blocks.Count; i++)
            {
                var cm = typeclassDefTranslated.body.class_def_blocks[i].members;

                for (int j = 0; j < cm.Count; j++)
                {
                    procedure_header header = null;
                    if (cm[j] is procedure_header ph)
                    {
                        header = ph;
                        header.proc_attributes.Add(new procedure_attribute("abstract", proc_attribute.attr_abstract));
                    }
                    else if (cm[j] is procedure_definition pd)
                    {
                        header = pd.proc_header;
                        header.proc_attributes.Add(new procedure_attribute("virtual", proc_attribute.attr_virtual));
                    }

                    ConvertOperatorNameIdent(header);
                }
            }

            /*
             * {
             *  // Add constructor
             *  var cm = typeclassDefTranslated.body.class_def_blocks[0];
             *  var def = new procedure_definition(
             *      new constructor(),
             *      new statement_list(new empty_statement()));
             *  def.proc_body.Parent = def;
             *  def.proc_header.proc_attributes = new procedure_attributes_list();
             *
             *  cm.Add(def);
             * }
             */
            // Add template parameters for typeclass class(derived typeclasses)
            ident_list templates = RestrictionsToIdentList(typeclassName.restriction_args);

            if (typeclassDefinition.additional_restrictions != null)
            {
                for (int i = 0; i < typeclassDefinition.additional_restrictions.types.Count; i++)
                {
                    string name;
                    string templateName;
                    if (typeclassDefinition.additional_restrictions.types[i] is typeclass_reference tr)
                    {
                        name         = tr.names[0].name;
                        templateName = TypeclassRestrctionToTemplateName(name, tr.restriction_args).name;
                    }
                    else
                    {
                        throw new NotImplementedException("SyntaxError");
                    }

                    // Add template parameter
                    templates.Add(templateName);

                    // Add where restriction
                    if (typeclassDefTranslated.where_section == null)
                    {
                        typeclassDefTranslated.where_section = new where_definition_list();
                    }
                    typeclassDefTranslated.where_section.Add(GetWhereRestriction(
                                                                 interfaceInheritance.types[i],
                                                                 templateName));

                    // Add methods from derived typeclasses
                    var body = (instancesAndRestrictedFunctions.typeclasses[name].type_def as typeclass_definition).body;
                    foreach (var cdb in body.class_def_blocks)
                    {
                        var cdbNew = new class_members(cdb.access_mod == null ? access_modifer.none : cdb.access_mod.access_level);
                        foreach (var member in cdb.members)
                        {
                            procedure_header memberHeaderNew;

                            if (member is procedure_header || member is function_header)
                            {
                                memberHeaderNew = (procedure_header)member.Clone();
                                memberHeaderNew.source_context = null;
                            }
                            else if (member is procedure_definition procDefinition)
                            {
                                memberHeaderNew                = (procedure_header)procDefinition.proc_header.Clone();
                                memberHeaderNew.Parent         = null;
                                memberHeaderNew.source_context = null;
                            }
                            else
                            {
                                continue;
                            }

                            var variableName = templateName + "Instance";
                            var parameters   = memberHeaderNew.parameters.params_list.Aggregate(new expression_list(), (x, y) => new expression_list(x.expressions.Concat(y.idents.idents).ToList()));

                            expression methodCall = null;
                            if (memberHeaderNew.name.meth_name is operator_name_ident oni)
                            {
                                ConvertOperatorNameIdent(memberHeaderNew);
                                Debug.Assert(parameters.expressions.Count == 2, "Parameters count for operation should be equal to 2");
                                //methodCall = new bin_expr(parameters.expressions[0], parameters.expressions[1], oni.operator_type);
                            }
                            var callName = new dot_node(variableName, memberHeaderNew.name.meth_name.name);
                            methodCall = new method_call(callName, parameters);
                            statement exec = null;
                            if (memberHeaderNew is function_header)
                            {
                                exec = new assign("Result", methodCall);
                            }
                            else if (memberHeaderNew is procedure_header)
                            {
                                exec = new procedure_call(methodCall as method_call);
                            }
                            var procDef = new procedure_definition(
                                memberHeaderNew,
                                new statement_list(
                                    GetInstanceSingletonVarStatement(templateName),
                                    exec));
                            cdbNew.Add(procDef);
                        }
                        typeclassDefTranslated.body.class_def_blocks.Add(cdbNew);
                    }
                }
            }

            var typeclassNameTanslated = new template_type_name(typeclassName.name, templates, typeclassName.source_context);

            var typeclassDeclTranslated = new type_declaration(typeclassNameTanslated, typeclassDefTranslated, typeclassDeclaration.source_context);

            typeclassDeclTranslated.attributes = typeclassDeclaration.attributes;
            AddAttribute(
                typeclassDeclTranslated, "__TypeclassAttribute",
                new expression_list(new string_const(TypeclassRestrictionToString(typeclassName))));

            Replace(typeclassDeclaration, typeclassDeclTranslated);
            UpperNodeAs <type_declarations>().InsertBefore(typeclassDeclTranslated, typeclassInterfaceDecl);
            visit(typeclassInterfaceDecl);
            visit(typeclassDeclTranslated);

            return(true);
        }
Beispiel #6
0
        protected override void DoAction(int action)
        {
            switch (action)
            {
            case 2: // module -> MODULE, ident, SEMICOLUMN, Declarations, BEGIN, StatementSequence,
                    //           END, ident, COMMA
            {
                if (ValueStack[ValueStack.Depth - 8].id.name != ValueStack[ValueStack.Depth - 2].id.name)
                {
                    PT.AddError("Имя " + ValueStack[ValueStack.Depth - 2].id.name + " должно совпадать с именем модуля " + ValueStack[ValueStack.Depth - 8].id.name, LocationStack[LocationStack.Depth - 2]);
                }

                // Подключение стандартной библиотеки
                ident_list il = new ident_list();
                il.Add(new ident("Oberon00System"));
                unit_or_namespace un = new unit_or_namespace(il);
                uses_list         ul = new uses_list();
                ul.units.Insert(0, un);

                // Формирование главного модуля
                var b = new block(ValueStack[ValueStack.Depth - 6].decl, ValueStack[ValueStack.Depth - 4].sl, LocationStack[LocationStack.Depth - 6].Merge(LocationStack[LocationStack.Depth - 2]));
                var r = new program_module(null, ul, b, null, CurrentLocationSpan);
                r.Language = LanguageId.Oberon00;
                root       = r;
            }
            break;

            case 3: // module -> INVISIBLE, expr
            {       // Для Intellisense
                root = ValueStack[ValueStack.Depth - 1].ex;
            }
            break;

            case 4: // ident -> ID
            {
                CurrentSemanticValue.id = new ident(ValueStack[ValueStack.Depth - 1].sVal, CurrentLocationSpan);
            }
            break;

            case 5: // expr -> ident
            {
                CurrentSemanticValue.ex = ValueStack[ValueStack.Depth - 1].id;
            }
            break;

            case 6: // expr -> INTNUM
            {
                CurrentSemanticValue.ex = new int32_const(ValueStack[ValueStack.Depth - 1].iVal, CurrentLocationSpan);
            }
            break;

            case 7: // expr -> TRUE
            {
                CurrentSemanticValue.ex = new bool_const(true, CurrentLocationSpan);
            }
            break;

            case 8: // expr -> FALSE
            {
                CurrentSemanticValue.ex = new bool_const(false, CurrentLocationSpan);
            }
            break;

            case 9: // expr -> MINUS, expr
            {
                CurrentSemanticValue.ex = new un_expr(ValueStack[ValueStack.Depth - 1].ex, Operators.Minus, CurrentLocationSpan);
            }
            break;

            case 10: // expr -> LPAREN, expr, RPAREN
            { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth - 2].ex; }
            break;

            case 11: // expr -> NOT, expr
            {
                CurrentSemanticValue.ex = new un_expr(ValueStack[ValueStack.Depth - 1].ex, Operators.LogicalNOT, CurrentLocationSpan);
            }
            break;

            case 12: // expr -> expr, PLUS, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Plus, CurrentLocationSpan);
            }
            break;

            case 13: // expr -> expr, MINUS, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Minus, CurrentLocationSpan);
            }
            break;

            case 14: // expr -> expr, MULT, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Multiplication, CurrentLocationSpan);
            }
            break;

            case 15: // expr -> expr, DIVIDE, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.IntegerDivision, CurrentLocationSpan);
            }
            break;

            case 16: // expr -> expr, AND, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.LogicalAND, CurrentLocationSpan);
            }
            break;

            case 17: // expr -> expr, OR, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.LogicalOR, CurrentLocationSpan);
            }
            break;

            case 18: // expr -> expr, EQ, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Equal, CurrentLocationSpan);
            }
            break;

            case 19: // expr -> expr, NE, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.NotEqual, CurrentLocationSpan);
            }
            break;

            case 20: // expr -> expr, LT, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Less, CurrentLocationSpan);
            }
            break;

            case 21: // expr -> expr, LE, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.LessEqual, CurrentLocationSpan);
            }
            break;

            case 22: // expr -> expr, GT, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Greater, CurrentLocationSpan);
            }
            break;

            case 23: // expr -> expr, GE, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.GreaterEqual, CurrentLocationSpan);
            }
            break;

            case 24: // Assignment -> ident, ASSIGN, expr
            {
                CurrentSemanticValue.st = new assign(ValueStack[ValueStack.Depth - 3].id, ValueStack[ValueStack.Depth - 1].ex, Operators.Assignment, CurrentLocationSpan);
            }
            break;

            case 25: // IfStatement -> IF, expr, THEN, StatementSequence, END
            {
                CurrentSemanticValue.st = new if_node(ValueStack[ValueStack.Depth - 4].ex, ValueStack[ValueStack.Depth - 2].sl, null, CurrentLocationSpan);
            }
            break;

            case 26: // IfStatement -> IF, expr, THEN, StatementSequence, ELSE, StatementSequence, END
            {
                CurrentSemanticValue.st = new if_node(ValueStack[ValueStack.Depth - 6].ex, ValueStack[ValueStack.Depth - 4].sl, ValueStack[ValueStack.Depth - 2].sl, CurrentLocationSpan);
            }
            break;

            case 27: // WhileStatement -> WHILE, expr, DO, StatementSequence, END
            {
                CurrentSemanticValue.st = new while_node(ValueStack[ValueStack.Depth - 4].ex, ValueStack[ValueStack.Depth - 2].sl, WhileCycleType.While, CurrentLocationSpan);
            }
            break;

            case 28: // WriteStatement -> EXCLAMATION, expr
            {
                expression_list el = new expression_list(ValueStack[ValueStack.Depth - 1].ex);
                method_call     mc = new method_call(el);
                mc.dereferencing_value  = new ident("print");
                CurrentSemanticValue.st = mc;
            }
            break;

            case 29: // factparams -> expr
            {
                CurrentSemanticValue.el = new expression_list(ValueStack[ValueStack.Depth - 1].ex, CurrentLocationSpan);
            }
            break;

            case 30: // factparams -> factparams, COLUMN, expr
            {
                ValueStack[ValueStack.Depth - 3].el.Add(ValueStack[ValueStack.Depth - 1].ex, CurrentLocationSpan);
                CurrentSemanticValue.el = ValueStack[ValueStack.Depth - 3].el;
            }
            break;

            case 31: // ProcCallStatement -> ident, LPAREN, factparams, RPAREN
            {
                CurrentSemanticValue.st = new method_call(ValueStack[ValueStack.Depth - 4].id, ValueStack[ValueStack.Depth - 2].el, CurrentLocationSpan);
            }
            break;

            case 32: // EmptyStatement -> /* empty */
            {
                CurrentSemanticValue.st = new empty_statement();
            }
            break;

            case 39: // StatementSequence -> Statement
            {
                CurrentSemanticValue.sl = new statement_list(ValueStack[ValueStack.Depth - 1].st, CurrentLocationSpan);
            }
            break;

            case 40: // StatementSequence -> StatementSequence, SEMICOLUMN, Statement
            {
                ValueStack[ValueStack.Depth - 3].sl.Add(ValueStack[ValueStack.Depth - 1].st, CurrentLocationSpan);
                CurrentSemanticValue.sl = ValueStack[ValueStack.Depth - 3].sl;
            }
            break;

            case 41: // type -> BOOLEAN
            {
                CurrentSemanticValue.ntr = new named_type_reference("boolean", CurrentLocationSpan);
            }
            break;

            case 42: // type -> INTEGER
            {
                CurrentSemanticValue.ntr = new named_type_reference("integer", CurrentLocationSpan);
            }
            break;

            case 43: // IDList -> ident
            {
                CurrentSemanticValue.il = new ident_list(ValueStack[ValueStack.Depth - 1].id, CurrentLocationSpan);
            }
            break;

            case 44: // IDList -> IDList, COLUMN, ident
            {
                ValueStack[ValueStack.Depth - 3].il.Add(ValueStack[ValueStack.Depth - 1].id, CurrentLocationSpan);
                CurrentSemanticValue.il = ValueStack[ValueStack.Depth - 3].il;
            }
            break;

            case 45: // VarDecl -> IDList, COLON, type, SEMICOLUMN
            {
                CurrentSemanticValue.vds = new var_def_statement(ValueStack[ValueStack.Depth - 4].il, ValueStack[ValueStack.Depth - 2].ntr, null, definition_attribute.None, false, CurrentLocationSpan);
            }
            break;

            case 46: // VarDeclarations -> VarDecl
            {
                CurrentSemanticValue.vdss = new variable_definitions(ValueStack[ValueStack.Depth - 1].vds, CurrentLocationSpan);
            }
            break;

            case 47: // VarDeclarations -> VarDeclarations, VarDecl
            {
                ValueStack[ValueStack.Depth - 2].vdss.Add(ValueStack[ValueStack.Depth - 1].vds, CurrentLocationSpan);
                CurrentSemanticValue.vdss = ValueStack[ValueStack.Depth - 2].vdss;
            }
            break;

            case 48: // ConstDecl -> ident, EQ, ConstExpr, SEMICOLUMN
            {
                CurrentSemanticValue.scd = new simple_const_definition(ValueStack[ValueStack.Depth - 4].id, ValueStack[ValueStack.Depth - 2].ex, CurrentLocationSpan);
            }
            break;

            case 50: // ConstDeclarations -> ConstDecl
            {
                CurrentSemanticValue.cdl = new consts_definitions_list(ValueStack[ValueStack.Depth - 1].scd, CurrentLocationSpan);
            }
            break;

            case 51: // ConstDeclarations -> ConstDeclarations, ConstDecl
            {
                ValueStack[ValueStack.Depth - 2].cdl.Add(ValueStack[ValueStack.Depth - 1].scd, CurrentLocationSpan);
                CurrentSemanticValue.cdl = ValueStack[ValueStack.Depth - 2].cdl;
            }
            break;

            case 52: // ConstDeclarationsSect -> CONST, ConstDeclarations
            {
                CurrentSemanticValue.cdl = ValueStack[ValueStack.Depth - 1].cdl;
                CurrentSemanticValue.cdl.source_context = CurrentLocationSpan;
            }
            break;

            case 53: // VarDeclarationsSect -> VAR, VarDeclarations
            {
                CurrentSemanticValue.vdss = ValueStack[ValueStack.Depth - 1].vdss;
                CurrentSemanticValue.vdss.source_context = CurrentLocationSpan;
            }
            break;

            case 54: // Declarations -> VarDeclarationsSect
            {
                CurrentSemanticValue.decl = new declarations(ValueStack[ValueStack.Depth - 1].vdss, CurrentLocationSpan);
            }
            break;

            case 55: // Declarations -> ConstDeclarationsSect, VarDeclarationsSect
            {
                CurrentSemanticValue.decl = new declarations(ValueStack[ValueStack.Depth - 1].vdss, CurrentLocationSpan);
                CurrentSemanticValue.decl.Add(ValueStack[ValueStack.Depth - 1].vdss);
//		$$.source_context = @$;
            }
            break;
            }
        }