action ordering. is this a bug?

Chris Pirazzi cpira... at gmail.com
Sun Feb 18 11:38:45 UTC 2007


Hi,

Ragel seems completely amazing and I am hoping I can use
it for my application.  I am just getting to understand Ragel
and in particular its rules about the order in which
actions are called, because this will be important for
my application.  I have ragel-5.18.

The PDF says:

"When it visits a parse tree node it assigns
timestamps to all starting action embeddings, recurses
on the parse tree, then assigns timestamps
to the remaining all, finishing, and leaving embeddings
in the order in which they appear."

However if I feed in this small (admittedly ambiguous) grammar:

%%{

machine small;
write data noerror;

bar = 'a' >{ printf(">bar\n"); } @{ printf("@bar\n"); }  $
{ printf("$bar\n"); }  %{ printf("%%bar\n"); };

barz = ( bar* ) >{ printf(">barz\n"); } @{ printf("@barz\n"); }  $
{ printf("$barz\n"); }  %{ printf("%%barz\n"); };

tbarz = barz . barz >{ printf(">tbarz\n"); } @{ printf("@tbarz\n"); }
${ printf("$tbarz\n"); }  %{ printf("%%tbarz\n"); };

main := ( tbarz 0 ) @{ fbreak; };

write init;
write exec noend;

}%%
}%%

and I execute this machine on the input "aaa<nul>", then I would
expect to see ">tbarz" first, but I don't.  The total output is:

>barz
>bar
@bar
$bar
@barz
$barz
%barz
>tbarz
@tbarz
$tbarz
%bar
>bar
@bar
$bar
@barz
$barz
%barz
>tbarz
>barz
@tbarz
$tbarz
%bar
>bar
@bar
$bar
@barz
$barz
%barz
>tbarz
>barz
@tbarz
$tbarz
%bar
%barz
%tbarz

The "problem" can also be seen from the compiled output of ragel
without producing any C code, in that the action table id=1
does not list action 8 first.

<ragel filename="small.rl" lang="C">
<ragel_def name="small">
  <alphtype>0</alphtype>
  <machine>
    <action_list length="13">
      <action id="0" line="7" col="12"><text> printf(">bar\n"); </
text></action>
      <action id="1" line="7" col="35"><text> printf("@bar\n"); </
text></action>
      <action id="2" line="7" col="59"><text> printf("$bar\n"); </
text></action>
      <action id="3" line="7" col="83"><text> printf("%%bar\n"); </
text></action>
      <action id="4" line="9" col="18"><text> printf(">barz\n"); </
text></action>
      <action id="5" line="9" col="42"><text> printf("@barz\n"); </
text></action>
      <action id="6" line="9" col="67"><text> printf("$barz\n"); </
text></action>
      <action id="7" line="9" col="92"><text> printf("%%barz\n"); </
text></action>
      <action id="8" line="11" col="22"><text> printf(">tbarz\n");
</text></action>
      <action id="9" line="11" col="47"><text> printf("@tbarz\n"); </
text></action>
      <action id="10" line="11" col="73"><text> printf("$tbarz\n"); </
text></action>
      <action id="11" line="11" col="99"><text> printf("%%tbarz\n"); </
text></action>
      <action id="12" line="13" col="22"><text> </text><break></
break><text> </text></action>
    </action_list>
    <action_table_list length="4">
      <action_table id="0" length="3">7 11 12</action_table>
      <action_table id="1" length="10">4 0 1 2 5 6 7 8 9 10</
action_table>
      <action_table id="2" length="4">3 7 11 12</action_table>
      <action_table id="3" length="11">3 0 1 2 5 6 7 8 4 9 10</
action_table>
    </action_table_list>
    <start_state>1</start_state>
    <error_state>0</error_state>
    <state_list length="4">
      <state id="0">
      <trans_list length="0">
      </trans_list>
      </state>

      <state id="1">
      <trans_list length="2">
        <t>0 0 3 0</t>
        <t>97 97 2 1</t>
      </trans_list>
      </state>

      <state id="2">
      <trans_list length="2">
        <t>0 0 3 2</t>
        <t>97 97 2 3</t>
      </trans_list>
      </state>

      <state id="3" final="t">
      <trans_list length="0">
      </trans_list>
      </state>
    </state_list>
  </machine>
</ragel_def>
<host line="1" col="1">

</host>
<write def_name="small" line="5" col="1"><arg>data</arg><arg>noerror</
arg></write>
<write def_name="small" line="15" col="1"><arg>init</arg></write>
<write def_name="small" line="16" col="1"><arg>exec</arg><arg>noend</
arg></write>
<host line="18">

}</host>
<host line="20"></host>
</ragel>

Have I misunderstood the rules?

Is the behavior caused by the ambiguity of the grammar?

I will make a separate post on exactly what I'm hoping to do
with ragel, and why I am even showing an ambiguous grammar.

Thanks,

     - Chris Pirazzi



More information about the ragel-users mailing list