in reply to Re^2: Logical expressions
in thread Logical expressions

One problem you can find with 'little languages' on their own is that over time you get things like "it would be nice if you could use variables, or loops, or...".

I've seen it a few times with web templating systems, test case specification languages, etc.

If you can possibly make use of an existing 'full' language, then that may be better. One option is - perl (you have it to hand and know it well...)

You can put together strings like "$foo and ($bar or $boo)". Instead of writing a language parser and evaluator, you write the code which sets up the $foo, $bar variables and then calls "eval $logical_expression".

Such an approach would require less code (you'll have to set up the same foo/bar/boo whichever approach you take) and you also potentially have the full power of perl there if you ever need it. You're basically using 'eval' as your parser and evaluator.

Some more of the rationale behind this approach is suggested in the documentation to Text::Template. You could even use that module as a way of helping set up your foo/bar/baz, since your logical expression could be seen simply as a text template evaluating to 1 or 0. :-)

People sometimes talk about using Domain Specific Languages (DSLs) - and they *are* often a good idea. One point which sometimes gets missed is that DSLs are *embedded* in the full language they are created in, not just *implemented*. You can still escape to the full language and so don't have to re-invent precedence rules, loops, conditionals, variables and all that good stuff.