I started to write a hand written parser just for fun. For simple rules it is working, but I have problem with the optional grammar rules. I marked the optional rules with a question mark.
Here is a simple rule:
rule1: "AA"? "AB"? "AC"? "AD"
So AA, AB and AC string is optional, but AD is required.
ex.: "AAABAD" is matching, "AAAD" is matching, "AAAB" is not matching, "AD" is matching, ...
I need an algorithm and not a regex tool or something like that. I can solve this with brute force method (so trying every possible combination of the rules) but I think there is a better way to do this.