// FILE DESCRIPTION ENTRY
        ////////////////////////////
        public override void EnterFileDescriptionEntry(CodeElementsParser.FileDescriptionEntryContext context)
        {
            var entry = new FileDescriptionEntry();

            if (context.FD() != null)
                entry.LevelIndicator = new SyntaxProperty<FileDescriptionType>(FileDescriptionType.File, ParseTreeUtils.GetFirstToken(context.FD()));
            else
            if (context.SD() != null)
                entry.LevelIndicator = new SyntaxProperty<FileDescriptionType>(FileDescriptionType.SortMergeFile, ParseTreeUtils.GetFirstToken(context.SD()));

            entry.FileName = CobolWordsBuilder.CreateFileNameReference(context.fileNameReference());

            if (context.externalClause() != null && context.externalClause().Length > 0) {
                var externalClauseContext = context.externalClause()[0];
                entry.IsExternal = new SyntaxProperty<bool>(true, ParseTreeUtils.GetFirstToken(externalClauseContext.EXTERNAL()));
            }
            if (context.globalClause() != null && context.globalClause().Length > 0) {
                var globalClauseContext = context.globalClause()[0];
                entry.IsGlobal = new SyntaxProperty<bool>(true, ParseTreeUtils.GetFirstToken(globalClauseContext.GLOBAL()));
            }
            if (context.blockContainsClause() != null && context.blockContainsClause().Length > 0) {
                var blockContainsClauseContext = context.blockContainsClause()[0];
                entry.MaxBlockSize = CobolWordsBuilder.CreateIntegerValue(blockContainsClauseContext.maxNumberOfBytes);
                if (blockContainsClauseContext.minNumberOfBytes != null) {
                    entry.MinBlockSize = CobolWordsBuilder.CreateIntegerValue(blockContainsClauseContext.minNumberOfBytes);
                }
                if (blockContainsClauseContext.CHARACTERS() != null) {
                    entry.BlockSizeUnit = new SyntaxProperty<BlockSizeUnit>(BlockSizeUnit.Characters,
                        ParseTreeUtils.GetFirstToken(blockContainsClauseContext.CHARACTERS()));
                } else
                if (blockContainsClauseContext.RECORDS() != null) {
                    entry.BlockSizeUnit = new SyntaxProperty<BlockSizeUnit>(BlockSizeUnit.Records, ParseTreeUtils.GetFirstToken(blockContainsClauseContext.RECORDS()));
                }
            }
            if (context.recordClause() != null && context.recordClause().Length > 0) {
                var recordClauseContext = context.recordClause()[0];
                if (recordClauseContext.numberOfBytes != null) {
                    entry.MinRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.numberOfBytes);
                    entry.MaxRecordSize = entry.MinRecordSize;
                } else
                if (recordClauseContext.minNumberOfBytes != null) {
                    entry.MinRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.minNumberOfBytes);
                    entry.MaxRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.maxNumberOfBytes);
                } else
                if (recordClauseContext.VARYING() != null) {
                    if (recordClauseContext.fromNumberOfBytes != null)
                        entry.MinRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.fromNumberOfBytes);
                    if (recordClauseContext.toNumberOfBytes != null)
                        entry.MaxRecordSize = CobolWordsBuilder.CreateIntegerValue(recordClauseContext.toNumberOfBytes);
                    if (recordClauseContext.dataNameReference() != null)
                        entry.RecordSizeDependingOn = CobolWordsBuilder.CreateDataNameReference(recordClauseContext.dataNameReference());
                }
            }
            if (context.labelRecordsClause() != null && context.labelRecordsClause().Length > 0) {
                var labelRecordClauseContext = context.labelRecordsClause()[0];
                if (labelRecordClauseContext.STANDARD() != null) {
                    entry.LabelRecordType = new SyntaxProperty<LabelRecordType>(LabelRecordType.StandardLabels, ParseTreeUtils.GetFirstToken(labelRecordClauseContext.STANDARD()));
                }
                if (labelRecordClauseContext.OMITTED() != null) {
                    entry.LabelRecordType = new SyntaxProperty<LabelRecordType>(LabelRecordType.Omitted, ParseTreeUtils.GetFirstToken(labelRecordClauseContext.OMITTED()));
                } else
                if (labelRecordClauseContext.dataNameReference() != null && labelRecordClauseContext.dataNameReference().Length > 0) {
                    entry.LabelRecords = new SymbolReference[labelRecordClauseContext.dataNameReference().Length];
                    for (int i = 0; i < labelRecordClauseContext.dataNameReference().Length; i++)
                        entry.LabelRecords[i] = CobolWordsBuilder.CreateDataNameReference(labelRecordClauseContext.dataNameReference()[i]);
                }
            }
            if (context.valueOfClause() != null && context.valueOfClause().Length > 0) {
                var valueOfClauseContext = context.valueOfClause()[0];
                entry.ValueOfLabelRecords = new Dictionary<SymbolReference, Variable>();
                for (int i = 0; i < valueOfClauseContext.qualifiedDataName().Length; i++) {
                    entry.ValueOfLabelRecords.Add(
                        CobolWordsBuilder.CreateQualifiedDataName(valueOfClauseContext.qualifiedDataName()[i]),
                        CobolExpressionsBuilder.CreateVariable(valueOfClauseContext.variable5()[i]));
                }
            }
            if (context.dataRecordsClause() != null && context.dataRecordsClause().Length > 0) {
                var dataRecordClauseContext = context.dataRecordsClause()[0];
                entry.DataRecords = new SymbolReference[dataRecordClauseContext.dataNameReference().Length];
                for (int i = 0; i < dataRecordClauseContext.dataNameReference().Length; i++)
                    entry.DataRecords[i] = CobolWordsBuilder.CreateDataNameReference(dataRecordClauseContext.dataNameReference()[i]);
            }
            if (context.linageClause() != null && context.linageClause().Length > 0) {
                var linageClauseContext = context.linageClause()[0];
                if (linageClauseContext.numberOfLinesInPage != null)
                    entry.LogicalPageBodyLineCount = CobolExpressionsBuilder.CreateIntegerVariable(linageClauseContext.numberOfLinesInPage);
                if (linageClauseContext.firstLineNumberOfFootingArea != null)
                    entry.LogicalPageFootingLineNumber = CobolExpressionsBuilder.CreateIntegerVariable(linageClauseContext.firstLineNumberOfFootingArea);
                if (linageClauseContext.numberOfLinesInTopMargin != null)
                    entry.LogicalPageTopMarginLineCount = CobolExpressionsBuilder.CreateIntegerVariable(linageClauseContext.numberOfLinesInTopMargin);
                if (linageClauseContext.numberOfLinesInBottomMargin != null)
                    entry.LogicalPageBottomMarginLineCount = CobolExpressionsBuilder.CreateIntegerVariable(linageClauseContext.numberOfLinesInBottomMargin);
            }
            if (context.recordingModeClause() != null && context.recordingModeClause().Length > 0) {
                var recordingModeClauseContext = context.recordingModeClause()[0];
                entry.RecordingMode = CobolWordsBuilder.CreateRecordingMode(recordingModeClauseContext.recordingMode());
            }

            Context = context;
            CodeElement = entry;
        }
        public override void EnterDataDescriptionEntry(CodeElementsParser.DataDescriptionEntryContext context)
        {
            if (context.dataRenamesEntry() != null || context.dataConditionEntry() != null) {
                // For levels 66 and 88, the DataDefinitionEntry is created by the following methods
                // - EnterDataRenamesEntry
                // - EnterDataConditionEntry
                return;
            }
            if (context.redefinesClause() != null) {
                // Redefines clause is not a separate rule in the grammar for optimization puroposes,
                // but we pretend here that it is a separate rule
                EnterDataRedefinesEntry(context);
                return;
            }

            DataDescriptionEntry entry;
            // [COBOL 2002]
            if (context.cobol2002TypedefClause() != null) {
                var typedef = new DataTypeDescriptionEntry();
                typedef.DataTypeName = CobolWordsBuilder.CreateDataTypeNameDefinition(context.dataNameDefinition());
                var strong = context.cobol2002TypedefClause().STRONG();
                typedef.Strong = new SyntaxProperty<bool>(strong != null, ParseTreeUtils.GetFirstToken(strong));

                entry = typedef;
                entry.DataName = typedef.DataTypeName;
                entry.DataType = new DataType(typedef.DataTypeName.Name, typedef.IsStrong);
            }
            // [/COBOL 2002]
            else {
                entry = new DataDescriptionEntry();
                entry.DataName = CobolWordsBuilder.CreateDataNameDefinition(context.dataNameDefinition());
                entry.DataType = DataType.Unknown;
            }

            if (context.levelNumber() != null)
                entry.LevelNumber = CobolWordsBuilder.CreateIntegerValue(context.levelNumber().integerValue());

            if (context.FILLER() != null) entry.Filler = new SyntaxProperty<bool>(true, ParseTreeUtils.GetFirstToken(context.FILLER()));
            else entry.Filler = new SyntaxProperty<bool>(entry.DataName == null, null);

            if (context.pictureClause() != null && context.pictureClause().Length > 0) {
                var pictureClauseContext = context.pictureClause()[0];
                entry.Picture = CobolWordsBuilder.CreateAlphanumericValue(pictureClauseContext.pictureCharacterString);
                if (entry.DataType == DataType.Unknown) // only for a basic TYPEDEF <typename> PIC <picture>
                    entry.DataType = DataType.Create(entry.Picture.Value);
            }
            // [COBOL 2002]
            if (context.cobol2002TypeClause() != null && context.cobol2002TypeClause().Length > 0) {
                entry.UserDefinedDataType = CobolWordsBuilder.CreateDataTypeNameReference(context.cobol2002TypeClause()[0].dataTypeNameReference());
                entry.DataType = DataType.CreateCustom(entry.UserDefinedDataType.Name);
            }
            // [/COBOL 2002]
            if (context.blankWhenZeroClause() != null && context.blankWhenZeroClause().Length > 0)
            {
                var blankClauseContext = context.blankWhenZeroClause()[0];
                Token zeroToken = null;
                if (blankClauseContext.ZERO() != null)
                {
                    zeroToken = ParseTreeUtils.GetFirstToken(blankClauseContext.ZERO());
                }
                else if (blankClauseContext.ZEROS() != null)
                {
                    zeroToken = ParseTreeUtils.GetFirstToken(blankClauseContext.ZEROS());
                }
                else
                {
                    zeroToken = ParseTreeUtils.GetFirstToken(blankClauseContext.ZEROES());
                }
                entry.IsBlankWhenZero = new SyntaxProperty<bool>(true, zeroToken);
            }

            if (context.externalClause() != null && context.externalClause().Length > 0) {
                entry.External = new SyntaxProperty<bool>(true, ParseTreeUtils.GetFirstToken(context.externalClause()[0].EXTERNAL()));
            }
            if (context.globalClause() != null && context.globalClause().Length > 0) {
                entry.Global = new SyntaxProperty<bool>(true, ParseTreeUtils.GetFirstToken(context.globalClause()[0].GLOBAL()));
            }
            if (context.justifiedClause() != null && context.justifiedClause().Length > 0)
            {
                var justifiedClauseContext = context.justifiedClause()[0];
                Token justifiedToken = null;
                if (justifiedClauseContext.JUSTIFIED() != null)
                {
                    justifiedToken = ParseTreeUtils.GetFirstToken(justifiedClauseContext.JUSTIFIED());
                }
                else
                {
                    justifiedToken = ParseTreeUtils.GetFirstToken(justifiedClauseContext.JUST());
                }
                entry.IsJustified = new SyntaxProperty<bool>(true, justifiedToken);
            }
            if (context.groupUsageClause() != null && context.groupUsageClause().Length > 0)
            {
                var groupUsageClauseContext = context.groupUsageClause()[0];
                entry.IsJustified = new SyntaxProperty<bool>(true,
                    ParseTreeUtils.GetFirstToken(groupUsageClauseContext.NATIONAL()));
            }
            if (context.occursClause() != null && context.occursClause().Length > 0)
            {
                var occursClauseContext = context.occursClause()[0];
                if (occursClauseContext.minNumberOfOccurences != null)
                {
                    entry.MinOccurencesCount = CobolWordsBuilder.CreateIntegerValue(occursClauseContext.minNumberOfOccurences);
                }
                if (occursClauseContext.maxNumberOfOccurences != null)
                {
                    entry.MaxOccurencesCount = CobolWordsBuilder.CreateIntegerValue(occursClauseContext.maxNumberOfOccurences);
                }
                if (entry.MinOccurencesCount == null && entry.MaxOccurencesCount != null)
                {
                    entry.MinOccurencesCount = entry.MaxOccurencesCount;
                }
                if (occursClauseContext.UNBOUNDED() != null)
                {
                    entry.HasUnboundedNumberOfOccurences = new SyntaxProperty<bool>(true,
                        ParseTreeUtils.GetFirstToken(occursClauseContext.UNBOUNDED()));
                }
                if (occursClauseContext.varNumberOfOccurences != null)
                {
                    entry.OccursDependingOn = CobolExpressionsBuilder.CreateNumericVariable(occursClauseContext.varNumberOfOccurences);
                }
                if (occursClauseContext.tableSortingKeys() != null && occursClauseContext.tableSortingKeys().Length > 0)
                {
                    int keysCount = 0;
                    foreach (var tableSortingKeysContext in occursClauseContext.tableSortingKeys())
                    {
                        keysCount += tableSortingKeysContext.dataNameReference().Length;
                    }
                    entry.TableSortingKeys = new TableSortingKey[keysCount];
                    int keyIndex = 0;
                    foreach (var tableSortingKeysContext in occursClauseContext.tableSortingKeys())
                    {
                        SyntaxProperty<SortDirection> sortDirection = null;
                        if (tableSortingKeysContext.ASCENDING() != null)
                        {
                            sortDirection = new SyntaxProperty<SortDirection>(SortDirection.Ascending,
                                ParseTreeUtils.GetFirstToken(tableSortingKeysContext.ASCENDING()));
                        }
                        else
                        {
                            sortDirection = new SyntaxProperty<SortDirection>(SortDirection.Descending,
                                ParseTreeUtils.GetFirstToken(tableSortingKeysContext.DESCENDING()));
                        }
                        foreach (var dataNameReference in tableSortingKeysContext.dataNameReference())
                        {
                            SymbolReference sortKey = CobolWordsBuilder.CreateDataNameReference(dataNameReference);
                            entry.TableSortingKeys[keyIndex] = new TableSortingKey(sortKey, sortDirection);
                            keyIndex++;
                        }
                    }
                }
                if (occursClauseContext.indexNameDefinition() != null && occursClauseContext.indexNameDefinition().Length > 0)
                {
                    entry.Indexes = new SymbolDefinition[occursClauseContext.indexNameDefinition().Length];
                    for (int i = 0; i < occursClauseContext.indexNameDefinition().Length; i++)
                    {
                        var indexNameDefinition = occursClauseContext.indexNameDefinition()[i];
                        entry.Indexes[i] = CobolWordsBuilder.CreateIndexNameDefinition(indexNameDefinition);
                    }
                }
            }
            if (context.signClause() != null && context.signClause().Length > 0)
            {
                var signClauseContext = context.signClause()[0];
                if (signClauseContext.LEADING() != null)
                {
                    entry.SignPosition = new SyntaxProperty<SignPosition>(SignPosition.Leading,
                        ParseTreeUtils.GetFirstToken(signClauseContext.LEADING()));
                }
                else
                {
                    entry.SignPosition = new SyntaxProperty<SignPosition>(SignPosition.Trailing,
                        ParseTreeUtils.GetFirstToken(signClauseContext.TRAILING()));
                }
                if (signClauseContext.SEPARATE() != null)
                {
                    entry.SignIsSeparate = new SyntaxProperty<bool>(true,
                        ParseTreeUtils.GetFirstToken(signClauseContext.SEPARATE()));
                }
            }
            if (context.synchronizedClause() != null && context.synchronizedClause().Length > 0)
            {
                var synchronizedClauseContext = context.synchronizedClause()[0];
                if (synchronizedClauseContext.SYNCHRONIZED() != null)
                {
                    entry.IsSynchronized = new SyntaxProperty<bool>(true,
                        ParseTreeUtils.GetFirstToken(synchronizedClauseContext.SYNCHRONIZED()));
                }
                else
                {
                    entry.IsSynchronized = new SyntaxProperty<bool>(true,
                        ParseTreeUtils.GetFirstToken(synchronizedClauseContext.SYNC()));
                }
            }
            if (context.usageClause() != null && context.usageClause().Length > 0) {
                entry.Usage = CreateUsageClause(context.usageClause()[0]);
            }
            if (context.valueClause() != null && context.valueClause().Length > 0)
            {
                var valueClauseContext = context.valueClause()[0];
                entry.InitialValue = CobolWordsBuilder.CreateValue(valueClauseContext.value2());
            }

            Context = context;
            CodeElement = entry;
        }