internal AlphanumericVariable CreateAlphanumericVariable(CodeElementsParser.AlphanumericVariable1Context context)
 {
     if (context.identifier() != null)
     {
         return new AlphanumericVariable(
             CreateIdentifier(context.identifier()));
     }
     else
     {
         return new AlphanumericVariable(
             CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue3()));
     }
 }
 // --- Storage areas where statements results are saved ---
 internal ReceivingStorageArea CreateNumericStorageArea(CodeElementsParser.NumericStorageAreaContext context)
 {
     return new ReceivingStorageArea(StorageDataType.Numeric,
         CreateIdentifier(context.identifier()));
 }
 internal SymbolReferenceVariable CreateMethodNameVariable(CodeElementsParser.MethodNameVariableContext context)
 {
     if (context.methodNameReference() != null)
     {
         SymbolReference symbolReference = CobolWordsBuilder.CreateMethodNameReference(context.methodNameReference());
         return new SymbolReferenceVariable(StorageDataType.MethodName, symbolReference);
     }
     else
     {
         StorageArea storageArea = CreateIdentifier(context.identifier());
         return new SymbolReferenceVariable(StorageDataType.MethodName, storageArea);
     }
 }
 internal StorageArea CreateSharedStorageArea(CodeElementsParser.SharedStorageArea1Context context)
 {
     if (context == null || context.identifier() == null) return null;
     var identifier = CreateIdentifier(context.identifier());
     return identifier;
 }
        internal ConditionalExpression CreateClassCondition(CodeElementsParser.ClassConditionContext context)
        {
            SyntaxProperty<bool> invertResult = null;
            if (context.NOT() != null)
            {
                invertResult = new SyntaxProperty<bool>(
                    true,
                    ParseTreeUtils.GetFirstToken(context.NOT()));
            }

            ClassCondition classCondition = null;
            if(context.characterClassNameReference() != null)
            {
                classCondition = new ClassCondition(
                    CreateIdentifier(context.identifier()),
                    CobolWordsBuilder.CreateCharacterClassNameReference(context.characterClassNameReference()),
                    invertResult);
            }
            else
            {
                DataItemContentType contentTypeEnum = DataItemContentType.Numeric;
                if(context.dataItemContentType().ALPHABETIC() != null)
                {
                    contentTypeEnum = DataItemContentType.Alphabetic;
                }
                else if (context.dataItemContentType().ALPHABETIC_LOWER() != null)
                {
                    contentTypeEnum = DataItemContentType.AlphabeticLower;
                }
                else if (context.dataItemContentType().ALPHABETIC_UPPER() != null)
                {
                    contentTypeEnum = DataItemContentType.AlphabeticUpper;
                }
                else if (context.dataItemContentType().DBCS() != null)
                {
                    contentTypeEnum = DataItemContentType.DBCS;
                }
                else if (context.dataItemContentType().KANJI() != null)
                {
                    contentTypeEnum = DataItemContentType.Kanji;
                }
                SyntaxProperty<DataItemContentType> dataItemContentType = new SyntaxProperty<DataItemContentType>(
                    contentTypeEnum,
                    ParseTreeUtils.GetFirstToken(context.dataItemContentType()));

                classCondition = new ClassCondition(
                    CreateIdentifier(context.identifier()),
                    dataItemContentType,
                    invertResult);
            }

            return classCondition;
        }
 internal SymbolReferenceVariable CreateProgramNameOrProgramEntryOrProcedurePointerOrFunctionPointerVariable(CodeElementsParser.ProgramNameOrProgramEntryOrProcedurePointerOrFunctionPointerVariableContext context)
 {
     if (context.programNameReferenceOrProgramEntryReference() != null)
     {
         SymbolReference symbolReference = CobolWordsBuilder.CreateProgramNameReferenceOrProgramEntryReference(context.programNameReferenceOrProgramEntryReference());
         return new SymbolReferenceVariable(StorageDataType.ProgramNameOrProgramEntryOrProcedurePointerOrFunctionPointer, symbolReference);
     }
     else
     {
         StorageArea storageArea = CreateIdentifier(context.identifier());
         return new SymbolReferenceVariable(StorageDataType.ProgramNameOrProgramEntryOrProcedurePointerOrFunctionPointer, storageArea);
     }
 }
 internal Variable CreateVariable(CodeElementsParser.Variable1Context context)
 {
     if (context == null) return null;
     StorageArea storageArea = CreateIdentifier(context.identifier());
     return new Variable(storageArea);
 }
        internal NumericVariable CreateNumericVariable(CodeElementsParser.NumericVariable3Context context)
        {
            NumericVariable variable = null;
            if (context.identifier() != null)
                variable = new NumericVariable(CreateIdentifier(context.identifier()));
            if (context.numericValue() != null)
                variable = new NumericVariable(CobolWordsBuilder.CreateNumericValue(context.numericValue()));

            // Collect storage area read/writes at the code element level
            if (variable != null && variable.StorageArea != null)
            {
                this.storageAreaReads.Add(variable.StorageArea);
            }

            return variable;
        }
        internal ReceivingStorageArea CreateAlphanumericStorageArea(CodeElementsParser.AlphanumericStorageAreaContext context)
        {
            var storageArea = new ReceivingStorageArea(StorageDataType.Alphanumeric,
                CreateIdentifier(context.identifier()));

            // Collect storage area read/writes at the code element level
            this.storageAreaWrites.Add(storageArea);

            return storageArea;
        }
        internal VariableOrExpression CreateVariableOrExpression(CodeElementsParser.VariableOrExpression2Context context)
        {
            VariableOrExpression variableOrExpression = null;
            if (context.identifier() != null)
            {
                variableOrExpression = new VariableOrExpression(
                    CreateIdentifier(context.identifier()));
            }
            else if (context.numericValue() != null)
            {
                variableOrExpression = new VariableOrExpression(
                    CobolWordsBuilder.CreateNumericValue(context.numericValue()));
            }
            else if (context.alphanumericValue2() != null)
            {
                variableOrExpression = new VariableOrExpression(
                    CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue2()));
            }
            else if (context.repeatedCharacterValue1() != null)
            {
                variableOrExpression = new VariableOrExpression(
                    CobolWordsBuilder.CreateRepeatedCharacterValue(context.repeatedCharacterValue1()));
            }
            else
            {
                variableOrExpression = new VariableOrExpression(
                    CreateArithmeticExpression(context.arithmeticExpression()));
            }

            // Collect storage area read/writes at the code element level
            if (variableOrExpression.StorageArea != null)
            {
                this.storageAreaReads.Add(variableOrExpression.StorageArea);
            }

            return variableOrExpression;
        }
        internal NumericVariable CreateNumericVariable(CodeElementsParser.NumericVariable1Context context)
        {
            var variable = new NumericVariable(
                CreateIdentifier(context.identifier()));

            // Collect storage area read/writes at the code element level
            if (variable.StorageArea != null)
            {
                this.storageAreaReads.Add(variable.StorageArea);
            }

            return variable;
        }
        internal Variable CreateVariable(CodeElementsParser.Variable7Context context)
        {
            if (context == null) return null;
            Variable variable = null;
            if (context.identifier() != null) {
                variable = new Variable(CreateIdentifier(context.identifier()));
            } else
            if (context.numericValue() != null) {
                variable = new Variable(CobolWordsBuilder.CreateNumericValue(context.numericValue()));
            } else
            if (context.alphanumericValue2() != null) {
                variable = new Variable(CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue2()));
            } else {
                variable = new Variable(CobolWordsBuilder.CreateRepeatedCharacterValue(context.repeatedCharacterValue2()));
            }

            // Collect storage area read/writes at the code element level
            if (variable.StorageArea != null)
            {
                this.storageAreaReads.Add(variable.StorageArea);
            }

            return variable;
        }
        internal Variable CreateVariable(CodeElementsParser.Variable1Context context)
        {
            if (context == null) return null;
            StorageArea storageArea = CreateIdentifier(context.identifier());
            var variable = new Variable(storageArea);

            // Collect storage area read/writes at the code element level
            this.storageAreaReads.Add(storageArea);

            return variable;
        }
 // --- Storage areas shared with calling or called program ---
 internal Variable CreateSharedVariable(CodeElementsParser.SharedVariable3Context context)
 {
     Variable variable = null;
     if (context.identifier() != null) {
         StorageArea storageArea = CreateIdentifier(context.identifier());
         variable = new Variable(storageArea);
     } else
     if (context.numericValue() != null) {
         variable = new Variable(CobolWordsBuilder.CreateNumericValue(context.numericValue()));
     } else {
         variable = new Variable(CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue2()));
     }
     // Collect storage area read/writes at the code element level
     if (variable.StorageArea != null) {
         this.storageAreaReads.Add(variable.StorageArea);
     }
     return variable;
 }
 internal NumericVariable CreateNumericVariable(CodeElementsParser.NumericVariable1Context context)
 {
     return new NumericVariable(
         CreateIdentifier(context.identifier()));
 }
        internal SymbolReferenceVariable CreateProgramNameVariable(CodeElementsParser.ProgramNameVariableContext context)
        {
            SymbolReferenceVariable variable = null;
            if (context.programNameReference1() != null) {
                SymbolReference symbolReference = CobolWordsBuilder.CreateProgramNameReference(context.programNameReference1());
                variable = new SymbolReferenceVariable(StorageDataType.ProgramName, symbolReference);
            }
            if (context.identifier() != null) {
                StorageArea storageArea = CreateIdentifier(context.identifier());
                variable = new SymbolReferenceVariable(StorageDataType.ProgramName, storageArea);
            }

            // Collect storage area read/writes at the code element level
            if (variable!= null && variable.StorageArea != null)
            {
                this.storageAreaReads.Add(variable.StorageArea);
            }

            return variable;
        }
 internal NumericVariable CreateNumericVariable(CodeElementsParser.NumericVariable3Context context)
 {
     if(context.identifier() != null)
         return new NumericVariable(CreateIdentifier(context.identifier()));
     if (context.numericValue() != null)
         return new NumericVariable(CobolWordsBuilder.CreateNumericValue(context.numericValue()));
     return null;
 }
 internal Variable CreateVariable(CodeElementsParser.Variable7Context context)
 {
     if (context == null) return null;
     if (context.identifier() != null) {
         return new Variable(CreateIdentifier(context.identifier()));
     } else
     if (context.numericValue() != null) {
         return new Variable(CobolWordsBuilder.CreateNumericValue(context.numericValue()));
     } else
     if (context.alphanumericValue2() != null) {
         return new Variable(CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue2()));
     } else {
         return new Variable(CobolWordsBuilder.CreateRepeatedCharacterValue(context.repeatedCharacterValue2()));
     }
 }
 internal SymbolReferenceVariable CreateProgramNameVariable(CodeElementsParser.ProgramNameVariableContext context)
 {
     if (context.programNameReference1() != null) {
         SymbolReference symbolReference = CobolWordsBuilder.CreateProgramNameReference(context.programNameReference1());
         return new SymbolReferenceVariable(StorageDataType.ProgramName, symbolReference);
     }
     if (context.identifier() != null) {
         StorageArea storageArea = CreateIdentifier(context.identifier());
         return new SymbolReferenceVariable(StorageDataType.ProgramName, storageArea);
     }
     return null;
 }
 internal VariableOrExpression CreateVariableOrExpression(CodeElementsParser.VariableOrExpression2Context context)
 {
     if (context.identifier() != null)
     {
         return new VariableOrExpression(
             CreateIdentifier(context.identifier()));
     }
     else if (context.numericValue() != null)
     {
         return new VariableOrExpression(
             CobolWordsBuilder.CreateNumericValue(context.numericValue()));
     }
     else if (context.alphanumericValue2() != null)
     {
         return new VariableOrExpression(
             CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue2()));
     }
     else if (context.repeatedCharacterValue1() != null)
     {
         return new VariableOrExpression(
             CobolWordsBuilder.CreateRepeatedCharacterValue(context.repeatedCharacterValue1()));
     }
     else
     {
         return new VariableOrExpression(
             CreateArithmeticExpression(context.arithmeticExpression()));
     }
 }
 internal Variable CreateVariable(CodeElementsParser.Variable3Context context)
 {
     if (context.identifier() != null)
     {
         StorageArea storageArea = CreateIdentifier(context.identifier());
         return new Variable(storageArea);
     }
     else if(context.numericValue() != null)
     {
         return new Variable(
             CobolWordsBuilder.CreateNumericValue(context.numericValue()));
     }
     else
     {
         return new Variable(
             CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue2()));
     }
 }
        internal AlphanumericVariable CreateAlphanumericVariable(CodeElementsParser.AlphanumericVariable1Context context)
        {
            AlphanumericVariable variable = null;
            if (context.identifier() != null)
            {
                variable = new AlphanumericVariable(
                    CreateIdentifier(context.identifier()));
            }
            else
            {
                variable = new AlphanumericVariable(
                    CobolWordsBuilder.CreateAlphanumericValue(context.alphanumericValue3()));
            }

            // Collect storage area read/writes at the code element level
            if (variable.StorageArea != null)
            {
                this.storageAreaReads.Add(variable.StorageArea);
            }

            return variable;
        }