I have created what I think are identical machines (except for the host code, that is) that don't behave the same way. The ragel files are attached.

Here's a typical session with the C machine:

$ ragel client_c.rl
$ gcc -o client_c client_c.c
$ echo "OK callnum 8108" | ./client_c
figure out how to print out the call number.
$ echo "OK callnum 8108 foo" | ./client_c
Parse error.


Here's the same session with the Java machine:

$ ragel -J client_java.rl -o ClientParser.java
$ javac ClientParser.java
$ java ClientParser "OK callnum 8108"
$ java ClientParser "OK callnum 8108 foo"
Parse error.


It seems like the "%" transition action works differently in Java and C. If I change the transition action to and "@" I get "figure out how to print out the call number." several times. This is true for both the C and Java versions.

What am I doing wrong?

Thanks,
Jose.
public class ClientParser
{
%%{
        machine client;

        action call_number {
                System.out.println( "figure out how to print out the call 
number." );
        }

        action err_code {
                System.out.println( "figure out how to print out the error 
code." );
        }

        action err_msg {
                System.out.println( "figure out how to print out the error 
message." );
        }

        # Single Quoted string.
        squotedStr = '\'' . [^'\\] . '\'';

        # Double Quoted string.
        dquotedStr = '"' . [^'\\] . '"';

        arb_string = !(space - '\n') | squotedStr | dquotedStr;

        ok_tk = "OK ";
        callnum = "callnum " . (digit+) %call_number;
        error_tk = "ERROR ";
        errspec = (digit+) %err_code . " " . arb_string %err_msg;
        
        goodcall = ok_tk . callnum;
        badcall = error_tk . callnum . " " . errspec;
        error = error_tk . errspec;

        main := ( goodcall | badcall | error ) . '\n'; 

}%%

%% write data;

        public static void main( String[] p_args )
        {
                ClientParser l_parse = new ClientParser();
                
                l_parse.parse( p_args[0] );
        }

        public void parse( String p_line )
        {
                //These are all required by ragel
                int cs;
                int p = 0;
                char [] data = p_line.toCharArray();
                int pe = data.length;

                %% write init;
                %% write exec;

                if( cs == client_error )
                {
                        System.out.println( "Parse error." );
                }
        }
}
#include <stdio.h>
#include <string.h>

%%{
        machine client;

        action call_number {
                printf( "figure out how to print out the call number.\n" );
        }

        action err_code {
                printf( "figure out how to print out the error code.\n" );
        }

        action err_msg {
                printf( "figure out how to print out the error message.\n" );
        }

        # Single Quoted string.
        squotedStr = '\'' . [^'\\] . '\'';

        # Double Quoted string.
        dquotedStr = '"' . [^'\\] . '"';

        arb_string = !(space - '\n') | squotedStr | dquotedStr;

        ok_tk = "OK ";
        callnum = "callnum " . (digit+) %call_number;
        error_tk = "ERROR ";
        errspec = (digit+) %err_code . " " . arb_string %err_msg;
        
        goodcall = ok_tk . callnum;
        badcall = error_tk . callnum . " " . errspec;
        error = error_tk . errspec;

        main := ( goodcall | badcall | error ) . '\n'; 

}%%

%% write data;

#define BUFSIZE 1024

int main( int argc, char **argv )
{
        int a, cs;
        char buf[BUFSIZE];

        %% write init;

        while ( fgets( buf, sizeof(buf), stdin ) != 0 )
        {
                const char *p = buf;
                const char *pe =  p + strlen( buf );

                %% write exec;
        }

        if( cs == client_error )
        {
                printf( "Parse error.\n" );
        }

        return 0;
}
_______________________________________________
ragel-users mailing list
[email protected]
http://www.complang.org/mailman/listinfo/ragel-users

Reply via email to