Giter VIP home page Giter VIP logo

dirt's Introduction

dirt

The "irt" in "dirt" stands for "iterated regular transduction". The "d" stands for "don't use this for serious programming".

Language Overview

dirt uses transduction expressions which are similar to regular expressions, except they are able to produce output.

Transduction expressions have the following regex syntax:

  • Any non-special character matches itself.

  • . matches any 1 character.

  • X* matches X 0 or more times.

  • X+ matches X 1 or more times.

  • X? matches X 0 or 1 times.

  • XY matches the concatenation of X and Y. Lower precedence than *, + and ?.

  • X|Y matches the union of X and Y. Lower precedence than concatenation.

  • ( and ) override precedence.

  • \ escapes the next character.

  • [...] matches one of the character between the []s.

  • [a-b] matches character in the range from a to b. Can have multiple ranges and additional non-range characters (e.g. [a-zA-Z0-9_])

  • [^...] matches any character not included between the []s

Any expression using only the above syntax, when run on a string which it matches, will output the same string.

To allow different output than the input string, the following syntax can be used:

  • 'c matches the empty string and outputs a single character c when matched. Special characters don't need to be escaped (e.g. '\ outputs a backslash).

  • "..." matches the empty string and outputs everything between the 2 " characters when matched. "s and \s inside need to be escaped.

  • `c matches a single character c and outputs nothing. Special characters don't need to be escaped.

  • {X} matches whatever X matches but outputs nothing.

In cases where the input can be matched multiple ways, dirt chooses whichever way produces the least output.

A dirt program is just a transduction expression. dirt reads its input from stdin, then repeatedly transduces it until it doesn't match, then outputs it to stdout.

Note: by "character" I mean "byte". Non-printable characters are perfectly valid in a dirt program.

Usage

Build with dotnet build (I think?).

Run with dirt [source-filename] < [input-filename] or dirt [source-filename] -i "[input]".

Use -v for verbose mode, where it prints every transduction.

Examples

Hello World

Here's a Hello World program

"Hello, World!"

brainfuck interpreter

Here's a brainfuck interpreter in 489 characters.

'@[^@]*"# @00000000 "(#[^#]*|"#")'#|[^R]*(('<R+`<|'>R+`>|'-R+`-|'+R+`+|'.R+`.|',R+`,|'['RR+`[|']`RR+`])|`R\]'@).*|.*((`<L+'<|`>L+'>|`-L+'-|`+L+'+|`.L+'.|`,L+',|`[`LL+'[|`]'LL+'])|'@\[`L)[^L]*|[^x]*(`x('0[^#]*#`0|'1[^#]*#`1)|(`x'0)+ .*##).*|.*`I",@"[^x]*|.*`o(0'o.*'0|1'o.*'1| .*)|.*`O".@"[^o]*|.*`@(-'@.*@([^ ]*`1'0|)(`0'1)* |\+'@.*@([^ ]*`0'1|)(`1'0)* |<'@.*#( @"00000000 "|.* '@[^ ]+ `@)|>'@.*`@[^ ]+ '@("00000000 "|[^#]+)#|\['@.*@([^ ]*1)|'L\]|\['R.*@0* |`,'I.*@({0|1}'x)* |`.'O.*@'o).*

dirt's People

Contributors

0xb0c5 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.