Re: [fpc-pascal] A complex trouble(at least for me)
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. 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. 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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
Show me an example of what you are talking about please. I think I don't understand your post. [ ] 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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
It's out matter but, I'm working with legacy modernization. The company I work deals with legacy modernization. Mainly in mainframes [ ] At 19:40 7/5/2009, you wrote: 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.n...@ntlworld.com (David W Noon) === ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
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 will at runtime. Also, 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. //*** On Friday 08 May 2009 15:09:36 Arí Ricardo Ody wrote: 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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
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.n...@ntlworld.com (David W Noon) === ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
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ç At 11:33 8/5/2009, you wrote: 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.n...@ntlworld.com (David W Noon) === ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
Hi Felipe! If you was talking with me, please explain better. [ ] Ricardo At 14:49 8/5/2009, you wrote: 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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
Ah, now I see that you already gave an example output ... sorry -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
On Thu, 07 May 2009 18:12:50 -0300 Arí Ricardo Ody ari@japinfo.com.br 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. 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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
No problema! At 15:01 8/5/2009, you wrote: Ah, now I see that you already gave an example output ... sorry -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
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.n...@ntlworld.com (David W Noon) === ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
RE: [fpc-pascal] A complex trouble(at least for me)
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 stuart@gov.bc.ca -Original Message- From: fpc-pascal-boun...@lists.freepascal.org [mailto:fpc-pascal-boun...@lists.freepascal.org] 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.n...@ntlworld.com (David W Noon) === ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A complex trouble(at least for me)
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 - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal