Problem with long alphabet type

Elmin matty.no... at gmail.com
Thu Sep 13 06:34:21 UTC 2007


Hi,

I'm working on a project where I need to run tests on Unicode code
points -- my idea was to decode them from UTF-8 first, then store them
in an array of long integers and run that array through the FSM to
validate/parse it.  I'm using semantic conditions to check the
categories of the symbols.  The problem is that when I set the
alphabet type to "long" or "unsigned long" I get compiler warnings:

longtest.c:109: warning: this decimal constant is unsigned only in ISO
C90
longtest.c:109: warning: this decimal constant is unsigned only in ISO
C90
longtest.rl:9: warning: integer constant is too large for 'long' type

Also, the FSMs don't seem to work as expected.  Here's the sample
program I wrote to isolate the issue somewhat, which is pretty similar
to the semantic conditions example from the guide:

#include <stdio.h>

%%{
  machine longtest;

action rec_num { i = 0; n = fc-'0'; }
action test_len { i++ < n }
  main := (
'd'
[0-9] @rec_num
':'
( [a-z] when test_len )*
)**;

  write data;
}%%

int main(int argc, char *argv[])
{
  long data[] = {'d', '2', ':', 'c', 'z'};
  long *p = data, *pe = data+5;
  int cs, i, n;

  %% write init;
  %% write exec;

  if (cs == longtest_error && *p != 0)
    {
      printf("Error: %i\n", (int)*p);
    }
  else
    printf("No Error!\n");

  return 0;
}

It should print "No Error!"  It does, if the alphabet type is set to
anything smaller than "long", but in the form above it always prints
"Error: 99" -- anyone have any ideas?  It almost seems like Ragel is
using the wrong limits or something.  This is on OS X 10.4 on PPC, and
I saw the same behavior with Ragel versions 5.19 and 5.23.  The
compiler is GCC 4.0.1.

Thanks,
Elmin



More information about the ragel-users mailing list