Phile

From Esolang
Jump to navigation Jump to search

Phile is an esolang by User:PythonshellDebugwindow. Its name is a play-on-words of the word "phile" and the word "file", a major part of the language.

Syntax

Each line in Phile is one of the following:

OPEN fname;
WRITE fname value;
OVERWRITE fname value;
CLOSE fname;
value? line-number;

If a line begins with OPEN, then that fname will be set as a current file (it will be created if it doesn't already exist).

If it starts with CLOSE, then that fname will be removed as a current file; it is an error if you don't close an opened file by the end of the program.

If it starts with WRITE, then value will be written to fname without overwriting it.

And if it starts with OVERWRITE, then value will be written to fname, overwriting any previous contents.

value? line-number; is a conditional jump; if value is not one of "", "0", or 0, then the instruction pointer will jump to 0-based line-number.

Comments are denoted by /// and last until end-of-line.

The READ fname instruction can be used to read a line from fname (until newline or EOF). If a READ, WRITE, or CLOSE instruction attempts to operate on an fname that isn't a current file, or if the OPEN instruction tries to open a file that is a current file, then an error will be thrown.

Datatypes

Datatypes are string and signed integer, both arbitrary-length. Integer literals are base 10, and string literals are encased in "" double quotes. 0 + string is string-to-integer conversion, "" + number is integer-to-string conversion. String escape sequences are \" \n \\ \t, \n can be \r\n.

Math and Comparison (operators)

The syntax A OP B can be used for math and comparison. Where OP is one of +-*/, then it will perform that operation on A and B and return the result. Where OP is one of =![] (= → equality, ! → inequality, < → less than, > → greater than), then it will return A (OP) B. Otherwise, it is invalid syntax. Precedence is as follows, with first listed being highest: */+-=![], READ has the highest precedence, + is used for addition, concatenation, and conversion (see #Datatypes).

Special Files

stdin.stream, stdout.stream, and stderr.stream represent STDIN, STDOUT, and STDERR respectively. It is an error to write to STDIN or to read from STDOUT or STDERR.

Examples

Hello, World!

OPEN "stdout.stream";
WRITE "stdout.stream" "Hello, World!";
CLOSE "stdout.stream";

Cat

OPEN "stdin.stream";
OPEN "stdout.stream";
WRITE "stdout.stream" READ "stdin.stream";
1? 2;

Truth-machine

OPEN "stdin.stream";
OPEN "stdout.stream";
READ "stdin.stream" = 0? 5;
WRITE "stdout.stream" 1;
1? 3;
WRITE "stdout.stream" 0;
CLOSE "stdin.stream";
CLOSE "stdout.stream";

99 Bottles of Beer

The following program prints the lyrics of the song “99 Bottles of Beer”:

OPEN "stdout.stream";
OPEN "numberOfBottles.dat";
WRITE "numberOfBottles.dat" 99;
WRITE "stdout.stream" READ "numberOfBottles.dat" + " bottles of beer on the wall,\n";
WRITE "stdout.stream" READ "numberOfBottles.dat" + " bottles of beer.\n";
WRITE "stdout.stream" "Take one down, pass it around,\n";
OVERWRITE "numberOfBottles.dat" READ "numberOfBottles.dat" - 1;
WRITE "stdout.stream" READ "numberOfBottles.dat" + " bottles of beer on the wall.\n";
WRITE "stdout.stream" "\n";
READ "numberOfBottles.dat" > 2? 3;
READ "numberOfBottles.dat" = 2? 11;
WRITE "stdout.stream" READ "numberOfBottles.dat" + " bottles of beer on the wall,\n";
WRITE "stdout.stream" READ "numberOfBottles.dat" + " bottles of beer.\n";
WRITE "stdout.stream" "Take one down, pass it around,\n";
OVERWRITE "numberOfBottles.dat" READ "numberOfBottles.dat" - 1;
WRITE "stdout.stream" READ "numberOfBottles.dat" + " bottle of beer on the wall.\n";
WRITE "stdout.stream" "\n";
WRITE "stdout.stream" READ "numberOfBottles.dat" + " bottle of beer on the wall,\n";
WRITE "stdout.stream" READ "numberOfBottles.dat" + " bottle of beer.\n";
WRITE "stdout.stream" "Take one down, pass it around,\n";
WRITE "stdout.stream" "No bottles of beer on the wall.\n";
CLOSE "stdout.stream";
CLOSE "numberOfBottles.dat";

Turing-completeness

Using the OPEN command for initialization, the READ command for getting its value, and the OVERWRITE command for setting its value, a file can be used as a variable. Any amount of files can be open at one time and can be any length, and you can therefore have any amount of variables of unlimited size, and therefore unlimited memory. The x? y; should provide enough control flow.

Interpreter

  • Common Lisp implementation of the Phile programming language.