C++ build all possible chains from grammar

I need to solve the lab from univeristy but I can't understand main idea for the following:
you have a grammar and a start point grammar:
"S;" "S->S(S)S|<empty>;" "S"

Where first S is allowed symbol "S->S(S)S|<empty>;"
this is a chain from there I need to build rules, such as:
Last string is "start point".

Anyone solve tasks like this before?

I build a bicycle like this:

But I can't solve the problem: if I have many complecated rules in multiple chains:

I can't handle this situations.
I'm tried to multiple vector and store "recursion point" there, but no success.
Can anyone help me with understanding this?
Lexical analysis is a complex subject.

When handling a grammar like this there are several ways to do it, some of which involve a lot of work.

I recommend you use a Recursive Descent Parser. It will make your life much happier.

BTW, that grammar is a little confusing to me the way it is written ā€” it does not clearly delineate terminals and rules. In particular, I am unsure what is meant by ā€œS(S)Sā€.

Also BTW, that grammar reduces to a single semicolon being a valid program.

Good luck!
Thanks for recursive parser!
I went to read about it. :)
I see what Recursive Descent Parser is not suitable for me, because program must work with any LL(k) grammar.
Ok, um, LOL, RD is for parsing LL(k) grammars...
Registered users can post here. Sign in or register to post.