亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
樓主: cjaizss
打印 上一主題 下一主題

娛樂一下,介紹一種語言——brainfuck [復制鏈接]

論壇徽章:
0
21 [報告]
發(fā)表于 2008-06-04 15:57 |只看該作者
該語言名副其實: 操 大腦

論壇徽章:
0
22 [報告]
發(fā)表于 2008-06-04 16:58 |只看該作者
這東西就是用來玩的,呵呵
程序員自己的游戲

論壇徽章:
0
23 [報告]
發(fā)表于 2008-06-05 00:50 |只看該作者
  友情支持一下。偶給你加個精表示表示

論壇徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-08-03 06:20:00數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-08-04 06:20:00
24 [報告]
發(fā)表于 2008-06-05 01:34 |只看該作者
原帖由 mik 于 2008-6-5 00:50 發(fā)表
  友情支持一下。偶給你加個精表示表示

呵呵,終于等到你來了,整一個月沒上線了,.......

論壇徽章:
0
25 [報告]
發(fā)表于 2008-06-05 01:42 |只看該作者
原帖由 cjaizss 于 2008-6-5 01:34 發(fā)表

呵呵,終于等到你來了,整一個月沒上線了,.......


呵呵,brainfuck 你是自創(chuàng)的嗎? 是不是應該給個原創(chuàng)才對

論壇徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-08-03 06:20:00數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-08-04 06:20:00
26 [報告]
發(fā)表于 2008-06-05 11:44 |只看該作者
brainfuck語言不是自創(chuàng)的,第一個用sed寫的編譯器不是我寫的,后面都是我寫的

論壇徽章:
0
27 [報告]
發(fā)表于 2008-06-05 12:31 |只看該作者

回復 #21 zhongfangqing 的帖子

要用書面語:強奸大腦。文明多了,

論壇徽章:
0
28 [報告]
發(fā)表于 2008-06-05 12:49 |只看該作者
我發(fā)個Python的版本 基本上是翻譯了樓主的C代碼到python
#!/usr/bin/env python
import sys

class VM():
    def __init__(self):
        self.stack=[0 for i in range(256)]
        self.stackLen=0;
        self.pool=[ 0 for i in range(4096)]
        self.pointer=0
        self.currentInstructIndex=0
        self.codeLen=0
        self.code=''
    def run(self,reader):
        self.code=reader.read()
        print "Run:",self.code
        self.codeLen=len(self.code)
        while self.currentInstructIndex<self.codeLen:
            self.bfInterpreter(self.code[self.currentInstructIndex])
            self.currentInstructIndex+=1
    def dump(self,size=10):
        pool=self.pool[:size]
        stack=self.stack[:size]
        print '============================================================================'
        print 'pool',pool
        print 'stack',stack
        print 'CurrentInstructIndex:%d,%s'%(self.currentInstructIndex,self.code[self.currentInstructIndex])
    def bfInterpreter(self,instruct):
        if instruct=='+':
                self.pool[self.pointer]+=1
        elif instruct=='-':
                self.pool[self.pointer]-=1
        elif instruct=='>':
                self.pointer+=1
        elif instruct=='<':
                self.pointer-=1
        elif instruct=='.':
                try:
                    sys.stdout.write(chr(self.pool[self.pointer]))
                except:
                    print r"can't  print:",self.pool[self.pointer]
        elif instruct==',':
                self.pool[self.pointer]=ord(sys.stdin.read())
        elif instruct=='[':
                if self.pool[self.pointer]!=0:
                    try:         
                        self.stack[self.stackLen]=self.currentInstructIndex
                        self.stackLen+=1
                    except:
                        print self.stackLen
                        raise IndexError
                else:
                    j=0;k=0
                    for k in range(self.currentInstructIndex,self.codeLen):
                        if self.code[k]=='[':
                            j+=1
                        if self.code[k]==']':
                            j-=1
                        if j==0:break
                    if j==0:
                        self.currentInstructIndex=k
                    else:
                        print 'Error'
                        return None
                        
        elif instruct==']':
                self.stackLen-=1
                self.currentInstructIndex=self.stack[self.stackLen]-1

if __name__=='__main__':
    if len(sys.argv)<=1:
        import StringIO
        sample='++++++++++[>+++++++>++++++++++>+++>+\
<<<<-]>++.>+.+++++++..+++.>++.<<++++++++++++++\
+.>.+++.------.--------.>+.>.'

        reader=StringIO.StringIO(sample)
    else:
        print 'Run file',sys.argv[1]
        reader=open(sys.argv[1])
    vm=VM()
    vm.run(reader)


[ 本帖最后由 zarra 于 2008-6-5 12:55 編輯 ]

論壇徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-08-03 06:20:00數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-08-04 06:20:00
29 [報告]
發(fā)表于 2008-06-05 13:00 |只看該作者
其實又想到了一個重要的優(yōu)化,只是現(xiàn)在沒時間,有時間把它寫出來。

論壇徽章:
0
30 [報告]
發(fā)表于 2008-06-05 15:23 |只看該作者
佩服。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP