Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a deterministic finite automata (DFA) - Mercury
    primarykey
    data
    text
    <p>I would like to have a deterministic finite automata (DFA) simulated in Mercury. But I’m s(t)uck at several places.</p> <p>Formally, a DFA is described with the following characteristics:</p> <ul> <li>a setOfStates S, </li> <li>an inputAlphabet E &lt;-- summation symbol, </li> <li>a transitionFunction : S × E --> S, </li> <li>a startState s € S,</li> <li><p>a setOfAcceptableFinalStates F =C S.</p> <p>A DFA will always starts in the start state. Then the DFA will read all the characters on the input, one by one. Based on the current input character and the current state, there will be made to a new state. These transitions are defined in the transitions function. when the DFA is in one of his acceptable final states, after reading the last character, then will the DFA accept the input, If not, then the input will be is rejected.</p> <p>The figure shows a DFA the accepting strings where the amount of zeros, is a plurality of three. Condition 1 is the initial state, and also the only acceptable state. for each input character is the corresponding arc followed to the next state.</p></li> </ul> <p><a href="http://i48.tinypic.com/ibetuh.png" rel="nofollow">Link to Figure</a></p> <p><strong>What must be done</strong></p> <ol> <li><p>A type “mystate” which represents a state. Each state has a number which is used for identification.</p></li> <li><p>A type “transition” that represents a possible transition between states. Each transition has a source_state, an input_character, and a final_state.</p></li> <li><p>A type “statemachine” that represents the entire DFA. In the solution, the DFA must have the following properties:</p> <ul> <li>The set of all states,</li> <li>the input alphabet,</li> <li>a transition function, represented as a set of possible transitions,</li> <li>a set of accepting final states,</li> <li>a current state of the DFA</li> </ul></li> <li><p>A predicate “init_machine (state machine :: out)” which unifies his arguments with the DFA, as shown as in the Figure. The current state for the DFA is set to his initial state, namely, 1. The input alphabet of the DFA is composed of the characters '0'and '1'.</p></li> <li><p>A user can enter a text, which will be controlled by the DFA. the program will continues until the user types Ctrl-D and simulates an EOF. If the user use characters that are not allowed into the input alphabet of the DFA, then there will be an error message end the program will close. (pred require)</p></li> </ol> <p><strong>Example</strong></p> <pre><code>Enter a sentence: 0110 String is not ok! Enter a sentence: 011101 String is not ok! Enter a sentence: 110100 String is ok! Enter a sentence: 000110010 String is ok! Enter a sentence: 011102 Uncaught exception Mercury: Software Error: Character does not belong to the input alphabet! </code></pre> <hr> <p><strong>the thing wat I have.</strong></p> <pre><code> :- module dfa. :- interface. :- import_module io. :- pred main(io.state::di, io.state::uo) is det. :- implementation. :- import_module int,string,list,bool. </code></pre> <p><strong>1</strong> </p> <pre><code>:- type mystate ---&gt; state(int). </code></pre> <p><strong>2</strong></p> <pre><code>:- type transition ---&gt; trans( source_state::mystate, input_character::bool, final_state::mystate ). </code></pre> <p><strong>3</strong> (error, finale_state and current_state and input_character)</p> <pre><code>:- type statemachine ---&gt; dfa( list(mystate), list(input_character), list(transition), list(final_state), current_state(mystate) ). </code></pre> <p><strong>4</strong> missing a lot</p> <pre><code>:- pred init_machine(statemachine :: out) is det. %init_machine(statemachine(L_Mystate,0,L_transition,L_final_state,1)) :- &lt;-probably fault </code></pre> <p><strong>5</strong> not perfect</p> <pre><code>main(!IO) :- io.write_string("\nEnter a sentence: ", !IO), io.read_line_as_string(Input, !IO), ( Invoer = ok(StringVar), S1 = string.strip(StringVar), (if S1 = "mustbeabool" then io.write_string("Sentenceis Ok! ", !IO) else io.write_string("Sentence is not Ok!.", !IO)), main(!IO) ; Invoer = eof ; Invoer = error(ErrorCode), io.format("%s\n", [s(io.error_message(ErrorCode))], !IO) ). </code></pre> <p>Hope you can help me</p> <p>kind regards</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload