欢天喜地迎国庆,国产开源编程语言 RPP 1.87 公布!

更新例如以下:

1.支持超级宏

2.修复bug


下载地址:

https://github.com/roundsheep/rpp


超级宏能够随意定义语法,制约你的仅仅有想象力:


void main()
{	
	==> 2 3 <==
	
	┏━━━━━┓
	┃ 1     2  ┃
	┃ 3     4  ┃  
	┗━━━━━┛	
}

mac$ ==> _word _word <==
{
	putsl(rstr($0)+rstr($1))
}

mac$ ┏━━━━━┓┃ _word _word ┃ ┃ _word _word ┃┗━━━━━┛
{
	putsl(rstr($0)+'--'+rstr($1)+'--'+rstr($2)+'--'+rstr($3))
}



以下是用RPP实现的BF解释器:


/*
BF解释器,以下是一个BF版的Hello World:
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
*/

void main()
{
	code=getsl
	rbuf<int> data(30000)
	rf.memset(data.begin,0,data.size)
	pd=0
	for pc=0;pc<code.count;pc++
		switch code[pc]
		case `>
			pd++
		case `<
			pd--
		case `+
			data[pd]++
		case `-
			data[pd]--
		case `.
			puts(rstr.format('%c',data[pd]))
		case `,
			data[pd]=rf.getch
		case `[
			if data[pd]==0
				pc=find< ++ >(pc,code,`[,`])
				continue//这里也可用continued
		case `]
			if data[pd]!=0
				pc=find< -- >(pc,code,`],`[)
				continue
}

int find<T>(int pc,rstr& code,int left,int right)
{
	count=0
	for i=pc;;i T
		if code[i]==left
			count++
		elif code[i]==right
			count--
		if count==0
			return i
}


原文地址:https://www.cnblogs.com/jhcelue/p/7025806.html