Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-05

A complex trouble(at least for me)

16 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Arí Ricardo Ody

Suppose the following structure:

01 a-1.
03 b-1 pic xxx.
03 b-2 pic 999.
03 b-3.
05 c-1 pic aaa.
05 c-2.
07 d-1 pic zzz.
07 d-2 pic xxx.
05 c-3 pic 99.
03 b-4 pic zzz.
03 b-5.
05 e-1 pic zzz.

All line not containing the word pic I would call a group item and the other lines will be elementary items.

I would like to wrote a routine(or program) that save each group item and the elementary items contained in a StringList. Admit that the pattern of the structure is random. The example above is only an example.

In this example:
StringList1 will contain 'a-1' '03 b-1 pic xxx.' '03 b-2 pic 999.' '03 b-4 pic zzz.'
StringList2 will contain 'b-3' '05 c-1 pic aaa.' '05 c-3 pic 99.' StringList3 will contain 'c-2' '07 d-1 pic zzz.' '07 d-2 pic xxx.' StringList4 will contain 'b-5' '05 e-1 pic zzz.'

At the end of the program I will(for example) write the StringList's to disk. But I can't write anyone before the program end.

I had thinked hard about it. I can't create StringList with a variable name. I must previously declare each one in my pascal source. How can I solve the trouble proposed?

Note that when I'm appending strings in a StringList, it's possible that I must create a new StringList(or various), put data in it(or them) and return to put data in the first StringList.

If the solution is obvious I beg your pardon. I can't find it.

David W Noon
to Arí Ricardo Ody
Arí Ricardo Ody wrote 17 lines
Suppose the following structure: 01 a-1. 03 b-1 pic xxx. 03 b-2 pic 999. 03 b-3. 05 c-1 pic aaa. 05 c-2. 07 d-1 pic zzz. 07 d-2 pic xxx. 05 c-3 pic 99. 03 b-4 pic zzz. 03 b-5. 05 e-1 pic zzz. All line not containing the word pic I would call a group item and the other lines will be elementary items.

This is loosely COBOL source code.

Show quoted text 12 lines
I would like to wrote a routine(or program) that save each group item and the elementary items contained in a StringList. Admit that the pattern of the structure is random. The example above is only an example. In this example: StringList1 will contain 'a-1' '03 b-1 pic xxx.' '03 b-2 pic 999.' '03 b-4 pic zzz.' StringList2 will contain 'b-3' '05 c-1 pic aaa.' '05 c-3 pic 99.' StringList3 will contain 'c-2' '07 d-1 pic zzz.' '07 d-2 pic xxx.' StringList4 will contain 'b-5' '05 e-1 pic zzz.'

Do you want to put the COBOL source into a TStringList?

Are you trying to write a COBOL compiler?

If not, what are you trying to do?

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================
Cox, Stuart TRAN:EX
to David W Noon

There's some interesting ideas on how to store hierarchical data in tabular form available by googling "how can I represent hierarchal data in a relational database?"

You might be able to linearize your hierarchical structure's data by using the techniques found there.

Stu Cox
Project Management Technician
Southern Interior Region
Ministry of Transportation and Infrastructure
342-447 Columbia St.,
Kamloops, BC V2C 2T3
p: 250-828-4320
f: 250-828-4229

