08-18-2020 01:49 AM
Hello,
I'd like to create a simple C code scripting control in GUI and convert those text to LabVIEW code.
I have been thinking how to make a most effective structure for that but is not easy to design.
So, kindly ask is there any idea or experience about this from you globally?
Users want to typing some conditions and logic based on C style text scripting.
Thanks in advance!!
Best Regards,
08-18-2020 07:50 AM - edited 08-18-2020 07:50 AM
You could look at the Formula Parsing Vis which come together with LabVIEW. They "only" implement mathematical formulas in text form and are already fairly complex. Mathematical formulas are in many ways a subset of the C programming language, so you can safely assume that a proper C like parser is going to be considerably more complex to implement.
This is doubtlessly a very fun and interesting project to attempt to do, but do you even remotely comprehend what you are trying to do here? Do you have the preseverence to do this for real AND the time to spend for that? A reasonably C like parser will quickly require weeks if not months of development time, even if you don't implement all the different C syntax features.
08-18-2020 08:16 AM - edited 08-18-2020 08:18 AM
Why?
It's probably a lot easier to make some sort of interpreter of a simple c-like text if you want the text-based script functionality. But sure, you can interpret text and use scripting to create items on a VI. As mentioned, if you want to make it a true parser it's a pretty big job.
There's examples of how to create items on a block diagram through scripting, that's actually the easy part.
Connecting them to each other and in the right hierarchy is the next hurdle.
There should be plenty of external parsers that can check the validity of the text, i'd use that as a shortcut to know i don't have to handle all syntax checks myself.
And so on.
What have you tried?
08-18-2020 08:46 AM
Maybe it'd be worth exploring LabVIEW's Python nodes. That might make for a more straightforward path forward overall.
-Kevin P
08-18-2020 05:32 PM
Hello,
Thanks for your comments. Unfortunately, I'm using LV 2017 now. 😞
08-18-2020 08:57 PM
Rather than parsing text input and generating/running LabVIEW code, would using a string control to populate a temporary text file and then actually compiling it with a C compiler into a DLL, then calling the DLL with Call Library Function Node be a possible workaround?
Making it 'interactive' might be tricky, since you'll have to have some 'update' function that causes the compilation and then wait, but for simple enough programs it might be possible.
You could consider always wrapping the input in a suitable template, such that the function name and parameters/return type were known and the appropriate declarations were in place, perhaps something like:
#if defined(_MSC_VER)
#define EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define EXPORT __attribute__((visibility("default")))
#endif
<separate string control for includes here. Maybe a string array and some nice parsing?>
EXPORT char* myFunction() {
<fill in the text input here, e.g. return "Hello World"; >
}