I have to search in a file with 300 000 lines of brainfuck code with grep for several constructions.
First Question
I need to find codes like the first code below, i am looking for an alternating + - construction, the other characters are seen as delimiters, also +-+ or -+- is correct. We start searching after the ], like in the examples below
++[>++>+++>+<<<-]>++++++++.---.+.>.<------.+.>.>. ∈ γ, (correct, it is alternating)
++[>++>+++>+<<<-]>+++++.>++++++.>++.++++.-----.>. not ∈ γ (so incorrect +* is followed by +*)
Second Question
I need to find codes like the first code below, I am looking for an odd number of occurences of - between a consecutive pair of <> and an empty <> is seen as an even number so incorrect.
++[>++>+++>+<<<-]>+.>++++++++.<-.----.+++++++.>>. ∈ δ (correct, odd times - between <> )
++[>++>+++>+<<<-]>+++.>++++++.<<-.-.>>--.<---.>>. not ∈ δ (incorrect, even times - between <> )
Note, only grep is allowed, we may not use a texteditor, which I did first.