出力チルダとプラス


5

this questionに触発されて、私はホワイトスペースで次のテキストを出力するプログラムを書きました:

p2020_0

instructionsを正しく理解していれば、プログラムの動作を説明するためにソースコードにコメントを残しましたが、ここでも重要な部分を説明します:

p2020_1

プログラムは、スタック操作ステートメントを開始するために、Sで示されるスペースで開始します。スペースの後に、ティルデ(126)の値をバイナリで入力します。スペースは0を表し、タブは1を表します。次に、改行(L)を入力して、バイナリ文字の終わりを示します。

次に、TLがI / Oコマンドになり、次にSSがスタックの一番上に値を出力します。

これは、「〜」、「+」、およびL(改行)の3文字で続きます。これを外部または内部で単純化する方法はありますか?このプログラムはIdeoneで実行できます。

S S S T T   T   T   T   T   S L---BEGINS-WITH-SPACE-TO-SIGNIFY-STACK-MANIPULATION-OTHER-VALUES-ARE-BINARY-CODE-FOR-126
T   L---BEGIN-OUTPUT-COMMAND
S S S S S T T   T   T   T   T   S L---BELOW-HERE-LINES-NEED-SS-AT-BEGINNING-TO-OUTPUT-VALUE-AT-TOP-OF-STACK
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L---END-OF-FIRST-LINE
S S S S S T S T S L---NEW-LINE(BINARY-CODE-10)
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L---BINARY-CODE-43-FOR-PLUS
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L---END-OF-SECOND-LINE
S S S S S T S T S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L---END-OF-THIRD-LINE
S S S S S T S T S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L---END-OF-FOURTH-LINE
S S S S S T S T S L
T   L---EXTRA-NEW-LINE-TO-PUSH-END-OF-PROGRAM-OUTPUT-DOWN
S S L---TRIPLE-LINEFEED-TO-END-PROGRAM
L
L
7

I know nothing of whitespace, but your code strikes me as something like this:

...
Console.Write("+");
Console.Write("~");
Console.Write("+");
Console.Write("+");
Console.Write("~");
Console.Write("+");
Console.Write("+");
Console.Write("~");
Console.Write("+");
Console.Write("+");
...

You have a heap, and you're not using it.

Heap access commands look at the stack to find the address of items to be stored or retrieved. To store an item, push the address then the value and run the store command. To retrieve an item, push the address and run the retrieve command, which will place the value stored in the location at the top of the stack.

http://compsoc.dur.ac.uk/whitespace/tutorial.html

I'm not going to test this, but the idea would be something like this:

  • Push 126 ("~") to heap at address A // tilde
  • Push 43 ("+") to heap at address B // plus

Now, SpaceSpace marks a label, TabTab would be a modulo operation, and TabSpace jumps to a label if the value at the top of the stack is zero: you can implement a form of conditional goto loop. And you can call a subroutine with SpaceTab, and return to caller with TabLF.

Make a subroutine that pushes the value at address A ("~") to the stack, and outputs it before discarding (LFLF) the value at the top of the stack, and then make another subroutine that does the same thing for address B ("-"). Or better, make one that pops an address from the stack, reads the heap value at that address and pushes it to the stack, outputs it and removes it from the stack, then returns to caller. For the purpose of this post let's call this subroutine PrintChar.

Now, break down the patterns:

  • ~~~~ // pattern A
  • ~+~~ // pattern B
  • +~++ // pattern C

Make a subroutine that pushes address A ("~") onto the stack from the heap and calls PrintChar, 4 times. Or better, store 4 on the heap at address C and implement a goto loop that exits after 4 iterations, and inside that loop you push address A onto the stack from the heap and call PrintChar, once; let's call that subroutine PatternA. Then, implement similar subroutines for PatternB and PatternC.

The rest is simple: make a subroutine that pops the address of a pattern subroutine from the stack, makes 12 iterations of calling that pattern subroutine and then outputs a newline - let's call that PrintLine.

The "main" procedure simply pushes a pattern to the stack and calls PrintLine:

  • Push the address of PatternA to the stack
  • Call PrintLine
  • Push the address of PatternB to the stack
  • Call PrintLine
  • Push the address of PatternC to the stack
  • Call PrintLine
  • Push the address of PatternA to the stack
  • Call PrintLine

And don't forget to comment along the way - I find your commenting not very useful here.