Earlier message 52 lines
-----Original Message----- From: On Behalf Of David W Noon Sent: Thursday, May 7, 2009 3:40 PM To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] A complex trouble(at least for me) On Thu, 2009-05-07 at 18:12 -0300, Arí Ricardo Ody wrote: > Suppose the following structure: > > 01 a-1. > 03 b-1 pic xxx. > 03 b-2 pic 999. > 03 b-3. > 05 c-1 pic aaa. > 05 c-2. > 07 d-1 pic zzz. > 07 d-2 pic xxx. > 05 c-3 pic 99. > 03 b-4 pic zzz. > 03 b-5. > 05 e-1 pic zzz. > > All line not containing the word pic I would call a group item and the > other lines will be elementary items. This is loosely COBOL source code. > > I would like to wrote a routine(or program) that save each group item > and the elementary items contained in a StringList. Admit that the > pattern of the structure is random. The example above is only an > example. > > In this example: > StringList1 will contain 'a-1' '03 b-1 pic xxx.' '03 b-2 pic 999.' '03 > b-4 pic zzz.' > StringList2 will contain 'b-3' '05 c-1 pic aaa.' '05 c-3 pic 99.' > StringList3 will contain 'c-2' '07 d-1 pic zzz.' '07 d-2 pic xxx.' > StringList4 will contain 'b-5' '05 e-1 pic zzz.' Do you want to put the COBOL source into a TStringList? > Are you trying to write a COBOL compiler? If not, what are you trying to do? -- Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================
Martin Friebe
to Arí Ricardo Ody: Suppose the following structure: 01 a-1. 03 b-1 pic xxx. 03 b-2 pic 999. 03 b-3. 05 c-1…
Arí Ricardo Ody wrote 35 lines
Suppose the following structure: 01 a-1. 03 b-1 pic xxx. 03 b-2 pic 999. 03 b-3. 05 c-1 pic aaa. 05 c-2. 07 d-1 pic zzz. 07 d-2 pic xxx. 05 c-3 pic 99. 03 b-4 pic zzz. 03 b-5. 05 e-1 pic zzz. All line not containing the word pic I would call a group item and the other lines will be elementary items. I would like to wrote a routine(or program) that save each group item and the elementary items contained in a StringList. Admit that the pattern of the structure is random. The example above is only an example. In this example: StringList1 will contain 'a-1' '03 b-1 pic xxx.' '03 b-2 pic 999.' '03 b-4 pic zzz.' StringList2 will contain 'b-3' '05 c-1 pic aaa.' '05 c-3 pic 99.' StringList3 will contain 'c-2' '07 d-1 pic zzz.' '07 d-2 pic xxx.' StringList4 will contain 'b-5' '05 e-1 pic zzz.' At the end of the program I will(for example) write the StringList's to disk. But I can't write anyone before the program end. I had thinked hard about it. I can't create StringList with a variable name. I must previously declare each one in my pascal source. How can I solve the trouble proposed?

"I can't create StringList with a variable name."

I don't know how much pascal experience you have. and I am not 100% sure what this line means, but taking a guess:
You need a way to store "stringlist2" in stringlist1 => So that if you later read the list, you can read the nested lists too?

You do not need a variable for each Stringlist you create.

Procedure AddNestedStringlist(OuterStringlist: TStringList; Text: String);
var
  InnerStringList: TStringlist;
begin
  InnerStringList := TStringlist.Create;
  OuterStringlist.AddObject(Text, InnerStringlist);
end;

Thats it. Note that there is no InnerStringlist.Free.

The stringlist you created is not bound to the variable "InnerStringlist". It is just a stringlist in memory, and any variable (of the correct type) can refer to it.

To read the variable back (you need a type cast):
NextedStringList := TStringList(OuterStringList.Objects[n]);

Before you Free OuterStringlist, you have to check for any InnerStringlist and destroy it, or you will leak memory.

Show quoted text 11 lines
Note that when I'm appending strings in a StringList, it's possible that I must create a new StringList(or various), put data in it(or them) and return to put data in the first StringList. If the solution is obvious I beg your pardon. I can't find it. * * ------------------------------------------------------------------------ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Arí Ricardo Ody
to Doug Chamberlin: I don't understand this part of your message. Does this mean you think you cannot…

Show me an example of what you are talking about
please. I think I don't understand your post.

[ ]

you wrote 13 lines
Arí Ricardo Ody wrote: >[snipped] >I can't create StringList with a variable name. >I must previously declare each one in my >pascal source. How can I solve the trouble proposed? I don't understand this part of your message. Does this mean you think you cannot dynamically create TStringList instances in your code? _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Arí Ricardo Ody
to David W Noon: This is loosely COBOL source code. Do you want to put the COBOL source into a TStringList?

It's out matter but, I'm working with legacy
modernization. The company I work deals with
legacy modernization. Mainly in mainframes

[ ]

