sequence detection : regular expressions conversion to finite state machines

Upload: mailghanashyamprabhu

Post on 07-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    1/12

    State1 State2a

    a

    Figure1: Representation of a+

    since a+ indicates at least one occurrence of a

    from a current state state1, the fsm has to transit

    to another state and consume as many 'a's as possible

    and on occurrence of any other symbol can traverse to

    the next state

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    2/12

    State2

    a

    State3

    aState1

    a'

    Figure2: Representation of a*

    since a* indicates zero or one or more occurrence of a

    the fsm will have a bypass path a' which is used when any

    other symbol is consumed instead of a letter a. if there

    are letters a being consumed they move through the

    intermediate State2 as shown.

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    3/12

    State2 State3a

    State1

    a'

    a'

    Figure3: Representation of a?

    since a? indicates zero or one occurrence of a

    the fsm reaches its final state State3 either via the bypass

    path which indicates a zero occurrence of a OR via

    the State2 which shall only consume a single occurrence of a

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    4/12

    Problem statement : To convert regex 1+0(10)+11 into a statemachine

    Solution Approach:

    Let's denote the inner 10 as an X, so the regex is 1+0X+11 We split it into smaller parts of the FSM

    First part as 1+ Followed by 0 Followed by X+ Followed by two consecutive 1s

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    5/12

    1. From the atomic regex representations mentioned in

    previous slides, 1+ is represented as in Figure4

    State1 State21

    1

    2. To consume a 0, the representation of the state diagram

    would be as in Figure5

    State30

    Figure4: Representation of 1+

    3. To consume a (X)+, the representation of the state

    diagram would be in Figure6

    Figure5: Representation of 0

    StateX StateYX

    Figure6: Representation of X+

    X

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    6/12

    4. To consume two consecutive 1s, the representation of thestate diagram would be as in Figure7

    State9 State101

    Figure6: Representation of 11

    1

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    7/12

    LEVEL 2 Combine the individual state machines graphs

    (1. and 2. for now!)

    State1 State21

    State30

    1

    In case of binary stream sequence match, the only possible

    values of the symbols are 0 and 1. Hence there can be only

    two path in the deterministic finite automaton. A path for

    consuming the 0 symbol and another for consuming the 1

    symbol.

    Any path that is not defined above, for instance the 0 path

    from State1 leads to the initial state. So State1's 0 pathleads to itself.

    State1 State21 State30

    1

    0

    Graph1

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    8/12

    Expanding 3. Consumption of the symbol X where X is 10

    StateX StateYX

    StateX StateY10

    10

    StateX1 StateX21

    StateX30

    StateX4

    0

    Graph2

    0

    1

    1

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    9/12

    Joining Graph1 and Graph2

    State1 State21

    State30

    1

    0

    StateX1 StateX21

    StateX30 0

    Note the transition from State3 to StateX1 is on

    an empty symbol which means reaching State3 is

    same as reaching StateX1

    StateX4

    0

    1

    1

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    10/12

    Simplifying the Graph by removing the empty symbol

    State1 State21 0

    1

    0

    StateX1 StateX21

    StateX30 0

    StateX4

    0

    1

    1

    StateX1 s 0 path shall transit to State1 since an

    occurrence of 0 breaks the path

    StateX2 s 1 path shall transit to State2 since an

    occurrence of 1 breaks the path but might be a

    starting of another valid sequence of 1+

    0 1

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    11/12

    Adding the last graph to this final graph we get the

    final finite state machine

    State1 State21 0

    1

    0

    State

    X1

    State

    X2

    1 State

    X3

    0 0

    State9

    0

    1

    10 1

    State10

    Note that StateX4 has become State9, because StateX4

    already detects a 1 following a 10, hence is

    equivalent to the first state of the 4. and so can be

    merged with State9

  • 8/6/2019 Sequence Detection : Regular Expressions conversion to Finite State Machines

    12/12

    State1

    Out