使用这样的机器:
主要:=(任何+);
当我向它提供超过 1 个字节的数据块时,它似乎只消耗 1 个字节,然后(通常)出现 %%write exec 块。我希望它是贪婪的并消耗所有提供的输入。
我总是可以在 %%write exec 之前检查 p < pe 和 goto,但它似乎很老套。
我如何让它“贪婪”?
使用这样的机器:
主要:=(任何+);
当我向它提供超过 1 个字节的数据块时,它似乎只消耗 1 个字节,然后(通常)出现 %%write exec 块。我希望它是贪婪的并消耗所有提供的输入。
我总是可以在 %%write exec 之前检查 p < pe 和 goto,但它似乎很老套。
我如何让它“贪婪”?
也许您的问题缺少一些关键数据,但默认行为是尽可能使用所有内容pe
。显然,使用您的机器是可能的,并且给定 Ragel 6.9 和这个简单的程序:
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
%%{
machine main;
alphtype char;
main := (any+);
}%%
int main()
{
static char data[] = "Some string!";
int cs;
char *p, *pe, *eof;
%% write data;
%% write init;
p = data;
pe = data + sizeof(data);
eof = pe;
printf("p: 0x%"PRIxPTR", pe: 0x%"PRIxPTR", eof: 0x%"PRIxPTR"\n",
(uintptr_t) p, (uintptr_t) pe, (uintptr_t) eof);
%% write exec;
printf("p: 0x%"PRIxPTR", pe: 0x%"PRIxPTR", eof: 0x%"PRIxPTR"\n",
(uintptr_t) p, (uintptr_t) pe, (uintptr_t) eof);
return 0;
}
你应该在输出中得到类似的东西:
p: 0x601038, pe: 0x601045, eof: 0x601045
p: 0x601045, pe: 0x601045, eof: 0x601045