Ragel状态机生成器

Ragel可以把正则表达式翻译成有限状态机(FA)的各种语言表示,包括C、C++、Objective-C、D、Java和Ruby。Regular Expression和FA的用途很广,可以用于协议分析、数据解析、词法分析、用户数据校验等。在Ragel的帮助下,写一个atoi的函数非常容易,而且比标准库提供的atoi函数性能要高。

/*
 * Convert a string to an integer.
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
%%{
	machine atoi;
	write data;
}%%
 
long long atoi( char *str )
{
	char *p = str, *pe = str + strlen( str );
	int cs;
	long long val = 0;
	bool neg = false;
 
	%%{
		action see_neg {
			neg = true;
		}
 
		action add_digit {
			val = val * 10 + (fc - '0');
		}
 
		main :=
			( '-'@see_neg | '+' )? ( digit @add_digit )+
			'\n';
 
		# Initialize and execute.
		write init;
		write exec;
	}%%
 
	if ( neg )
		val = -1 * val;
 
	if ( cs &lt; atoi_first_final )
		fprintf( stderr, "atoi: there was an error\n" );
 
	return val;
};
 
#define BUFSIZE 1024
 
int main()
{
	char buf[BUFSIZE];
	while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
		long long value = atoi( buf );
		printf( "%lld\n", value );
	}
	return 0;
}

Google Talk Video in Gmail

Google 的新发明

le temps pour l’amour

Whether you believe me or not,
I fell in love, again, fabulously, rationally, and, radically.

May things go well, Amen.

Here’s to the Crazy Ones

Here’s to the Crazy Ones.
The misfits.
The rebels.
The troublemakers.
The round pegs in the square holes.
The ones who see things differently.
They’re not fond of rules.
And they have no respect for the status quo.
You can quote them, disagree with them,
disbelieve them, glorify or vilify them.
About the only thing that you can’t do, is ignore them.
Because they change things.
They invent. They imagine. They heal.
They explore. They create. They inspire.
They push the human race forward.
Maybe they have to be crazy.
How else can you stare at an empty canvas and see a work of art?
Or, sit in silence and hear a song that hasn’t been written?
Or, gaze at a red planet and see a laboratory on wheels?
We make tools for these kinds of people.
While some may see them as the crazy ones, we see genius.
Because the ones who are crazy enough to think that they can change the world,
are the ones who do.

Think different.

思念

我说要思念一些人,所以要思念。

一路顺风。

老歌与新歌

最近在Amazon上淘了两张李云迪的新碟。当然,其实只有其中一张是今年的,另一张是去年的。两张碟都是钢协,去年的一张是李云迪常弹的李斯特和肖邦,今年的一张是和小泽征尔、柏林爱乐合作的Prokofiev和Ravel。李云迪一向擅长李斯特和肖邦,能与他的肖邦版本比较的只有鲁宾斯坦的肖邦。

然而今年的Prokofiev和Ravel的钢协现场录音,的确令人耳目一新。李云迪的创造力比朗朗好多了。

数学的信徒

连生活的很多问题都相信数学可以解决,这算不算是中毒了?呵呵。

顺便一提,iphone上的wordpress还是不错的。

Supported by Webinit Consulting