Problem: Change state only when a new input is received

Aditi ad... at cse.iitk.ac.in
Wed Jul 11 19:43:19 UTC 2007


Hi Adrian,
Thanks for your reply. With your help I got it partially working, but
I still have some doubts and problems:
Here is the code snipet-
<snip>
		%% write init;

		while(true) {
 			if ((rval=read(msgsock, buff, 1024)) < 0){
				perror("reading stream message");
				break;
			}
			else {
				sscanf(buff, "%d", &num);
				printf("-->%d\n", num);
				p = #
				pe = p + 1;
			}

			%% write exec;

			if(num == 0) break;
		}
</snip>
Now,
1.) %% write exec will be executed in every iteration of the loop.
Will this effect the performance? Is there a better way to do it? I
couldn't get it working by putting it just once outside the loop. I am
using this to build a tool which is required to be efficient, that's
why I am concerned with this point.
2.) The printing of the tokens and the action triggered(as of now,
just a print statement) happen only after I send the next token. Why
is there this delay of one token in the processing. Is my approach not
correct?
3.) There are certain other issues also, like I want to match this
pattern anywhere in the string and may be multiple times if it occurs.
This is not happening here. This code works if I give my pattern in
the beginning only. What should I do?
I am sorry about putting so many questions together. Any kind of help
will be immensely useful.
Thanks Again!
Cheers,
Aditi.


On Jul 11, 7:42 pm, Adrian Thurston <thurs... at cs.queensu.ca> wrote:
> Hi Aditi,
>
> For this task don't use the "noend" write option. Set the alphabet type
> to int and when an integer arrives set p to point it and set pe to (p +
> 1). Also, make sure you separate out the init code so it is invoked only
> once before you start reading input.
>
> I've always wanted to add a "one-at-a-time" option to write which would
> eliminate the unnecessary loop over the single character but never got
> around to it.
>
> Adrian
>
> Aditi wrote:
> > Hi,
> > I am new to ragel and was hoping to use it for the following purpose-
> > I need to match a regular expression, but the input which is to be
> > matched comes as a series of tokens over a socket. I need the state
> > machine to advance to the next state as and when it receives the
> > token.
>
> > I am trying to do this with ragel but have been unsuccessful so far.
> > According to my understanding of ragel, I need to specify the whole
> > chunk of string between pointers p and pe and let machine run on it.
> > Instead I want p to read one value from socket on advance on it. Can
> > somebody please give me pointers on how to do this?
>
> > This is a code snippet of one of my futile attempts :( -->
> > <snip>
> >            if ((rval=read(msgsock, buff, 4)) < 0){
> >                    perror("reading stream message");
> >                    exit(1);
> >            }
>
> >            p = buff;
>
> >            %% write init;
> >            %% write exec noend;
>
> >            while(true) {
> >                    if ((rval=read(msgsock, buff, 4)) < 0){
> >                            perror("reading stream message");
> >                            break;
> >                    }
> >                    else {
> >                            p = buff;
> >                            printf("-->%s\n", buff);
>
> >                    }
> >                    if(strcmp(buff,"exit")== 0) break;
> >            }
> > </snip>
>
> > My token will by of type integer, but as a startup i was trying with
> > normal string tokens. It would be really helpful if someone can help
> > me out with this.
> > Regards,
> > Aditi.
>
> > >
>
>
>  signature.asc
> 1KDownload



More information about the ragel-users mailing list