A Compiler for the Popr Language
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
afl
cgen
css
linenoise @ c894b9e
lldb
org
patches
scripts
startle
test_output
tex
.gdbinit
.gitignore
.gitmodules
.lldbinit
.travis.yml
.ycm_extra_conf.py
LICENSE
Makefile
README.md
builders.h
byte_compile.c
cells.c
cgen.c
eval.c
eval.html
lex.c
lib.ppr
list.c
macros.h
module.c
package.json
parse.c
popr
popr-mode.el
poprc
poprc-mode.el
primitive.c
print.c
rt.c
rt_types.h
special.c
staging.ppr
tags.c
tests.ppr
tests.txt
tok.c
trace.c
user_func.c
yarn.lock

README.md

Popr Compiler Build Status

This project is to implement a compiler for the Popr (previously Peg) language. The language has changed somewhat to support efficient compilation and type checking.

Please see this presentation for more information.

The following expressions can be evaluated online using the PoprC web version.

Here is a quick description of the language as it is currently. Lines beginning with ":" are user input, the following lines are output from the interpreter.

: 1 2 +
  3

Popr is a post-fix concatenative language. + is an operator that takes two integers and returns one. There are several similar operators, with the same meaning as in C: -, *, <, <=, ==, >, >=. Booleans are represented as the symbols True and False.

: 1 2 | 3 +
  4
  5
: 2 5 | dup 3 >= !
  5

| creates alternative execution paths. ! takes two values. If the second argument is False, the it fails, otherwise the first value is returned. These primitives provide a more general mechanism than if/else, similar to speculative execution, or Prolog inference.

: [ 1 2 + 3 4 + ] popr
  [ 1 2 + ] 7
: 1 [ 2 + ] pushl
  [ 1 2 + ]
: 1 [ 2 + ] pushl popr
  [] 3

[ ... ] denotes a quote, which can be used for constructing functions or for aggregating values. popr pops the rightmost element and forces evaluation. pushl takes its first argument and pushes it onto the left of the fragment. The two primitives can be combined to evaluate a fragment. Notice that Popr is lazy, and only reduces functions in quotes when required.

: 1 2 | dup
  1 1
  2 2
: 1 2 swap
  2 1
: 1 2 drop
  1

Some other primitives. dup duplicates a value; notice how it respects the constraints introduced by alternatives. swap swaps two values. drop drops a value.

 : 1 2 [3+] dip11
   4 2
 : 1 2 [3] dip12
   1 3 2
 : 1 3 2 [+] dip21
   4 2
 : [1] 2 pushr
   [ 1 2 ]

Some other functions.

License

The license for the Popr Compiler is GPL3. See LICENSE for more information.