13.07.2015 Views

Chapter D Finite State Machines

Chapter D Finite State Machines

Chapter D Finite State Machines

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

H a !Q0[0]Q1[0]Q2[0]Q3[1]~H~a h~(! or h)Figure 9. FSM for recognising laughter. From Q0 an input “H” transits to Q1, any othercharacter returns to Q0. From Q1 we move to Q2 on receiving an “a”, which means we’ve got“Ha”. But if we don’t get an “a” then we return to Q0 to start afresh. From Q2 we accept eithera “!” to signal we’ve received a single “Ha!”, or if we get an “h” then we recycle to Q1 in waitfor an “a”. Anything else, then back to the beginning. This FSM recognises strings such as“Ha!”, “Haha!”, “Hahaha!” etc.more input strings. The door combination lock discussed in section D3 is anotherexample of a acceptor. But we have also seen examples of FSMs which output a valueat every state, like the people-counter in Section D4 Here the input stimulus wasconverted or “transduced” into a numerical value. So there are two classes of FSMs,“acceptors” and “transducers”.D9. Recognising Text – A Computer Program ParserWhen we write a computer program, we produce a bunch of text which is input into acompiler or interpreter which must ultimately convert this into a series of instructionswhich the CPU can execute. The part of the compiler which does this is called the“parser” and is fed by a stream of input characters and must “parse” this stream into aseries of tokens which can be used to generate the machine code. There are alsospecial symbols such as the semicolon, well-loved by C and Java programmers,whitespace “ “ and brackets “[“ and “]” familiar to us from out work on the Sam-2CPU in <strong>Chapter</strong> 2.Let’s sketch here a simple FSM to parse the “mov ax,[3]” type of instruction weencountered in our Sam-2 work. There are various possible patterns we have torecognise:mov ax, [addr]mov bx, [addr]mov [addr], ax,mov [addr],bxWe assume that we have a method in out program which can detect the tokens “mov”and “add” (that would be another FSM which would like the Laughter-detectorabove). A partial state diagram for this problem is shown in Fig.10.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!