[ragel] sample code
Adrian Thurston
thurston at colm.net
Wed Feb 21 04:12:42 UTC 2018
Hi, that's right, ragel doesn't automatically print anything.
The code you have will print an error if the machine is not in a final
state. If it is run at the end of the input then yes it is correct.
The noerror and nofinal modifiers just prevent the static integers
representing those things from getting created. In your code you don't
need them because you've used the write versions of those things
instead.
On 2018-02-12 03:58, xoru wrote:
> Hi,
>
> Many thanks. This work fine. I would like to thank you very much for your help. I have been struggling with this problem for a long time. I will go from bison, because unfortunately when bison have mistakes it publish messages to stdout and I want to emmbeding them in the program. Do not they write anything in the ragel?
>
> I add a information if there is a problem or not.
>
> if ( cs < %%{ write first_final; }%% )
> {
> printf("x1B[31mProblemx1B[0m [%d]n", %%{ write error; }%%);
> }
> this is correct?
>
> There is a phrase in the code:
> "write data noerror nofinal;"
> Is it correct?
> "noerror is neccesary? "nofinal" ?
>
> I working on comments but this is not important.
> You've helped me a lot, thank you.
>
> Marek Łukasz
>
> W dniu 2018-02-07 17:08:54 użytkownik Adrian Thurston <thurston at colm.net> napisał:
>
> Hi,
>
> It's because space* accepts the zero-length string. So "abc" is actually three words with zero-length whitespace in between. Well, technically it's both that and what you want, so you need to remove the ambiguity. What you need is more like this:
>
> space* wyraz ( space+ wyraz )*
>
> -Adrian
>
> On 2018-02-05 07:06, xoru wrote:
>
> How put "a ab abc t abcdn abcde"
> and get
> 'a'
> 'ab'
> 'abc'
> 'abcd'
> 'abcde'
>
> When i use main := (space* wyraz )* i get only chars not words
>
> /* @LANG: c */
> #include <stdio.h>
> #include <string.h>
>
> %%{
> machine foo;
>
> action beginning { pocz = p; }
> action ending { printf("'%.*s'n",(int)(p - pocz), pocz); }
>
> wyraz = [a-z]+ >beginning %ending;
> main := ( space* wyraz ) ;
>
> write data noerror nofinal;
> }%%
>
> int main(int argc, char **argv)
> {
> int cs = 0;
> char *pocz;
>
> if (argc > 1)
> {
> char *p = argv[1];
> char *pe = p + strlen(p);
> char *eof = pe;
> %%write init;
> %%write exec;
> }
>
> return 0;
> }
>
> _______________________________________________
> ragel mailing list
> ragel at colm.net
> http://www.colm.net/cgi-bin/mailman/listinfo/ragel [1]
_______________________________________________
ragel mailing list
ragel at colm.net
http://www.colm.net/cgi-bin/mailman/listinfo/ragel [1]
Links:
------
[1] http://www.colm.net/cgi-bin/mailman/listinfo/ragel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.colm.net/pipermail/ragel-users/attachments/20180220/2822e6be/attachment-0002.html>
More information about the ragel-users
mailing list