Dirst

Dirst is an Esoteric programming language by David Catt (user:David.werecat) where the source code is a directory.

Introduction
Dirst is the first language that takes directories as input, and is made to be both extensive and filesystem-centric. Since each program is a directory, programs will often be distributed in either script or archive form. Execution times are very IO bounded, so fast disks will significantly improve the execution speed.

Getting Started
The basic building block of Dirst is files and directories. Each file or directory in the program will be executed alphabetically, taking into account directory recursion. Files represent operations, and are executed according to their file name and extension. The extension specifies a subset of instructions and the file name specifies the instruction from that subset and its parameters. Directories represent conditional statements or loops. The directory name will give the condition and specifications for the loop. All subfiles/subdirectories of that directory will be conditionally executed or looped when the directory is executed. Since all looping and conditionals are bounded in scope, jumps (or GOTOs) are not directly allowed. These constructs must be emulated using explicit looping or conditionals. Where a file or directory is to be executed, its creation time is checked first. If the creation time has not already passed, the file or directory will not be executed. As such, programs can implement time activated functionality.

Exception Handling
There are several features to aid in exception handling. There are two types of exception handling: local and global. Exception handling defaults to global, but may be changed at run time. Global exceptions are shared between each directory. Therefore, an exception that occurs in one directory will change the last error code for globally. If an exception is uncaught with global exception handling active, the program will fail and report the exception code. Local exceptions are local to only the current directory. Therefore, an exception that occurs in one directory will only change the last error code for that directory. If an exception is uncaught with local exception handling active, the exception will be thrown up each level of recursion until it is caught or until it reaches the top of the stack, in which case the program fails and an exception code is reported. Exception handling can be enabled or disabled on a per-directory or global basis. To enable exception handling, the appropriate exception toggle must be set to false (0). Setting the toggle to true (-1) will disable exception handling.

Variable Types
There are several types of variables available, split into two main categories: values and arrays. Values are used for all operations and are considered the "active" variable type. Arrays are used for dynamic storage and are considered the "passive" variable type. Of these two categories, variables may be signed 32-bit integers, single precision floating point values, or unicode variable length strings. Type safety is enforced strongly and conversion between types must be performed using the conversion instruction subset. Variables must be created before use. Array variables initialize to a default size of zero, although the size may be modified through the proper instructions. Array variables cannot be used with regular computations, so are recommended for storage only. Variable names are case sensitive and are unlimited in scope, therefore a variable created in any part of the program can be used throughout the program. Variables should be deleted when they are no longer needed to improve performance.

Syntax
Each file or directory name may optionally start with a comment terminated with an exclamation point (!). This can be used to ensure proper sequential execution as well as providing source code commenting mechanics. There may be multiple comments prepended to any file or directory name. After the conditional comment, the instruction follows. Instructions are three letters long and are followed by an underscore (_) and a parameter list also delimited with underscores. Instruction names are not case sensitive and are matched using an invariant locale. Since certain characters are not allowed in filesystem names or are reserved (such as exclamation points, underscores and periods (.)), escape sequences are used. These escape sequences are discussed later. Each parameter represents a variable name or a literal value. When a parameter is parsed, it is first checked as a variable name. If no matching variable name is found, it is then interpreted as a literal value. An exception is thrown if both attempts fail. String interpretation will never fail when retrieving a value, so it is recommended that string variables names are made recognizable to aid maintainability. All variable names are case sensitive. After the instruction and parameters, a file extension is appended to the end of the file name. The extension is prefixed with a period and is a three letter string. File extensions are case insensitive and are matched using an invariant locale. The file extension specifies one of the instruction subsets in which to find the instruction. An invalid or nonexistent file extension will throw an exception. If any directory or file does not contain an instruction or definition, an exception is also thrown. Therefore comments must be mixed in with the source code. It is important to remember to keep file or directory names concise, since some filesystems limit the maximum length of a file or directory path.

