Discussion:
[ragel-users] Can someone supply a Simple example of C# Ragel State machine code
Jerry
2014-05-30 19:39:25 UTC
Permalink
I am attempting to use QFSM which outputs in Ragel but is C based so I need to see if I can create a template for easy conversion of the QFSM Ragel output to C#. A?simple example would be a great start.

Thanks

Jerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.complang.org/pipermail/ragel-users/attachments/20140530/91d7eb9e/attachment.html>
Adrian Thurston
2014-06-29 15:01:53 UTC
Permalink
This was created by the C# test case translator. You need TXL and GMCS
in order for the C# test cases to be created.

-Adrian
Post by Jerry
I am attempting to use QFSM which outputs in Ragel but is C based so I
need to see if I can create a template for easy conversion of the QFSM
Ragel output to C#. A simple example would be a great start.
Thanks
Jerry
_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users
-------------- next part --------------
/*
* @LANG: csharp
* @GENERATED: yes
*/
using System;
// Disables lots of warnings that appear in the test suite
#pragma warning disable 0168, 0169, 0219, 0162, 0414
namespace Test {
class atoi1_csharp
{
bool neg;
int val;
%%{
machine atoi1_csharp;
action begin {
neg = false;
val = 0;
}
action see_neg {
neg = true;
}
action add_digit {
val = val * 10 + (fc - 48);
}
action finish {
if (neg)
{
val = - 1 * val;
}
}
action print {
Console.Write (val);
Console.Write ("\n");
}
atoi = (('-' @ see_neg | '+') ? (digit @ add_digit) +) > begin % finish;
main := atoi '\n' @ print;
}%%

int cs;
%% write data;

void init()
{
val = 0;
neg = false;
%% write init;
}

void exec( char[] data, int len )
{
int p = 0;
int pe = len;
int eof = len;
string _s;
%% write exec;
}

void finish( )
{
if ( cs >= atoi1_csharp_first_final )
Console.WriteLine( "ACCEPT" );
else
Console.WriteLine( "FAIL" );
}

static readonly string[] inp = {
"1\n",
"12\n",
"222222\n",
"+2123\n",
"213 3213\n",
"-12321\n",
"--123\n",
"-99\n",
" -3000\n",
};

static readonly int inplen = 9;

public static void Main (string[] args)
{
atoi1_csharp machine = new atoi1_csharp();
for ( int i = 0; i < inplen; i++ ) {
machine.init();
machine.exec( inp[i].ToCharArray(), inp[i].Length );
machine.finish();
}
}
}
}
/* _____OUTPUT_____
1
ACCEPT
12
ACCEPT
222222
ACCEPT
2123
ACCEPT
FAIL
-12321
ACCEPT
FAIL
-99
ACCEPT
FAIL
_____OUTPUT_____ */
Jerry
2014-06-29 22:02:28 UTC
Permalink
Adrian

Ragel is absolutely incredible.???

Thanks?for the file.
Jerry


On Sunday, June 29, 2014 11:01 AM, Adrian Thurston <thurston at complang.org> wrote:



This was created by the C# test case translator. You need TXL and GMCS
in order for the C# test cases to be created.

-Adrian
Post by Jerry
I am attempting to use QFSM which outputs in Ragel but is C based so I
need to see if I can create a template for easy conversion of the QFSM
Ragel output to C#. A simple example would be a great start.
Thanks
Jerry
_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users
_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.complang.org/pipermail/ragel-users/attachments/20140629/21e2f43a/attachment.html>
Loading...