<![CDATA[Latest posts for the topic "Cần giúp đỡ về Ragel"]]> /hvaonline/posts/list/19.html JForum - http://www.jforum.net Cần giúp đỡ về Ragel module: microscript.rl -- parse numbers from input Code:
#include <stdio.h>
#include <inttypes.h>

%%{
	machine microscript;

	action clear_number {
		current_number = 0;
	}

	action record_digit {
		uint8_t digit = (*p) - '0';
		current_number = current_number*10 + digit;
	}

	action print_current_number {
		printf("%d\n", current_number);
	}

	number = ((digit @record_digit)+) >clear_number;
	whitespace = (space)+;

	main := number @ print_current_number (whitespace number @ print_current_number)*;
}%%


%% write data;

static uint8_t cs;
static uint8_t current_number;

void init_microscript(void) {
	%% write init;
}


void parse_microscript(const char *p, uint16_t len, uint8_t is_eof) {
	const char * pe = p + len;
	char * eof = is_eof? pe : ((char*)0);

	%% write exec;
}
Chương trình C sử dụng module microscript.pl: main.c Code:
int 
main (int argc, char *argv[])
{
	char * buffer = "89 1 234  5|6 789a";
	init_microscript();
	parse_microscript(buffer, 10, 0);
	return 0;
}
Kêt quả mà mình mong muốn: Code:
89
1
234
Tuy nhiên, kết quả thực tế: Code:
8
89
1
2
23
234
]]>
/hvaonline/posts/list/44589.html#274982 /hvaonline/posts/list/44589.html#274982 GMT