Mindless code generator. "Not Recommended For Production Use."
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
emitters
samples
vendor/parsedown
.gitignore
LICENSE
README.md
emit.php

README.md

nrfpu

Basically just a quirky regex runner :)

The eventual goal

To be able to take in an "english" looking file and emit code in various languages, based on successive, englishly looking definitions. Not only should the resulting tool be able to take a single "english" program and emit code in various languages, but it will support "dialects" and stacks.

And if not that, at least it will have been fun to tinker with ...

For now ...

For now, it supports only PHP, and the "definitions" are stated in PHP. For example, this definition of to returns an array of integers between the numbers to its left and right (inclusively):

to
    if (!is_numeric($left) || !is_numeric($right)) return;
    $values = array();
    for ($i = $left; $i <= $right; $i++) {
        $values[] = $i;
    }
    return $values;

Eventually, definitions will be recursive and we'll have a list of different emitters, which provide a small set of standard translations for simple things like:

  • conditionals
  • loops
  • standard I/O
  • mathematical operations
  • logical operations

etc..

The basic format is:

Words go here.

Word
	Definition goes here

So, for example:

show Hello World

show
	print $right;

show turns into a sort of function. And Hello World! gets dumped into its "right" variable.

Run the sample:

php emit.php php samples/program.lit | php

It should print:

Hello World!
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99

You mentioned stacks. What's that?

It's a set of languages that work together to form a complete program. You may, for example, create a small HTML/PHP/JS stack. And a single source file would be used to emit the HTML, PHP, JavaScript and "framework" code necessary to deploy the entire application (or module).

You might choose to write a program looks like this:

when I click The Button show Hello world.

Definitions for when I click and show would go in your stack definition. And emit.php would explode your code out, generating all HTML, PHP, and JS files you need to deploy.