-3

I am trying to draw out a finite state machine (start, next state etc.) how can I draw this using only 7 states?

I wrote out what the table looks like, this inputing characters into tokens Table: e.g. if the user types in a one a T for true should be the output

input/output or tokens

1   / T,
2   / F,
#   / ~,
!   / ~,
&   / ^,
*   / ^,
+   / v,
<>  / x,
!=  / x,
=>  / >,
--> / >,
--  / =,
=   / =,
==  / =,
(   / (,
)   / ),
MvG
  • 57,380
  • 22
  • 148
  • 276
  • 1
    Please organize your table, so it makes the least sense. Furthermore, please elaborate on what you exactly want. – Jeel Shah Oct 06 '12 at 23:25
  • At least Homer tried hard to hide the fact that this is a homework assignment. – dokaspar Oct 07 '12 at 10:25
  • @Dominik, as the homework tag is being phased out, the canonical way of marking a homework assignment is now gone. Yes, one *might* mention that in the question, but I'd not call that omission “hard hiding” yet. – MvG Oct 07 '12 at 10:30
  • @Dominik, I don't see how I am trying hard to hide the fact that it is homework I have to write the code for the finite state machine, and before I do that I knew I need to draw it out and was stuck so I asked. – Homer Homer Oct 07 '12 at 14:03

1 Answers1

0

You need one state for every prefix of an input sequence. So your states should correspond to

"", "<", "!", "=", "-", "--"

Usually, every input character which completes a recognized input sequence will generate the corresponding output and then return to the initial state. Any input character which contributes towards an input sequence but does not complete it yet will cause a state transition matching the prefix read so far. And any input which is neither will be reported as an error.

You do have some tricky situations in your table, though. There are some input sequences which themselves are prefixes of other input sequences. For example, when the input contains "=+". After the first "=" you don't know whether there will be a ">", so you can't output anything yet. After the "+" you know you'll have to output "=" first and "+" immediatley afterwards. So your automaton must be designed to handle multiple outputs per transition.

MvG
  • 57,380
  • 22
  • 148
  • 276
  • I was wondering if for example the number one which is suppose to output T for true, if you draw an arc curving back to the start state, and my question is does that arc count as a state? (unlike the < symbol which will need a "circle" state with arcs leading to it? – Homer Homer Oct 07 '12 at 15:35
  • Arcs are transitions, not states. So for most single-character sequences, you'll have arcs from the start state onto itself. – MvG Oct 07 '12 at 17:58