swi-prolog

Stack overflow in Prolog DCG grammar rule: how to handle large lists efficiently or lazily

筅森魡賤 提交于 2019-11-26 12:32:23
I'm parsing a fairly simple file format consisting of a series of lines, each line having some space separated fields, that looks like this: l 0x9823 1 s 0x1111 3 l 0x1111 12 ⋮ I'm using SWI-Prolog. This is the DCG I have so far: :- consult(library(pure_input)). load_trace(Filename, Traces) :- phrase_from_file(trace_file_phrase(Traces), Filename). trace_file_phrase([]) --> []. trace_file_phrase([T|Ts]) --> trace_phrase(T), trace_file_phrase(Ts). trace_phrase(access(Type, Address, SinceLast)) --> access_type(Type), space, address(Address), space, nat(SinceLast), newline. access_type(load) -->

Stack overflow in Prolog DCG grammar rule: how to handle large lists efficiently or lazily

…衆ロ難τιáo~ 提交于 2019-11-26 02:59:32
问题 I\'m parsing a fairly simple file format consisting of a series of lines, each line having some space separated fields, that looks like this: l 0x9823 1 s 0x1111 3 l 0x1111 12 ⋮ I\'m using SWI-Prolog. This is the DCG I have so far: :- consult(library(pure_input)). load_trace(Filename, Traces) :- phrase_from_file(trace_file_phrase(Traces), Filename). trace_file_phrase([]) --> []. trace_file_phrase([T|Ts]) --> trace_phrase(T), trace_file_phrase(Ts). trace_phrase(access(Type, Address, SinceLast)