Skip to content
/ pfl Public

The reference interpreter for Procedural Footnote Language.

License

Notifications You must be signed in to change notification settings

vasilescur/pfl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Procedural Footnote Language

An interpreter for Procedural Footnote Language, written in Dart.

Please note that this project is still work-in-progress and some features may not work as expected.

Getting Started

To get started with Procedural Footnote Language, first read the language specification.

Installing

Download the latest stable release of the PFL interpreter from the Releases section. Place the pfl.exe in a folder added to your PATH.

Important: The PFL interpreter is currently only available for Windows, and is packaged using dartbin.

Usage

To run a PFL program, execute the following command:

pfl filename.pfl

How it Works

The interpeter uses a loose interpretation of an abstract syntax tree to evaluate the final result of the document.

There is a class heirarchy of elements, each with an overriden evaluate method that, by default, evaluates all its children, concatenates the results, and returns:

/// Represents one node in the abstract syntax tree.
class Element {
    List<Element> children = new List<Element>();

    String evaluate() {
        String result = '';

        for (var child in children) {
            result += child.evaluate();
        }

        return result;
    }
}

Therefore, since the root document is also one of these nodes, evaluation of the entire document is as simple as calling evaluate on the root document.

Sample PFL Programs

Simple "Hello, world!"

[1]
[PFL1.0]
[1] Hello, world!
[PFLEND]

Adding two numbers

[1][2][3]
[PFL1.0]
[1:0:2] [INPUT]
[2:0:2] [INPUT]
[3] [ADD:[1]:[2]]
[PFLEND]

Primality test

[1][2]
[PFL1.0]
[1:0:2] [INPUT]
[2] [PRIME:[1]]
[PFLEND]

99 Bottles of Beer

[1][2]
[PFL1.0]
[1:98] [SUB:100:[INDEX:1]] bottles of beer on the wall, [SUB:100:[INDEX:1]] bottles of beer.[RET]Take one down, pass it around, [IF:[GT:[SUB:99:[INDEX:1]]:1]:[SUB:99:[INDEX:1]] bottles:1 bottle] of beer on the wall.[RET][RET][1]
[2] 1 bottle of beer on the wall, 1 bottle of beer.[RET]Take one down and pass it around, no more bottles of beer on the wall.[RET][RET]No more bottles of beer on the wall, no more bottles of beer.[RET]Go to the store and buy some more, 99 bottles of beer on the wall.[RET]
[PFLEND]

The Twelve Days of Christmas

The Twelve Days of Christmas[1][2][5][6][7][8][9][10][11][12][13][14][15]
[PFL1.0]
[1:12] [RET][RET]On the [ORD:[INDEX:1]] day of Christmas my true love gave to me[RET]
[2] [IF:[IS:[INDEX:2]:1]:[4]:[3]]
[3] and [4]
[4] a partridge in a pear tree[RET][1]
[5] Two turtle doves[RET][2]
[6] Three french hens[RET][5]
[7] Four calling birds[RET][6]
[8] FIVE GOLDEN RINGS[BEEP][RET][7]
[9] Six geese a laying[RET][8]
[10] Seven swans a swimming[RET][9]
[11] Eight maids a milking[RET][10]
[12] Nine ladies dancing[RET][11]
[13] Ten lords a leaping[RET][12]
[14] Eleven pipers piping[RET][13]
[15] Twelve drummers drumming[RET][14]
[PFLEND]

A few more examples can be found in the examples directory.

Development

Prerequisites

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments