Search code examples
fsmragel

What is the DEF state in the Ragel (6.10) document illustrations


The Ragel 6.10 manual has many illustrations of the FSM it generates. Some of which show a state DEF. As best I can tell this is never defined/discussed.

  1. What is the DEF state?
  2. What are its implications? e.g. if it shows up in your FSM abc should be done

Thanks in advance


Solution

  • Answer to Q1:

    DEF represents the default transition, which is taken if no other transition can be taken.

    Answer to Q2:

    This depends on what you are using Ragel for.

    1. Defining FSM using regular languages: Do you want move from State A to State B on any character?
    2. Defining FSM using state charts: Do you want to move from State A to State B on any event? Do you have a notion of a 'default' transition?.

    This issue be most clearly understood by working though the example in Section 6.4.5 of the manual (version 6.10), where parsing and state charts are both used.

    This can sometimes arise when you use explicitly any as a state.

    Example:

    %%{
      machine def_eg;
      action to_action_1 {}
      action to_action_2 {}
      action from_action_1 {}
      eg = (
          start: (
              any -> s1
            ),
          s1: (
              any -> s2
            )>to(to_action_1) >from(from_action_1),
          s2: (
              any -> final
            )>to(to_action_2)
          );
      main := ( eg ) ;
    }%%
    
    %% write data
    

    And the graphviz (ragel -Vp -o def_eg.dot def_eg.rl):

    Showing any character/event

    Now, with the expressions changed from any character to a single character. And using these single characters to represent states.

    %%{
      machine def_eg;
    
      event_1='1';
      event_2='2';
      event_3='3';
    
      action to_action_1 {}
      action to_action_2 {}
      action from_action_1 {}
    
      eg = (
          start: (
              event_1 -> s1
            ),
          s1: (
              event_2 -> s2
            )>to(to_action_1) >from(from_action_1),
          s2: (
              event_3 -> final
            )>to(to_action_2)
          );
      main := ( eg ) ;
    }%%
    
    %% write data
    

    Is illustrated as:

    Showing any character replaced by single character/event