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:
S->S
S->(S)
S-><empty>
Last string is "start point".

Anyone solve tasks like this before?

I build a bicycle like this:
https://gist.github.com/567bfb66e4eca7efb2b7305e0b1be22b

But I can't solve the problem: if I have many complecated rules in multiple chains:
A->BCD|1|2
B->2|3|ABC

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...
Topic archived. No new replies allowed.