Computerdeutsch

From Esolang
Jump to navigation Jump to search

Computerdeutsch ("Computer-German") is an esolang by User:Orangeyy based on the grammar and vocabulary of the German language. If you don't know some German, this probably won't make sense. If you do know German, it still probably won't make any sense.

It is somewhat like C in some respects and could maybe be compiled to C.

Overview

Syntax

  • Every statement ends with a period, except in some control structures.
  • All variables must have names that begin with a capital letter, and they must always be referred to with a capital letter.
  • Anything at the beginning of a line gets capitalized.
  • Whitespace includes newlines and tabs. Single spaces are NOT whitespace.

The value of the previous statement can be used in the next line as es.

  • Umlauted letters matter! mannlich won't be interpreted the same as männlich.
  • Every program ends with Tschüss! ("bye!").

Constants and variables

Variables

All variables must have names that begin with a capital letter. When you define a variable, you must also define its type using one of the nominative articles (described in the next section). This article must agree with the variable's data type and also indicates its role in the statement.

Defining a variable:

   <article> <variable name> ist <value>.

To define an empty variable, <value> is replaced with neu.

Changing a variable uses the same syntax as defining one. Declaring an existing variable with neu re-initializes and clears it.

When dealing with lists, ist becomes sind. List names must also end in -en.

Some functions accept a dative variable. The result of the function will be stored into the dative variable. The variable must already exist for this to be done.

Constants

Defining a constant is very similar:

   <article> <constant name> ist immer <value>.

Trying to change the constant later will result in an error.

Datatypes

Type Nominative Accusative Dative Genitive Literal Name
int der den dem - 123 männlich ("masculine")
bool die die der - ja, nein weiblich ("feminine")
float das das dem - 12.3 sächlich ("neutral")
list die die den der 1, 2, und 3 mehrzahl ("plural")

Any disagreement in datatype will result in an error, such as assigning an int variable a float value, supplying a function that takes a float a bool, etc. Conversion between types is 100% manual using functions.

The nominative case is usually for assigning a variable. Accusative case is usually for getting the value of a variable, and the dative case is usually for grabbing what a function returned and storing it in the variable. There are some special cases which will be noted.

Comments

Comments are surrounded by parentheses (like this).

Lists

Lists are treated as plural. They are a fixed length and may only contain one datatype. When defining a list, you must specify this datatype. List indices start at 1, not 0. Lists may not contain other lists.

Defining a list:

   Die <datatype name>e <list name> sind (<literal list or name of other list>).

Example:

   Die männliche Nummeren sind 1, 2, und 3.

Defining an empty list:

   Die <list length> <datatype name>e <list name> sind neu.

Example:

   Die 20 weibliche Dinge sind neu.

Getting a list value uses the preposition von ("of"). This preposition makes the article after it dative, because German.

   <nominative or accusative list article> <index>. von der <list>

Example:

   Die männliche Dingen sind 3, 4, 5, und 6.
   
   Der Ding ist den 3. von der Dingen. (variable Ding is now 5)
   Der 2. von der Dingen ist 10.       (changes item 2 of Dingen to 10)

Using a variable as an index uses the genitive case:

   <variable article> <index variable> der <dative list name> <list>

Example:

   Der Index ist 3.
   Die weibliche Boolen sind ja, nein, nein, ja.
   
   Der X ist den Index der Boolen. (X is now nein)

Strings

Computerdeutsch doesn't directly support strings, but there is a string notation. Before the program is run, the interpreter/compiler converts all strings to lists of ASCII values.

Any text enclosed in „these quotes” is automatically converted into a list of ASCII values by the compiler.

   „Hallo!” → 72, 101, 108, 108, und 111

Expressions

An expression is an inequality that returns either ja or nein.

Expression Meaning
x ist gleich y x == y ("x is the same as y")
x ist mehr als y x > y ("x is more than y")
x ist weniger als x < y ("x is less than y")

When placed after wenn, the ist gets moved to the end of the expression. Because German, again.

   Wenn X weniger als 10 ist,

Logical operators

Logical operators can only appear between expressions or boolean variables.

The logical operators are:

Operator Meaning
x und y x and y
x oder y x or y
nicht x / x nicht not x

Depending on the implementation, operators may or may not be able to be chained.

Math

Math is done within a berechne (“calculate”) statement.

   berechne <dative variable> <math expression>

This interprets the expression and stores the result in the dative variable. If no dative variable is specified, the result goes to the special variable (described later).

Math operators:

Operator Meaning
x plus y x + y
x minus y x - y
x mal y x * y
x geteilt durch y x / y
x modul y x % y

All operations return either int or float depending on the types of the arguments, except modul, which always returns int. An operation can't be performed on two values of different types.

Order of operations may or may not be supported depending on the compiler/interpreter. To group operations, use parentheses.

Flow control

Wenn (if) statement

   Wenn <bool> stimmt / Wenn <expression>,
       < code if true >,
       < code if true >.

Wenn nein (if-else) statement

   Wenn <bool> stimmt / Wenn <expression>,
       < code if true >,
       < code if true >.
   Und wenn nein,
       < code if false >,
       < code if false >.

After a wenn statement, every line must end with a comma instead of a period, until the end of the code block.

Loop

TODO: think of something more creative/esoteric for loops.

   Schlaufe:
       < code >.
       < code >.
   
       Wenn <bool> stimmt, brech aus. (optional)
   Wiederhol.

brech aus ("break out") is like a break statement, and can be placed anywhere within the loop, or omitted for an infinite loop.

