C Flat

From Esolang
Jump to navigation Jump to search

C Flat (or C♭) is an esoteric programming language that uses music as syntax.

Language overview

A C Flat program is a series of chords and rests. These are grouped into statements that take a certain number of parameters. There is nothing separating each statement, so a statement ends after the set number of parameters have been designated, each of which have either a set length or a pattern that marks their end.

Statements

Statement Description Indicator Parameters
Input Waits for numeric input and stores it at the specified location A 1-note chord or 2-note octave A location
Output Outputs the numeric value stored at the specified location A 3-note chord where the lower interval is greater than or equal to the higher interval A location
Print Outputs the ASCII value stored at the specified location A 3-note chord where the lower interval is less than the higher interval A location
Assign Stores the specified value at the specified location A 2-note chord (not an octave) A location and a value
Label Sets a label (The indicator is the label) A 4-note chord A rest or chord of 4+ notes
Jump Jumps to the label specified in the indicator if the comparison between the two specified values evaluates to true A 4-note chord A comparison and two values

Location

The way variables are stored in C♭ can be thought of as every note on the keyboard having an infinite array of numbers. Therefore, locations start with a single note which defines which array to use. This is followed by a value that represents which item of that array to access.

Value

The first chord of a value defines whether it is a literal or an operation

Type Amount of Notes
Literal Odd
Operation Even

Literal

The rest of the chords of a literal value define the value being returned. Each note on the keyboard is given a value, with Middle C being 0 and higher notes being higher and lower notes being lower. Another way of calculating a notes value is to take its MIDI value and subtract 60. A chord of notes multiplies note values together, and all of the chords in a sequence are added together to get the final value. Since there can be any number of chords in this sequence, it must be ended with a rest.

Operation

The second chord in an operation value defines its type. There are 4 math functions and an operation for getting the value of a variable.

Math operations are all 2 notes, so to get the value of the variable you can just use the location, because it starts with one note. (See above)

The math operations are distinguished by the number of semitones (black and white keys) between the two notes. (two adjacent notes is an interval of 1) These are followed by the two values that are being operated on.

Operation Intervals
Addition 4, 6, 11
Subtraction 2, 5, 8
Multiplication 1, 7, 10
Division 3, 9

Comparison

Comparisons define how the two values of a jump statement should be compared. This is defined by the amount of notes in the chord.

Amount of Notes Type
1 Jump if equal
2 (even interval) Jump if greater
2 (odd interval) Jump if less
3 Jump if not equal

Examples

Hello, World!

Cflathelloworld.png

The program pseudocode is below:

Set Eb4 to 8*9 (72)
Print Eb4 (H)
Set Eb4 to 5*20 + 1 (101)
Print Eb4 (e)
Set Eb4 to 12*9 (108)
Print Eb4 (l)
Print Eb4 (l)
Set Eb5 to 12*9 + 3 (111)
Print Eb5 (o)
Set A4 to 4*11 (44)
Print A4 (,)
Set A4 to 4*8 (32)
Print Eb5 (space)
Set A4 to 12*7 + 3 (87)
Print Eb5 (W)
Print Eb5 (o)
Set Eb5 to 19*6 (114)
Print Eb5 (r)
Print Eb4 (l)
Set Eb4 to 5*20 (100)
Print Eb4 (d)
Set Eb4 to 3*11 (33)
Print Eb4 (!)

External resources