initial (hacky af)
This commit is contained in:
0
examples/__init__.py
Normal file
0
examples/__init__.py
Normal file
18
examples/bf.py
Normal file
18
examples/bf.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import gll
|
||||
|
||||
def loop(string):
|
||||
parser = gll.seq(gll.skip(gll.string("[")),
|
||||
gll.many(op),
|
||||
gll.skip(gll.string("]")),
|
||||
tag="loop")
|
||||
return parser(string)
|
||||
|
||||
op = (gll.string("+", tag="add") |
|
||||
gll.string("-", tag="sub") |
|
||||
gll.string(".", tag="out") |
|
||||
gll.string(",", tag="in") |
|
||||
gll.string(">", tag="fwd") |
|
||||
gll.string("<", tag="bck") |
|
||||
loop)
|
||||
|
||||
parser = gll.all(gll.many(op), tag="program")
|
9
examples/calc.py
Normal file
9
examples/calc.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import gll
|
||||
|
||||
ws = gll.skipmany(gll.whitespace(), tag="spaces")
|
||||
num = gll.many1(gll.digit(), tag="number")
|
||||
op = gll.string("+", tag="op") | gll.string("-", tag="op")
|
||||
|
||||
expr = gll.seq(num, ws, op, ws, num, tag="expr")
|
||||
|
||||
parser = gll.many(expr)
|
13
examples/golike.py
Normal file
13
examples/golike.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import gll
|
||||
|
||||
ws = gll.many(gll.whitespace)
|
||||
|
||||
function = function
|
||||
|
||||
package_name = gll.seq(gll.skip(gll.string("package")), gl.skip(ws),
|
||||
gll.regex(".*$"), tag="package_name")
|
||||
|
||||
package = gll.seq(package_name, gll.many(function, tag="package_body"),
|
||||
tag="package")
|
||||
|
||||
parser = gll.all(package)
|
Reference in New Issue
Block a user