you wrote 50 lines
On Thu, 2009-05-07 at 18:12 -0300, Arí Ricardo Ody wrote: > Suppose the following structure: > > 01 a-1. > 03 b-1 pic xxx. > 03 b-2 pic 999. > 03 b-3. > 05 c-1 pic aaa. > 05 c-2. > 07 d-1 pic zzz. > 07 d-2 pic xxx. > 05 c-3 pic 99. > 03 b-4 pic zzz. > 03 b-5. > 05 e-1 pic zzz. > > All line not containing the word pic I would call a group item and the > other lines will be elementary items. This is loosely COBOL source code. > > I would like to wrote a routine(or program) that save each group item > and the elementary items contained in a StringList. Admit that the > pattern of the structure is random. The example above is only an > example. > > In this example: > StringList1 will contain 'a-1' '03 b-1 pic xxx.' '03 b-2 pic 999.' '03 > b-4 pic zzz.' > StringList2 will contain 'b-3' '05 c-1 pic aaa.' '05 c-3 pic 99.' > StringList3 will contain 'c-2' '07 d-1 pic zzz.' '07 d-2 pic xxx.' > StringList4 will contain 'b-5' '05 e-1 pic zzz.' Do you want to put the COBOL source into a TStringList? > Are you trying to write a COBOL compiler? If not, what are you trying to do? -- Regards, Dave [RLU #314465] ======================================================================= (David W Noon) ======================================================================= _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Arí Ricardo Ody
to Doug Chamberlin: I don't understand this part of your message. Does this mean you think you cannot…

I think I don'understand 'cause I need a
TStringList with a known different nam for each
group item(as proposed in the original e-mail)

[ ]

you wrote 13 lines
Arí Ricardo Ody wrote: >[snipped] >I can't create StringList with a variable name. >I must previously declare each one in my >pascal source. How can I solve the trouble proposed? I don't understand this part of your message. Does this mean you think you cannot dynamically create TStringList instances in your code? _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Unknown author
to Arí Ricardo Ody

Have you considered using XML to represent and structure your data?

If you must do it with TStringList, you could declare a dynamic array of TStringList and instantiate the array elements at , each string entry in the TStringList can hold a pointer to any object that you declare in your application. These objects are added by calling the TStringList.AddObject method. Refer to the FPC RTL docs for more information.

//*******************************************
Arí Ricardo Ody wrote 24 lines
I think I don'understand 'cause I need a TStringList with a known different nam for each group item(as proposed in the original e-mail) [ ] At 20:51 7/5/2009, you wrote: >Arí Ricardo Ody wrote: >>[snipped] >>I can't create StringList with a variable name. >>I must previously declare each one in my >>pascal source. How can I solve the trouble proposed? > >I don't understand this part of your message. >Does this mean you think you cannot dynamically >create TStringList instances in your code? > >_______________________________________________ >fpc-pascal maillist - >http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
David W Noon
to Arí Ricardo Ody: It's out matter but, I'm working with legacy modernization. The company I work deals with…
Arí Ricardo Ody wrote
It's out matter but, I'm working with legacy modernization. The company I work deals with legacy modernization. Mainly in mainframes

So, are you trying to convert COBOL code to some more modern language?

If not, I still don't understand what you are trying to do.

Moreover, very few modern languages implement COBOL semantics, especially as regards decimal arithmetic. You will likely need to generate assembler code for your target platform, and that is even more of a "legacy" approach to software than coding in COBOL. [Note: double precision floating point does *not* implement decimal semantics, in spite of it seeming an easy substitute.] The "modern" language that is most likely to provide you with decimal capability is Java; it also runs even slower than COBOL.

Assuming you are trying to automate conversion of COBOL source to some newer language, then you will largely need to write a parser for the COBOL grammar. This is far from trivial. You will then need to write an emitter for your chosen "modern" language, so that you rebuild the COBOL semantics as exactly as possible.

From your original message, you seem to be still working on the parser.

I would suggest you use a more compiler theoretical approach than just generating a string list. If you encode the parsed COBOL source into some internal meta-language, this will make your emitter much easier to write. Better yet, if your encoding includes some semantic analysis of the COBOL source, you can optimize the generated code so that it both runs better and is easier maintained in your "modern" language.

Just my 2¢ worth.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================
Arí Ricardo Ody
to David W Noon

The conversation is becaming off topic. I
wouldn't like to discuss this matter here.

We have a great expertise in language conversor
development here. We can discuss it in private. Be my guest.

I'm needing a solution to the problem I propose.

Cheers

Ricardo
Sao Paulo - Brasiç

you wrote 45 lines
On Fri, 2009-05-08 at 09:41 -0300, Arí Ricardo Ody wrote: > It's out matter but, I'm working with legacy > modernization. The company I work deals with > legacy modernization. Mainly in mainframes So, are you trying to convert COBOL code to some more modern language? If not, I still don't understand what you are trying to do. Moreover, very few modern languages implement COBOL semantics, especially as regards decimal arithmetic. You will likely need to generate assembler code for your target platform, and that is even more of a "legacy" approach to software than coding in COBOL. [Note: double precision floating point does *not* implement decimal semantics, in spite of it seeming an easy substitute.] The "modern" language that is most likely to provide you with decimal capability is Java; it also runs even slower than COBOL. Assuming you are trying to automate conversion of COBOL source to some newer language, then you will largely need to write a parser for the COBOL grammar. This is far from trivial. You will then need to write an emitter for your chosen "modern" language, so that you rebuild the COBOL semantics as exactly as possible. >From your original message, you seem to be still working on the parser. I would suggest you use a more compiler theoretical approach than just generating a string list. If you encode the parsed COBOL source into some internal meta-language, this will make your emitter much easier to write. Better yet, if your encoding includes some semantic analysis of the COBOL source, you can optimize the generated code so that it both runs better and is easier maintained in your "modern" language. Just my 2¢ worth. -- Regards, Dave [RLU #314465] ======================================================================= (David W Noon) ======================================================================= _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Felipe Monteiro de Carvalho
to Arí Ricardo Ody

I didn't fully understand the original problems. You have already posted an example input, please add also an example output for the same input for the routine you are trying to build.

Felipe Monteiro de Carvalho
Arí Ricardo Ody

Hi Felipe!

If you was talking with me, please explain better.

[ ]

Ricardo

you wrote 9 lines
I didn't fully understand the original problems. You have already posted an example input, please add also an example output for the same input for the routine you are trying to build. -- Felipe Monteiro de Carvalho _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Mattias Gaertner
to Arí Ricardo Ody: Suppose the following structure: 01 a-1. 03 b-1 pic xxx. 03 b-2 pic 999. 03 b-3. 05 c-1…
Show quoted text 40 lines
Suppose the following structure: 01 a-1. 03 b-1 pic xxx. 03 b-2 pic 999. 03 b-3. 05 c-1 pic aaa. 05 c-2. 07 d-1 pic zzz. 07 d-2 pic xxx. 05 c-3 pic 99. 03 b-4 pic zzz. 03 b-5. 05 e-1 pic zzz. All line not containing the word pic I would call a group item and the other lines will be elementary items. I would like to wrote a routine(or program) that save each group item and the elementary items contained in a StringList. Admit that the pattern of the structure is random. The example above is only an example. In this example: StringList1 will contain 'a-1' '03 b-1 pic xxx.' '03 b-2 pic 999.' '03 b-4 pic zzz.' StringList2 will contain 'b-3' '05 c-1 pic aaa.' '05 c-3 pic 99.' StringList3 will contain 'c-2' '07 d-1 pic zzz.' '07 d-2 pic xxx.' StringList4 will contain 'b-5' '05 e-1 pic zzz.' At the end of the program I will(for example) write the StringList's to disk. But I can't write anyone before the program end. I had thinked hard about it. I can't create StringList with a variable name. I must previously declare each one in my pascal source. How can I solve the trouble proposed? Note that when I'm appending strings in a StringList, it's possible that I must create a new StringList(or various), put data in it(or them) and return to put data in the first StringList.

Sounds like a stack of TStringlist (or descendant). See unit contnrs.

If the solution is obvious I beg your pardon. I can't find it.

Mattias