State machine program

I am tasked with creating a small program that can read in the FSM definition from the input, read some lines from the input and determine whether these FSM lines are accepted based on the definition. I need to write this in C, C ++ or Java. I read the net for ideas on how to get started, but the best I could find was a Wikipedia article on Automatic Programming . The above example, C, apparently uses an enumerated list to determine states that are accurate if the states are hardcoded in advance. Again, I need to be able to really read the number of states and determine what each state should do. Any suggestions are welcome.

UPDATE: I can make the alphabet small (for example, {ab}) and accept other conventions, such as the beginning of the state is always state 0. I am allowed to impose reasonable restrictions on the amount of state, for example. no more than 10.

Summary of the issue:

  • How to implement FSA?
+3
source share
6 answers

First, get a list of all states (N of them) and a list of all characters (M of them). Then there are 2 ways to go, interpret or generate code:

  • Interpretation

    . NxM, -1, . . -1, . , . .

  • . C . , . , . switch , .

- , 2, (!), goto:-) , , , .

P.S. F A, .. while , , goto.

+7

, .

+2

. , question ( ). (, " FSA?" ).

FSA (, ), .

FSM: Σ, S, s 0, A δ . . , , FSM. , ; FSM ( , ), Σ S. .

, . , , . , , .

, . . , , O (log (| S | + | Σ |)), . (, char s), ​​ , O (log (| S |)).

, FSM, . ( ). ; .

class State {
    property name;
    State& transition(Symbol s);
    void setTransition(Symbol s, State& to);
}

.

, , .

+1

.

- come with language of state machine
- come with language for stimulus
- create sample file of one state machine in language
- create sample file of stimulus
- come with class for state
- come with class for transition
- come with class for state machine as set of states and transitions
- add method to handle violation to state class
- code a little parser for language 
- code another parser for language 
- initial state
- some output thing like WriteLn here and there
- main method
- compile
- run
- debug
- done
+1

OpenFst: FSM , , ( ), . . , .

+1

If you use an object-oriented language like Java or C ++, I would recommend that you start with objects. Before you worry about file formats and the like, get a good object model for state machines and how they behave. How will you represent states, transitions, events, etc.? Will your FSA be composite? Once you have this kind of work, you can get the file formats right. Everything will be done: XML, text, etc.

0
source

Source: https://habr.com/ru/post/1723564/


All Articles