DNA-Sharp: Difference between revisions

From Esolang
Jump to navigation Jump to search
Content deleted Content added
→‎Fibonacci Numbers:: Fixed errors in the Fibonacci Numbers example code
彻底消除了对于''=''符号的歧义
Tag: Reverted
Line 26: Line 26:
| GCCG || ] || || ]
| GCCG || ] || || ]
|-
|-
| TAAT * || || *pointer = *newpointer || = or '':='' ****
| TAAT * || || *pointer = *newpointer || :=
|-
|-
| TAGC * || || *pointer += *newpointer || +=
| TAGC * || || *pointer += *newpointer || +=
Line 48: Line 48:


''*** newpointer is only active after [[#Special Commands|Special Commands]]''
''*** newpointer is only active after [[#Special Commands|Special Commands]]''

''**** This change is unofficial and intends to remove ambiguous use of =''


==Interpreter(s)==
==Interpreter(s)==
Line 61: Line 59:
# Helix form (see below)
# Helix form (see below)
# Line form (example: "ATGCATATGCATTACG", helix form without "-" and whitespace)
# Line form (example: "ATGCATATGCATTACG", helix form without "-" and whitespace)
# Symbol form (example: "++>=<X.", symbols instead of 4-Letter-Commands, increasing readability)
# Symbol form (example: "++>:=<X.", symbols instead of 4-Letter-Commands, increasing readability)


===Comments===
===Comments===
Line 240: Line 238:


Hello, world! program (symbol form):
Hello, world! program (symbol form):
+++=+=X>=<-*=+=X>=<<+=+=X<+=<--.---.+=<-..+++.>.<+=<.-=<.+++.-=<++.-=<.>+.
+++=+=X>:=<-*=+=X>:=<<+=+=X<+=<--.---.+=<-..+++.>.<+=<.-=<.+++.-=<++.-=<.>+.


== Other Examples ==
== Other Examples ==
Line 360: Line 358:
CG
CG


+++++*=X>>+>>=<<<<+++++++<<<<[>>>=<+=<<X<<=>X>=>X>~><<<<-]
+++++*=X>>+>>:=<<<<+++++++<<<<[>>>:=<+=<<X<<:=>X>:=>X>~><<<<-]


===[[Quine]]===
===[[Quine]]===

Revision as of 01:52, 2 August 2025

The title of this article is not correct because of technical limitations. The correct title is actually DNA#.

DNA# is an esoteric programming language which is based on the schematic structure of the DNA molecule and was invented 2009 by User: Benni++.

Logo of DNA#

Commands

There are 16 commands:

Command Brainfuck equivalent C-equivalent Symbols for symbol form
ATAT > pointer++ / newpointer++ *** >
ATGC < pointer-- / newpointer-- *** <
ATTA + +
ATCG - -
GCAT . (Output as ASCII) .
GCGC , (ASCII input) ,
GCTA [ [
GCCG ] ]
TAAT * *pointer = *newpointer :=
TAGC * *pointer += *newpointer +=
TATA * *pointer -= *newpointer -=
TACG * *pointer *= *newpointer *=
CGAT * *pointer /= *newpointer /=
CGGC . (Output as integer value) ~
CGTA , (Integer input) ?
CGCG - (NOP) X**

* A line of ATAT or ATGC commands, selecting "newpointer", can follow these commands (see Special Commands)

** Adding three CGCG commands in a row will print out the program's source (line form)

*** newpointer is only active after Special Commands

Interpreter(s)

For now, there is only a single interpreter, written in Javascript. It simulates a Turing-complete 1D data matrix using a simple javascript array.

Language Basics

Appearance

There are three forms of DNA#:

  1. Helix form (see below)
  2. Line form (example: "ATGCATATGCATTACG", helix form without "-" and whitespace)
  3. Symbol form (example: "++>:=<X.", symbols instead of 4-Letter-Commands, increasing readability)

Comments

Comments can be put into the code similar to C/C++:

    AT
   T--A
  A----T
  T-----A
  A-----T
  T----A       /* Comment  */
   A--T
    TA
    AT
   A--T
  A----T
  T-----A
  T-----A
  G----C
   A--T
    GC

Special Commands

Following commands like =(TAAT), +=(TAGC) etc. it is possible to add a line of ATAT or ATGC commands to select the second variable.

Example (symbol form):

+++>+=<X>

Commented:

+ + +         /* add 3 to reg0 */
>             /* select reg1   */
+= <          /* add reg(1-1) (= reg0 ) to reg1 (reg1 is set to 3) */
X             /* nop to stop interpreter from going to non-existant reg(-1) */
>             /* continue in code... */

C-Equivalent to upper example:

// pos = 0
reg[pos]++;
reg[pos]++;
reg[pos]++;
pos++;
reg[pos] += reg[pos-1]; // actually newpos = pos; newpos--; reg[pos] += reg[newpos]
pos++;

The compiler/interpreter first sets newpos to pos, then parses through the following code until he finds an command inequal ATAT or ATGC. Doing this, he increments (decrements for ATGC) newpos. In the end the actually selected operation (in this case +=) is done.

Hello World Program

Hello, World! Program in DNA# (Helix form):

HelloWorld.dna

    AT
   T--A
  A----T
  T-----A
  T-----A
  G----C
   T--A
    GC
    CG
   C--G
  A----T
  A-----T
  T-----A
  A----T
   A--T
    GC
    AT
   C--G
  T----A
  C-----G
  T-----A
  G----C
   C--G
    CG
    AT
   A--T
  T----A
  A-----T
  A-----T
  G----C
   A--T
    GC
    TA
   G--C
  T----A
  G-----C
  C-----G
  C----G
   A--T
    GC
    TA
   G--C
  A----T
  G-----C
  A-----T
  C----G
   A--T
    CG
    GC
   A--T
  A----T
  C-----G
  A-----T
  C----G
   A--T
    CG
    GC
   A--T
  T----A
  G-----C
  A-----T
  G----C
   A--T
    CG
    GC
   A--T
  G----C
  A-----T
  A-----T
  T----A
   A--T
    TA
    AT
   T--A
  G----C
  A-----T
  A-----T
  A----T
   G--C
    AT
    AT
   G--C
  T----A
  G-----C
  A-----T
  G----C
   G--C
    AT
    TA
   T--A
  A----T
  G-----C
  G-----C
  A----T
   A--T
    TA
    AT
   T--A
  A----T
  T-----A
  G-----C
  A----T
   T--A
    TA
    AT
   G--C
  A----T
  T-----A
  A-----T
  T----A
   G--C
    AT
    TA
   T--A
  A----T
  G-----C
  G-----C
  A----T
   A--T
    AT
    AT
   T--A
  G----C
  A-----T

Hello, world! program (line form):

ATTAATTATAGCTAGCCGCGATATTAATATGCATCGTACGTAGCCGCGATATTAATATGCATGCTAGCTAGCCGCGATGCTAGCATGCATCGATCGGCATATCGATCGATCGGCATTAGCATG
CATCGGCATGCATATTAATTAATTAGCATATATGCATATGCTAGCATGCGCATTATAATGCGCATATTAATTAATTAGCATTATAATGCATTAATTAGCATTATAATGCGCATATATATTAGCAT

Hello, world! program (symbol form):

+++=+=X>:=<-*=+=X>:=<<+=+=X<+=<--.---.+=<-..+++.>.<+=<.-=<.+++.-=<++.-=<.>+.

Other Examples

Fibonacci Numbers:

ATTAATTAATTAATTAATTATACGCGCGATATATATATTAATATATATTAATATGCATGCATGCATGCATTAATTAATTAATTAATTAATTAATTAATGCATGCATGCATGCGCTAATATATATATATTAATATGCTAGCATG
CATGCCGCGATGCATGCTAATATATCGCGATATTAATATATCGCGATATCGGCATATATGCATGCATGCATGCATCGGCCG
    AT
   T--A
  A----T
  T-----A
  A-----T
  T----A
   A--T
    TA
    AT
   T--A
  T----A
  C-----G
  C-----G
  C----G
   A--T
    AT
    AT
   A--T
  A----T
  T-----A
  A-----T
  A----T
   A--T
    AT
    TA
   A--T
  A----T
  G-----C
  A-----T
  G----C
   A--T
    GC
    AT
   G--C
  A----T
  T-----A
  A-----T
  T----A
   A--T
    TA
    AT
   T--A
  A----T
  T-----A
  A-----T
  T----A
   A--T
    TA
    AT
   G--C
  A----T
  G-----C
  A-----T
  G----C
   A--T
    GC
    GC
   T--A
  A----T
  A-----T
  A-----T
  A----T
   A--T
    AT
    TA
   A--T
  A----T
  G-----C
  T-----A
  G----C
   A--T
    GC
    AT
   G--C
  C----G
  C-----G
  A-----T
  G----C
   A--T
    GC
    TA
   A--T
  A----T
  A-----T
  C-----G
  C----G
   A--T
    AT
    TA
   A--T
  A----T
  A-----T
  C-----G
  C----G
   A--T
    AT
    CG
   G--C
  A----T
  A-----T
  A-----T
  G----C
   A--T
    GC
    AT
   G--C
  A----T
  G-----C
  A-----T
  C----G
   G--C
    CG
+++++*=X>>+>>:=<<<<+++++++<<<<[>>>:=<+=<<X<<:=>X>:=>X>~><<<<-]

Quine

   CG
  C--G
 C----G
 C-----G
 C-----G
 C----G
CGCGCGCGCGCG
XXX

External resources

DNA# online interpreter