DFA at run time

I am currently working on a program that will take a English description of a language and then use the description to create a DFA for those specs. I allow certain operations, example {w | w has the sub string 01 in the beginning} and other options such as even odd sub string, more less or exactly than k sub string, etc. The user also chooses the alphabet.

My question is how would i know how many states I will need? since the user gives me my alphabet and rules I don't know anything until run time. I have created DFA's/transition tables before, but in those cases I knew what my DFA was and could declare it in a class or have it static. Should I be using the 5 tupil (Q, ∑, δ, q0, F)? or taking a different approach? Any help wrapping my head around the problem is appreciated.
My question is how would i know how many states I will need? since the user gives me my alphabet and rules I don't know anything until run time.


You don't know how many states you will need in advance, so this is what a vector is used for.

The user will:
- define a class 'state' and class 'symbol'
- supply you with a vector<state> Q;
- supply you with a vector<symbol> alphabet for your ∑
- supply you with a transition function δ, say: state delta( state q, symbol a )
- supply you with an initial state q0;
- supply you with a vector<state> F for accepts.

You can create a class 'sequence' to be composed of strings of symbols.
You have to test your sequences of letters from the alphabet, say a vector<symbol>, and create a vector<sequence> that constitutes your language.

https://en.wikipedia.org/wiki/Deterministic_finite_automaton
Last edited on
Topic archived. No new replies allowed.