A Parser for Conditional Expressions

I’ve created a tool at https://www.wimpyprogrammer.com/conditional-parser/ for analyzing conditional expressions. Here’s the story of what inspired it.

A while back my co-worker and I encountered a tricky conditional statement on a legacy C# project (variables have been renamed):

We updated and cleaned it up to make it a bit better:

But it remained tough to comprehend.  While troubleshooting that portion of the code, we needed to understand all of the circumstances in which the expression would evaluate to true.  “Surely there’s a tool that can break this down for us!” I thought, but couldn’t find one and decided to build my own.

The Conditional Expression Parser will divide a conditional statement into its operators and conditions, then list the combinations that would cause the entire expression to evaluate to true.  It recognizes AND ( && ), OR ( || ), and XOR ( ^ ) operators and is smart enough to ignore strings ( "a && b" ) and function calls ( foo(a && b) ).

The source code is available on GitHub.

Leave a Reply

Your email address will not be published.