Pig
Jump to navigation
Jump to search
Pig is a programming language that has only one keyword: the word PIG.
Usage
Pig can be used to create text files. To code in Pig, write the title of your text file, then write PIG
, then write the contents of the text file.
Various Programs in Pig
Hello, World!
The following code creates a text file named "Hello, World!" which contents are "Hello, World!".
Hello, World!PIGHello, World!
Cat program
Pig cannot create the Cat program because it is output only.
Quine
Pig cannot create a Quine either.
The Pig series
The Pig series is a a series of programming languages that are all based on Pig.
The languages are Pig, SickPig, DeadPig, QuinePig and DeafPig.
Interpreter
Simple interpreter written in C#.
using System; using System.IO; class Pig { static int Main(string[] args) { try { if (args.Length < 1) { Console.WriteLine("USAGE: {0} <file>", Environment.GetCommandLineArgs()[0]); return 1; } string[] input = File.ReadAllText(args[0]).Split(new string[] { "PIG" }, 2, StringSplitOptions.None); if (input.Length < 2) { Console.WriteLine("File must contain the string 'PIG'."); return 2; } File.WriteAllText(input[0], input[1]); return 0; } catch (IOException ex) { Console.WriteLine(ex.Message); return 3; } } }
Simple Interpreter written in Python:
def run_pig(code): assert type(code) is str, 'ERROR: Code must be a string.' assert 'PIG' in code, 'ERROR: Code must contain "PIG".' file_name, file_text = code.split('PIG', 1) file = open(f'{file_name}.txt', 'w') file.write(file_text) file.close()