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

On 14-05-30 03:39 PM, Jerry wrote:
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@complang.org
http://www.complang.org/mailman/listinfo/ragel-users

/*
 * @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_____ */
_______________________________________________
ragel-users mailing list
ragel-users@complang.org
http://www.complang.org/mailman/listinfo/ragel-users

Reply via email to