Is it possible to write a program that creates regexes from an entire C++ source code?
What I mean by this, is that the program reads the code, and then creates regexes for parts of the code. I want to create something that keeps the type then uses (w+)
for the variable name.
I know that it is simple to code for easy cases, but I wonder if it is even possible for more complicated code. I also want that the regex that is created is that I can access it later or so, like for example (w+)1
.
For example:
code to be read:
int main(){int a = 10; int b = 12; int sum = a + b;}
I want it to be a regex like:
int((w+)1)=10;int((w+)2)=20;int((w+)3)=((w+)1)+((w+)2)
But now, I want to know if it is possible to get this done with somewhat more difficult types of code, like if
statements (like the i
that can be initialized inside the if
statement), loops, etc. Also, how do I get the types (because sometimes a type can also be a struct, class, … defined elsewhere, so it can’t be added to a vector of all types) without having to write all the types into a vector or so.
Is this even possible, and if it is then how does one start with this?
(if it sounds stupid, I’m sorry for wasting your time, I’m new to programming)
I have tried to create it for each type, by adding all the types to a vector, but I cannot seem to get it dynamically. If there are more difficult types in front of a variable, like a struct that was defined elsewhere, I cannot choose it from a list of types. Also, I can’t seem to be able to get loops and if
statements to work.
OrdinaryGuy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3