Functions

Defining a function:

   <function name>en ist:
       < code >.
       Gib <value/var> zurück.
   mit <argument1>, <argument2>, ... und <argument3>.

Function names must end in -en when defining them, but the -en is omitted when calling the function. You must define the type and name of each argument using the appropriate dative article. Gib ... zurück ("give ... back") returns a value which can be stored into a variable or ignored by the call. It is equivalent to "return" in many actual programming languages.

Calling a function:

   <function name> <dative var> <argument1>, <argument2>, ... und <argument3>.

Here, the dative variable is where the result is stored.

When a function takes no arguments but returns something, the call looks like this:

   functionname für <accusative var>.

The accusative variable accepts the value returned by the function.

Example:

   Zahlen ist:        ( define a function named “zahl(en)” )
       Gib den Value plus den Step berechnet zurück. ( return Value + Step; )
   für den Value und den Step.
   Der X ist 1.        ( int X = 1; )
   
   Zahl dem X den X und 2.    ( X = zahl(X, 2); )

When a function is called without a variable to store the returned value, the value is stored in a temporary variable where it can be used until another function overwrites it. This special variable can be used by using a special pronoun instead of a variable.

   Berechne 5 plus 6. ( stores 11 in the special variable )
   Druck ihn. ( prints 11 )

The pronoun differs depending on the data type, so you need to pay attention to what type will be returned when using this feature.

Type Pronoun
männlich (int) ihn
weiblich (bool) sie
sächlich (float) es

These pronouns can only be used as arguments in the accusative case; they can't be assigned or written to. Doing so will result in a syntax error. Lists can't be stored in this variable.

Builtin Functions

These functions are included with the language. In German, some verbs have prefixes that move to the end of the sentence. The same is true for some of the predefined functions, so pay attention!

I/O

   druck <accusative list of characters or single character>. ("print")

Takes either a single character ASCII value (int) or a list of such and prints them to the console.

   lies für <accusative var>. ("read")

Reads a list of characters entered by the user into a chosen variable. If the variable is an int, only the first character will be read. If it is a list, all input will be read.

   druck <accusative int/float> wie eine Nummer. ("print ... like a number")

Prints an integer or float as text.

   lies für <accusative int/float> wie eine Nummer. ("read ... like a number")

Takes input and converts it to an int or float.

Type conversion

   mach (<dative int/float>) <accusative int/float> männlich/sächlich. ("make ... masculine/feminine")

Truncates a floating point number into an int, or vice versa.


List operations

   mach (<dative list>) <accusative list 1>, <accusative list 2> fest. ("make ... whole")

Concatenates the lists. The lists must contain the same datatype.

   schneid (<dative list>) <accusative list>, <start index>, und <end index>. ("cut")

Returns a list of the values between the start and end indices of the accusative list.

Math

   erhöh (<dative int>) <accusative int> (bei <step>). ("increase (by ...)")

Increments the accusative int by 1 and stores it in the dative int. Default step is 1. Same as <int> ist <int> plus <step> berechnet.

   verringere (<dative int>) <accusative int> (bei <step>). ("decrease (by ...)")

Same as erhöh, but decrements instead.

Sample code

(Most of these are untested because there isn't an implementation yet.)

Hello world:

   Druck „Hallo, Welt!”.
   Tschüss!

Cat (up to 100 characters):

   Die 100 männliche Charakturen sind neu.
   Lies für die Charakturen.
   Druck die Charakturen.
   Tschüss!

Rule 110 cellular automaton (probably):

   Der SPACE ist immer 32.
   Der HASHTAG ist immer 35.
   
   Die männliche Cellen sind „                              # ”. # 32 elements long #
   
   Converten ist:
   	Der X ist 0.
   	Die Multiplieren sind 1, 2, und 4.
   	Der J ist 1.
   	Schlaufe:
   		Berechne den J der Multiplieren plus den J der Staten.
   		Berechne dem X ihn plus den X.
   	Gib den X zurück.	
   mit der Staten.
   
   Schlaufe:
   	Druck die Cellen.
   	
   	Die Nexten sind die Cellen.
   	
   	Der I ist 1.
   	Schlaufe:
   		Die 3 männliche Staten sind neu.
   		
   		Berechne den I plus 2.
   		Schneid der Staten die Cellen, den I, und ihn.
   		
   		Der State ist neu.
   		Convert dem State die Staten.
   		
   		Wenn der State 0 ist,
   			der Nextcell ist den SPACE.
   		Wenn der State 1 ist,
   			der Nextcell ist den HASHTAG.
   		Wenn der State 2 ist,
   			der Nextcell ist den HASHTAG.
   		Wenn der State 3 ist,
   			der Nextcell ist den HASHTAG.
   		Wenn der State 4 ist,
   			der Nextcell ist den SPACE.
   		Wenn der State 5 ist,
   			der Nextcell ist den HASHTAG.
   		Wenn der State 6 ist,
   			der Nextcell ist den HASHTAG.
   		Wenn der State 7 ist,
   			der Nextcell ist den SPACE.
   		
   		Berechne den I plus 1.
   		Ihn der Nexten ist den Nextcell.
   		
   		Wenn der I 30 ist,
   			brech aus.
   	Wiederhol.
   	
   	Die Cellen sind die Nexten.
   Wiederhol.

Rule 110 is Turing-complete, so this implementation makes Computerdeutsch Turing-complete (technically).

Implementation

There is an implementation in progress from User:Orangeyy, kind of. It may or may not be finished.