I am working on my own little Script Language. Now I am stucking at the Script Reader which reads the file and converts it into the Script Parts (variables, functions, if clauses etc). I hava String which saves the Script File content in one line like so:
mega = "";test(){hallo();test = "";if(){p2 = -1;}else{p1 = "";}hi = 0;}
Now my Problem. I want to get the strings between the parentheses for if clauses and the function (which is around the if clause). I tried it with regex:
Matcher m = Pattern.compile("\\(([^)]+)\\)").matcher(example);
while(m.find()) {
System.out.println(m.group(1));
}
But then I get the content between the first parenthese of the function test(){ and the first parenthese that clauses the if clause. How can I extract the Strings between the if clause, else clause and the function?
EDIT:
This is want I want to get out after the extraction:
For the If: p2 = -1;
For the Else: p1 = "";
And for the Function arround:
hallo();test = "";if(){p2 = -1;}else{p1 = "";}hi = 0;
EDIT 2: I would like to have it recursive to its endless (when in the if clause is another etc.)