15,884,237 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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