เขียนล่ามสำหรับ2B
ฉันชอบภาษาลึกลับของDavid Catt 2B มีหน่วยความจำเก็บไว้ในเทปที่แต่ละเซลล์เป็นเทปแยกไบต์ ('subtape') เขียนล่ามให้มัน!
ข้อกำหนดภาษา
สเปคอย่างเป็นทางการสามารถพบได้ที่นี่ ในสเปคนี้"หมายถึงตัวเลขในช่วง0-9( 0ถูกตีความว่าเป็น10) และ_หมายถึงสตริงที่มีความยาวใด ๆ แต่ละเซลล์เก็บค่าไว้ในช่วง0-255และโอเวอร์โฟลว์ / อันเดอร์โฟลว์จะพันรอบเหมือนที่มันเป็น BF (ขอบคุณ @ MartinBüttner) การแปลงข้อความให้เป็นตัวเลข0-255การใช้รหัส ASCII เนื่องจากฉันไม่สามารถหารายละเอียดเกี่ยวกับเรื่องนี้ได้ฉันจะบอกว่าความยาวของเทปควร255น้อยที่สุด แต่ถ้าคุณรู้อย่างอื่นโปรดแก้ไข
+-------------+----------------------------------------------------------------------------------------------------------------------------------------+
| Instruction |                                                              Description                                                               |
+-------------+----------------------------------------------------------------------------------------------------------------------------------------+
| 0           | Zeroes the current cell and clears the overflow/underflow flag.                                                                        |
| {           | If the current cell is zero, jump to the matching }.                                                                                   |
| }           | A placeholder for the { instruction.                                                                                                   |
| (           | Read a byte from the input stream and place it in the current cell.                                                                    |
| )           | Write the value of the current cell to the console.                                                                                    |
| x           | Store the value of the current cell in a temporary register.                                                                           |
| o           | Write the value of the temporary register to the console.                                                                              |
| !           | If the last addition overflowed, add one to the current cell. If the last subtraction underflowed, subtract one from the current cell. |
| ?           | Performs a binary NOT on the current cell.                                                                                             |
| +"          | Adds an amount to the current cell.                                                                                                    |
| -"          | Subtracts an amount from the current cell.                                                                                             |
| ^"          | Moves the subtape up a number of times.                                                                                                |
| V"          | Moves the subtape down a number of times.                                                                                              |
| <"          | Moves the tape left a number of times.                                                                                                 |
| >"          | Moves the tape right a number of times.                                                                                                |
| :_:         | Defines a label of name _.                                                                                                             |
| *_*         | Jumps to a label of name _.                                                                                                            |
| ~_~         | Defines a function of name _.                                                                                                          |
| @_@         | Calls a function of name _.                                                                                                            |
| %           | Ends a function definition.                                                                                                            |
| #_#         | Is a comment.                                                                                                                          |
| [SPACE]     | Is an NOP.                                                                                                                             |
| [NEWLINE]   | Is treated as whitespace and removed.                                                                                                  |
| [TAB]       | Is treated as whitespace and removed.                                                                                                  |
+-------------+----------------------------------------------------------------------------------------------------------------------------------------+
การทดสอบ
+0+0+0+0+0+0+0+2)+0+0+9)+7))+3)-0-0-0-0-0-0-0-9)+0+0+0+0+0+0+0+0+7)-8)+3)-6)-8)-7-0-0-0-0-0-0)
ควรส่งออก Hello world!
+1:i:{()*i*}
เรียงลำดับของcatโปรแกรมโดยไม่มีการขึ้นบรรทัดใหม่
+1:loop:{@ReadChar@*loop*}@PrintHello@@WriteAll@(~ReadChar~(x-0-3<2o^1>1+1>1%~PrintHello~+0+0+0+0+0+0+0+2)-1+0+0+0)+7))+3)+1-0-0-0-0-0-0-0-0)%~WriteAll~<1x:reverse:{<1v1>1-1*reverse*}o-1:print:{-1<1)^1>1*print*}%
ควรยอมรับชื่อก่อนแล้วกดReturnเอาท์พุทHello name(โดยที่ชื่อคือสิ่งที่ถูกป้อนเข้า)
เครดิตสำหรับโปรแกรมที่จะไปเดวิด Catt
ฉันกำลังทำงานกับโปรแกรมทดสอบเต็มรูปแบบ
กฎระเบียบ
- ช่องโหว่มาตรฐานเป็นสิ่งต้องห้าม
- ล่ามของคุณจะต้องตรงตามข้อกำหนดทั้งหมดยกเว้นสำหรับความคิดเห็นที่ไม่จำเป็น
เกณฑ์การให้คะแนน
- นี่คือโค้ดกอล์ฟซึ่งมีจำนวนน้อยที่สุดที่จะชนะ!
- -10 ไบต์หากล่ามของคุณจัดการกับความคิดเห็น
ลีดเดอร์บอร์ด
นี่เป็นตัวอย่างข้อมูลเพื่อสร้างทั้งกระดานผู้นำปกติและภาพรวมของผู้ชนะตามภาษา
เพื่อให้แน่ใจว่าคำตอบของคุณปรากฏขึ้นโปรดเริ่มคำตอบด้วยหัวข้อโดยใช้เทมเพลต Markdown ต่อไปนี้:
# Language Name, N bytes
ที่Nมีขนาดของส่งของคุณ หากคุณปรับปรุงคะแนนของคุณคุณสามารถเก็บคะแนนเก่าไว้ในพาดหัวได้ ตัวอย่างเช่น
# Ruby, <s>104</s> <s>101</s> 96 bytes