LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate Syntax in string format

Hello all,

 

I need small help. Please help me.

 

I want to validate some syntaxes like below. Is there is any default LabVIEW function for this?

 

OK Type:

(((1 AND 2) OR 3) OR 4)

(((1 AND 2) OR (3 OR 4)) OR 5)

 

NG Type:

((1 AND 2) OR (3 OR 4) OR 5)

(( 1 AND 2 OR 3) OR 6)

(1 AND 3 OR 3

 

I need to check above syntax is correct or not (like brackets are properly opened & closed, AND/OR etc.).

I created sample VI for this but in some cases it is giving wrong result (eg: ((1 AND 2) OR (3 OR 4) OR 5)) .

Munna
0 Kudos
Message 1 of 10
(4,637 Views)

Brackets should be easy enough - the number of times "(" appears" is the same as ")" and the first and last instance of each must be those respectively.

0 Kudos
Message 2 of 10
(4,628 Views)

we cant judge syntax only by open & close bracket.

 

For example. ((1 AND 2) OR (3 OR 4) OR 5)

Here "(" count is same as  ")" but it is NG case.

 

Correct Synatax: (((1 AND 2) OR (3 OR 4)) OR 5)

Munna
0 Kudos
Message 3 of 10
(4,621 Views)

@Munna232 wrote:

we cant judge syntax only by open & close bracket.

 

For example. ((1 AND 2) OR (3 OR 4) OR 5))

Here "(" count is same as  ")" but it is NG case.

 

Correct Synatax: (((1 AND 2) OR (3 OR 4)) OR 5))


Your NG example has 3 "(" and 4 ")". So I'm not sure I understand your point. But you also haven't clarified what rules you are trying to enforce or any other context for your question. Until you do I don't think I can help.

 

EDIT - I see you have updated your example to fix the last ")". But I still don't understand what you are trying to achieve. If 1 to 5 are boolean inputs then your NG example is perfectly valid boolean arithmetic syntax. You need to provide a better context for what you are trying to achieve.

0 Kudos
Message 4 of 10
(4,616 Views)

State your requirements... as a set of requirements!  Not only will it help us, but you may come up with the solution yourself.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 10
(4,587 Views)

Hello Tyk007,

 

Sorry for the confusion.

 

1 to 5 are Boolean but we want to do logical operation for only two at once.

For example:

(1 OR 2 OR 3) à this is correct for logical operations. But we want to do two at a time.

It means ((1 OR 2) OR 3) , other way (1 OR (2 OR 3)).

 

So, if user is giving syntax like (1 OR 2 OR 3), we need to make it NG type. Like this I need to check different combinations to validate the syntax.

Munna
0 Kudos
Message 6 of 10
(4,585 Views)

This might be one of those times where telling us "why" you need to have it done is more valuable than "what" you want done.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 10
(4,572 Views)
Part of you problem is that some of the disallowed cases are logically correct. A two-step approach might work well. Step 1 would be to check for logical correcteness. Step 2 would be to insure that the syntax matches whatever arbitrary rules are imposed.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 10
(4,557 Views)

Here is updated code.

 

I'm really sorry if my required is not clear.

Please let me know where your getting confuse.

Munna
0 Kudos
Message 9 of 10
(4,553 Views)

I did little modifications.

I think it will cover all combinations.

 

Please let me know if there is any modifications required.

 

 

Munna
0 Kudos
Message 10 of 10
(4,524 Views)