Click here to Skip to main content
15,884,237 members

Comments by T_uRRiCA_N (Top 5 by date)

T_uRRiCA_N 9-Jun-11 2:40am View    
Hi John Simmons,
sorry for scratching on your 30years "ego".
But of course it could be me, to got something wrong. So lets do it step by step and then you can correct me, where I am wrong.
Your step 0): string.replace(", ","") - I read this: replace any comma, followed by a whitespace with nothing (zero length string)
Lets do this line by line:
Origin:
DEF BOOL LB_TEST1
DEF BOOL LB_TEST2, LB_TEST3
DEF BOOL LB_TEST4[10], LB_TEST5[10,5]

DEF INT LI_TEST7
DEF INT LI_TEST8[3,4,5], LI_TEST9[3], LI_TEST10

DEF CHAN BOOL CB_TEMP1, CB_TEMP2
...
DEF NCK INT NI_TEMP5
...

string.replace leads to:

DEF BOOL LB_TEST1
DEF BOOL LB_TEST2LB_TEST3
DEF BOOL LB_TEST4[10]LB_TEST5[10,5]

DEF INT LI_TEST7
DEF INT LI_TEST8[3,4,5]LI_TEST9[3]LI_TEST10

DEF CHAN BOOL CB_TEMP1CB_TEMP2
...
DEF NCK INT NI_TEMP5
...

For all the arrays it works fine, BUT
All the scalar variables (without brackets) are melted
e.g. LB_TEST2, LB_TEST3 becomes LB_TEST2LB_TEST3
Or to make it worse:
As I wrote you, its user input, there also could be more or less space after or before the comma.
Lets take LI_TEST8[3,4,5],LI_TEST9[3],LI_TEST10 as input.
This still is: LI_TEST8[3,4,5],LI_TEST9[3],LI_TEST10

I understand, that normalizing data is important here, but the algorithm is not perfect, because the same char is separating variables AND array-ranks.
So I still will use RegEx to find the occurence of a definition line and to separate description (DEF NCK INT) from naming (NI_TEMP5,NI_TEMP17[5]).
And then I start left, scan for comma and/or bracket.

By the way: Are people with 30 years of programming expierience free of misunderstandings or mistakes? With my 15 years I am far away from it. But what do I know ...
T_uRRiCA_N 9-Jun-11 2:38am View    
Deleted
Hi John Simmons,
sorry for scratching on your 30years "ego".
But of course it could be me, to got something wrong. So lets do it step by step and then you can correct me, where I am wrong.
Your step 0): string.replace(", ","") - I read this: replace any comma, followed by a whitespace with nothing (zero length string)
Lets do this line by line:
Origin:
DEF BOOL LB_TEST1
DEF BOOL LB_TEST2, LB_TEST3
DEF BOOL LB_TEST4[10], LB_TEST5[10,5]

DEF INT LI_TEST7
DEF INT LI_TEST8[3,4,5], LI_TEST9[3], LI_TEST10

DEF CHAN BOOL CB_TEMP1, CB_TEMP2
...
DEF NCK INT NI_TEMP5
...

string.replace leads to:

DEF BOOL LB_TEST1
DEF BOOL LB_TEST2LB_TEST3
DEF BOOL LB_TEST4[10]LB_TEST5[10,5]

DEF INT LI_TEST7
DEF INT LI_TEST8[3,4,5]LI_TEST9[3]LI_TEST10

DEF CHAN BOOL CB_TEMP1CB_TEMP2
...
DEF NCK INT NI_TEMP5
...

For all the arrays it works fine, BUT
All the scalar variables (without brackets) are melted
e.g. LB_TEST2, LB_TEST3 becomes LB_TEST2LB_TEST3
Or to make it worse:
As I wrote you, its user input, there also could be more or less space after or before the comma.
Lets take LI_TEST8[3,4,5],LI_TEST9[3],LI_TEST10 as input.
This still is: LI_TEST8[3,4,5],LI_TEST9[3],LI_TEST10

I understand, that normalizing data is important here, but the algorithm is not perfect, because the same char is separating variables AND array-ranks.
So I still will use RegEx to find the occurence of a definition line and to separate description (DEF NCK INT) from naming (NI_TEMP5,NI_TEMP17[5]).
And then I start left, scan for comma and/or bracket.

By the way: Are people with 30 years of programming expierience free of misunderstandings or mistakes? With my 15 years I am far away from it. But what do I know ...
T_uRRiCA_N 8-Jun-11 11:41am View    
Sorry, this doesn't help, because the strings come from user input. It could also be "... LR_TEST4[10,5,4],LI_TEST[3,2]" or "... LR_TEST4[10,5,4], LI_TEST[3,2]".
Perhaps I should first RegEx to separate declaration (DEF CHAN INT) from variables and then Parse the variables by hand.
T_uRRiCA_N 8-Jun-11 10:17am View    
I already stumbled upon ANTLR, but was a little "afraid" of using something like this in my programm. Until now it was not necessary to include such a solution. But perhaps I should consider this in the future.
Thanks for your fast answer. But I still hope, that there is a Regex solution.
T_uRRiCA_N 22-Jul-10 12:52pm View    
Deleted
Reason for my vote of 5
Simple but effective