Escape Codes
Escape codes are expanded before interpreting a name. Invalid escape codes are kept as their literal values. Escape codes are case insensitive.

Instruction Subsets Reference
The following subsets are defined:

When a value is set as part of an instruction, that value will most likely reside in the first parameter of the instruction. In all examples, the following notations are used:


 * $ : Integer variable or literal integer
 * # : String variable or literal string
 * % : Float variable of literal float

Any variable surrounded by square brackets ([]) is an array variable of the specified type. There are no literal array values.

Scripting
Dirst also supports scripting. Scripts are expanded into a temporary directory and executed from there. A script is a textual representation of the directory tree that makes up a program. Each line of script is a definition for a directory or a file; although unlike the directory programming form a script may contain fully commented lines. A fully commented line must start with a tilde (~) and must maintain tabbing. Any difference in tabbing with tildes will result in directory breaking. This is useful for separating sequential directories. Also, the first line of a new directory must be the name of the directory and cannot be a comment.

Each line is the name of the file or directory. Lines are automatically prefixed with numbering comments by the interpreter when the script is expanded, so there is no need to worry about the order of execution. Each sequential entry in a directory has the same tabbing as the last entry. Whenever an extra tab is added in a line from the last line, that line represents the name of a directory and all sequential statements of the same tabbing are put in that new directory. When a line has less tabs than the last line, a number of directories are returned to their parent equal to the number of tabs lost. A directory returned to the parent directory cannot be re-entered. To separate sequential directories, put a line with one less tab starting with a tilde in between them. Remember that the first line in a new directory is the name of that directory.

The interpreter can be called with the argument "-e" to expand scripts to their full representation. There is no option to convert directories into scripts, since there are better archival options and programs should be stored in directory form.

Sample Programs
The following samples are stored in script format. Using the interpreter to expand them before running will help with a better understanding of both the directory structure and scripting.

CAT Program
civ_tmp.csv civ_input.csv set_tmp_1.dat lpc_tmp ric_input.dat neq_tmp_input_--1.dat dif_tmp dic_input.dat div_tmp.csv div_input.csv

Hello, World!
dss_Hello, world-e.txt

Fibonacci Sequence
civ_val1.csv civ_val2.csv civ_val3.csv civ_bool.csv set_val2_1.dat set_bool_1.dat dlw_bool add_val3_val1_val2.dat set_val1_val2.dat set_val2_val3.dat dsi_val1.dat dsl_.txt les_bool_val2_1000000000.dat div_val1.csv div_val2.csv div_val3.csv div_bool.csv

Greeter
csv_name.csv dss_What is your name-u .txt rds_name.txt dss_Hello .txt dss_name.txt dss_-e.txt dsv_name.csv

Deadfish Interpreter
civ_value.csv civ_char.csv civ_boolean.csv civ_temp.csv cfv_fv.csv cfv_fr.csv dlw_boolean dss_-g-g .txt ric_char.dat neq_boolean_char_-1.dat dif_boolean equ_temp_char_100.dat dif_temp sub_value_value_1.dat equ_temp_char_105.dat dif_temp add_value_value_1.dat equ_temp_char_111.dat dif_temp dsi_value.dat dsl_.txt equ_temp_char_115.dat dif_temp itf_fv_value.exe pwr_fr_fv_2.bin fti_value_fr.exe equ_temp_char_10.dat lpn_temp ric_char.dat equ_temp_char_10.dat nif_temp equ_temp_char_-1.dat equ_temp_value_256.dat dif_temp set_value_0.dat les_temp_value_0.dat dif_temp set_value_0.dat div_value.csv div_char.csv div_boolean.csv div_temp.csv dfv_fv.csv dfv_fr.csv

Truth Machine
civ_value.csv civ_tmp.csv ric_value.dat equ_tmp_value_49.dat lpc_tmp dic_value.dat dic_48.dat

External resources
Interpreter and sample programs, requires either the .NET framework on Windows or Mono on Linux to run (Mono untested)