dd/dd

From Esolang
Jump to navigation Jump to search

dd/dd is something created by User:Zzo38, based on dd/sh but different. It is based on the UNIX 'dd' command, but it doesn't use 'dd' command, actually, because it is different.

Syntax

All numbers are hexadecimal in uppercase letters. Everything is case-sensitive. All control characters are treated the same as spaces. Spaces separate parts of a command, semicolons separate commands, and you can use [] around a code to include the output of that command there, and () for just the number for the length of its output instead of that command's output itself, and you can use {} around anything to treat what it is inside there as a text string without requiring escaping characters (but it must have balanced {}, except if they are escaped by backslashes). Any character can be escaped from its normal meaning by backslashes, and you can also put backslashes followed by the hex code of the character you want. Comments start with # and are until end of the line.

Variables

You can have variables with any names you want, but the first character indicates the type of varilable. The possible kinds of variables are:

  • $ String variable: This is a basically string variable. There can be a length and any number of bytes as the value (even null bytes are allowed).
  • * Null variable: Regardless of what is written to here, it will always be completely empty.
  • @ Numeric variable: It has a length, but all bytes in its value are all null. Any bytes written become null.
  • ! Literal string value: The rest of the name is the literal string which is its value. If it is written, anything written becomes ignored.
  • & Literal numeric value: Put a number, it is treated as the value being that many null bytes. You can put multiple number separated by commas, to make multiply numbers together. If it is written, anything written becomes ignored.
  • ? Standard I/O: Deals with standard I/O. If the rest of the name is blank it will be the current subroutine/subprogram's I/O, otherwise it will be the entire program's standard I/O streams.
  • = Subprogram: Treats the rest of the name as a subprogram, and will run that subprogram. If this is being used as input, then any output from subprogram is the input. If this is being used as output, then it is sent to the input to subprogram.
  • . Named subprogram: Same as the subprogram, except, that the contents of the subprogram is read from the variable with $ at beginning but other than that the same name as this one.

Commands

Each command line must have one or more parameters which tell it how to operate:

  • <var - Tell the variable to receive input (like if=)
  • >var - Tell the variable to send output (like of=)
  • <num - Set input block size (like ibs=) (default is 1 byte)
  • >num - Set output block size (like obs=) (default is 1 byte)
  • |num - Set number of blocks count (like count=)
  • %num - Set convert size (like cbs=)
  • 'num - Set input skip (like skip=)
  • +num - Set output skip (like seek=)
  • ^mode - Set conversion modes (like conv=) (see below)
  • :var - Reload the current program from that variable. It will restart over from the beginning. Any input/output, if any, will be directed from the <var and >var of this command.
  • /num - Set the character treat as newlines (for conversion commands).
  • _num - Set the character treat as spaces (for conversion commands).

Any numbers in these commands can have commas with multiple numbers to be multiplied.

Conversion modes are given any number of characters of the following:

  • 0 - Act as 'block'
  • 1 - Act as 'unblock'
  • 2 - Act as 'swab'
  • 3 - Act as 'sync'
  • 4 - Act as 'notrunc'
  • 5 - Exit current program/subprogram if no more input is available
  • 6 - Exit current program/subprogram if no more output is acceptable
  • 7 - Unconditionally exit after this command is done
  • 8 - Convert all characters into a backslash followed by the hex code of that character

Examples

Hello world program:

<!Hello,\ World!\0A;

Copy input/output:

^

Beer program:

<&99 >@Count;
<!End >$Last.0;
>$Decrement.F <{
  <@Count '6 >@Count;
};
>$Verse <{
  <!(<@Count){ bottles of beer on the wall}\0A;
  <!(<@Count){ bottles of beer}\0A;
  <!{Take 1 down and pass it around}\0A;
  <@Count '1 >@Count;
  <.Decrement.[<!(<@Count) '(<!(<@Count) '1)];
  :$Next[<$Last.(<@Count)];
};
>$Next <{
  <!(<@Count){ bottles of beer on the wall}\0A\0A;
  :$Verse;
};
>$NextEnd <{
  <!{No more bottles of beer on the wall.}\0A ^7;
};
:$Verse;