1

アクションが実行されると、特定の条件下でアクションが別の状態へのジャンプをトリガーするようにします。コードを読みやすくするために、マシンのインスタンス化の外でアクションを定義したいと思います。

マシンのインスタンス化の範囲外で、ragel によって生成された状態ラベルにアクセスするにはどうすればよいですか?

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

static int cs=1;

%%{
    machine simpleMachine;  
    write data;
}%%

//The code for ActionA and ActionB is defined outside the scope 
//of the instatiation for readability

void a(void)
{   //Called for ActionA
}

void b(void)
{   //Called for ActionB
    int var2=0;
    if (var2==0)
    {
        %%{
            fgoto STATE_A; 
            #This fgoto generates a ragel parse error
            #how to use the STATE_A label outside 
            #of the machine definition?
        }%%
    }
}
void ExecuteSM(const char *p)
{   const char *pe = p + strlen( p );
    int var1=0; 
    %%{
        EVENT1 = 'a';
        EVENT2 = 'b';
        EVENT3=  'c';

        action ActionA
        {   a();
            if (var1==0)
            {
                fgoto STATE_B; //This fgoto compiles OK
            }
        }
        action ActionB
        {
            b();//I'd like to execute an fgoto in the function b() but I get a 
               //parse error
        }
        myfsm := (
                #STATE          EVENT               ACTION              NEXT_STATE
            start:(             EVENT1              >ActionA            ->STATE_A), 
            STATE_A:(           EVENT2              >ActionB            ->STATE_B),
            STATE_B:(           EVENT3)             
        );
    write init nocs;
    write exec;
    }%%
}
int main()
{
    ExecuteSM("abc");
    return 0;
}
4

1 に答える 1