在这样的机器上:
main := (any+);
当我给它提供一个超过1字节的数据块时,它似乎只消耗了1个字节,然后(通常)从%%write exec块中出来。我希望它是贪婪的,并消耗所有提供的输入。
我总是可以在%%write exec之前检查p< pe和goto,但它似乎有点问题。
我如何让它变得“贪婪”?
发布于 2016-11-19 04:38:20
也许你的问题遗漏了一些关键数据,但默认行为是尽可能使用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: 0x601045https://stackoverflow.com/questions/28726041
复制相似问题