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

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3330 | 回復(fù): 3
打印 上一主題 下一主題

一個(gè)sed寫的圖靈機(jī) [復(fù)制鏈接]

論壇徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-03 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-04 06:20:00
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2008-05-29 20:42 |只看該作者 |倒序?yàn)g覽
還在加班,不斷修改、編譯數(shù)字電路
無聊中在這里看一個(gè)圖靈機(jī)
該圖靈機(jī)用sed編寫,源碼如下:

  1. #! /bin/sed -f
  2. #
  3. # turing.sed -- emulate a Turing machine
  4. #
  5. # Christophe Blaess <[email]ccb@club-internet.fr[/email]>
  6. # [url]http://perso.club-internet.fr/ccb/[/url]

  7. # See text file for information about Turing Machine script.

  8. # Read all the instructions, and add a final newline.
  9. :read
  10. N
  11. $!b read
  12. G

  13. # Delete comments extending from a '#' to the end of the line.
  14. s/#[^\n]*\n//g
  15. s/#.*$//g

  16. # Use a colon to separate the instructions.
  17. s/\n/:/g

  18. # Is there an initial tape ?
  19. /|/ s/\(.*\)|\([^:]\)\([^:]*\):\(.*\)/|\2|\3:\1\4/

  20. # else insert a blank one.
  21. /|/!s/\(.*\)/| |:\1/

  22. # Reserve the storage place at the beginning of the pattern space,
  23. # then set the current state to zero.
  24. s/\(.*\)/0x\1/

  25. # Start the machine !
  26. :loop
  27.         # Display only the tape and the state.
  28.         h
  29.         # (comment out the next two lines to see internal data when
  30.         #  debuging TM script)
  31.         s/:.*//
  32.         s/^\(.\)./(\1) /
  33.         p
  34.         g

  35.         # Check the content of the current cell.
  36.         /|[^:|]|/!{
  37.                 s/.*/Internal error in the Turing machine/
  38.                 q
  39.         }

  40.         # Store in second position the symbol read on the tape
  41.         s/^\(.\).\(.*\)|\(.\)|\(.*\)/\1\3\2|\3|\4/

  42.         # Have we reached a final state ?
  43.         /^\(.\).*:\1/!{
  44.                 s/\(.\).*/Final state \1 reached... end of processing/
  45.                 q
  46.         }

  47.         # Is there an instruction for this state and this cell content ?
  48.         /^\(..\).*:\1/!{
  49.                 s/^\(.\)\(.\).*/No instruction for state \1 and cell \2/
  50.                 q
  51.         }

  52.         # Look for the new content to write.
  53.         /^\(..\).*:\1[^:|]/!{
  54.                 s/.*/I can't write this symbol on the tape!/
  55.                 q
  56.         }
  57.         s/^\(..\)\(.*\)|.|\(.*\):\1\(.\)/\1\2|\4|\3:\1\4/

  58.         # Look for the direction of movement.
  59.         /^\(..\).*:\1.[ LRlr]/!{
  60.                 s/.*/Movement must be specified as L, R or space/
  61.                 q
  62.         }
  63.         # Clear the substitute flag that we will use later.
  64.         t nop
  65.         :nop
  66.         /^\(..\).*:\1. / {
  67.                 # Direction = ' ' -> Don't move the head
  68.                 b end_move
  69.         }
  70.         /^\(..\).*:\1.[Ll]/ {
  71.                 # Move the head to the left if the tape is long enough,
  72.                 s/^\(..\)\(.*\)\(.\)|\(.\)|/\1\2|\3|\4/
  73.                 t end_move
  74.                 # else extend the tape with an empty cell.
  75.                 s/|\(.\)|/| |\1/
  76.                 b end_move
  77.         }

  78.         # Move the head to the right, if the tape is long enough,
  79.         s/|\(.\)|\([^:]\)/\1|\2|/
  80.         t end_move
  81.         # else extend the tape with an empty cell.
  82.         s/|\(.\)|/\1| |/

  83.         :end_move

  84.         # Check the new state,
  85.         /^\(..\).*:\1..[^:|]/!{
  86.                 s/.*/I can't use this symbol as new state/
  87.                 q
  88.         }
  89.         # then switch the machine state
  90.         s/^\(.\)\(.\)\(.*\):\1\2\(..\)\(.\)/\5\2\3:\1\2\4\5/

  91.         # Garbage collector : cut the blank portions of the tape,
  92.         # on the left,
  93.         s/\(..\) */\1/
  94.         # then on the right.
  95.         s/\(..\)\([^:]\) *:/\1\2:/

  96.         b loop

  97. ###### end of the script
復(fù)制代碼

[ 本帖最后由 cjaizss 于 2008-5-29 21:39 編輯 ]

評(píng)分

參與人數(shù) 1可用積分 +3 收起 理由
prolj + 3

查看全部評(píng)分

論壇徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-03 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-04 06:20:00
2 [報(bào)告]
發(fā)表于 2008-05-29 21:39 |只看該作者
改一下標(biāo)題,呵呵

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2008-05-30 23:32 |只看該作者
曲高和寡

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2011-12-25 00:48 |只看該作者
我使用的sed,一般也不超過3、5行。。。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP