text - Is there a way to convert from a string to pure code in C++? -


I know that it is possible to read from .txt file and then the different parts of that string, char, and int Convert the value to, but is it possible to take this string and use it as a real code in the program?

Code:

  string codeblock1 = "cout <"; lt; & lt; this is a test; "; String codeblock2 = "int array [5] = {0,6,6,3,5};}"; Int i; CIN & gt; & Gt; I; If (i) {execute (codeblock1); } Else {execute (codeblock2); }  

Where execute is a function that changes from text to actual code (I do not know exactly what a function that is executed, I I am using it for the purpose of my example).

You can create a function and create a data structure with the string you prefer Known as a parsed tree. After this you can check your parse tree and prepare the necessary dynamic structure to perform logic theory. The purse tree is converted into a runtime presentation executed later.

All the compilers do it properly they take your code and they produce machine codes based on this. In your special case, you want a language to write code for yourself. Generally this is done in the context of a code generator and it is part of a big build process. If you write a program to parse your language (Flex and twenty considerations for this operation) that generate the code, you can get the results you want.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -