Re: Evaluate string expression in if statement?




"Keith Thompson" <kst-u@xxxxxxx> wrote
> Some people have suggested elaborate solutions like using an external
> interpreter. Aside from being way too much work, they're not going to
> work if you want the expression encoded in the string to refer to
> variables in your own program.
>
>> The general application is that I'm in interested in reading if
>> conditionals from a file, not only the conditional variables but the
>> conditional operators as well (the whole phrase).
>
> You might be able to implement an expression evaluator that takes a
> string and evaluates it as an expression, but you'll need to figure
> out how to evaluate variable names within the expression. Mapping
> them to variables in your own program probably doesn't make sense.
>
I think that if you don't understand why a string with the value "myvar"
cannot easily be used to access variable "myvar" in the program, you
probably don't understand enough to mess with expression parsers.
Why do you need these conditional expressions in a file? Is there not some
way of achieving what you want by hard-coding them?


.



Relevant Pages

  • Conditional evaluation in make(1)
    ... Its string conditional operators were broken, ... hidden behind another bug in makethat was recently fixed. ... : are all valid conditionals. ...
    (freebsd-arch)
  • Re: [Conditional] question
    ... I dont think that will work, you are detecting the environment at runtime, ... > on my development laptop, the stage server or the live server, and ... > conditionals seem to be the most efficient way forward. ... >> string productionServer; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [Conditional] question
    ... strictly for pre-processor values, not environment values. ... > I want to make tweaks to an application based up whether it is running> on my development laptop, the stage server or the live server, and> conditionals seem to be the most efficient way forward. ... >> string productionServer; ...
    (microsoft.public.dotnet.languages.csharp)
  • [Conditional] question
    ... on my development laptop, the stage server or the live server, and ... conditionals seem to be the most efficient way forward. ... > string productionServer; ... > private void checkIsDevBox() ...
    (microsoft.public.dotnet.languages.csharp)