nickclarson 0 Newbie Poster

I'm completely lost on this assignment:

The BNF rules (referred to as a grammar) are stored in a file. Your program is to read and echo the grammar file, and then walk the user through the process of building a sentence.

Once the grammar is read, the program will prompt the user to build a sentence in the specified grammar. For example assume the grammar is:

<s> -> let <var> = <val>
<val> -> <var> | <num>
<var> -> a | b
<num> -> 1 | 2 | 3
The program and the user could have the following interaction (user answers after the ?):
deriving <s>
deriving <var>
specify number of choice: 1 a, 2 b
?2
deriving <val>
specify number of choice: 1 <var>, 2 <num>
?2
deriving <num>
specify number of choice: 1 1, 2 2, 3 3
?1
The derived sentence is:
let b = 1
Assume the left hand side (LHS) of the first rule specifies the start symbol. Demonstrate the program with at least two grammars and for each grammar at least two examples. You need to use recursion to run through a rule after you start. Otherwise, you have to keep a stack of states of where you are.

I figure I have to use tokens of some sort to read in the grammar, but I'm stuck on the recursive part. I'm assuming the recursive part is if the grammar has:

<s> -> <s> ...

This is supposed to work for any grammar in a similar form to the example.

I appreciate any help or tips,
Nick