No project description provided
Project description
rbnf-rts
Runtime support for generated parsers of RBNF.hs
More Examples
Check the test directory:
- test
- multiply : parser/lexer implementation for multiplications
- arith : parser/lexer implementation for arithmetics
- relax : parser/lexer implementation for a full-featured programming language
- llvmir: parser/lexer implementation for LLVM IR, nearly full-featured
In each sub-directory of test, you can run tests via directly invoking the test.sh., like cd test/llvmir && bash test.sh
Native Dependencies
-
The Haskell Stack Toolchain
-
The executable
rbnf-pgenin PATH.If
~/.local/binis already in PATH:git clone https://github.com/thautwarm/RBNF.hs cd RBNF.hs stack install .
Example: Multiplications
- write a
multiply.rbnffile:
# 'mul' is a python global which should be marked as 'required' in .rlex
Mul : !lhs=Mul "*" !rhs=Atom -> mul(lhs, rhs);
Mul : !a=Atom -> a;
Atom : "(" !a=Mul ")" -> a;
# 'unwrap' should be marked as 'required', just as 'mul'
Atom : !a=<number> -> unwrap(a);
START ::= <BOF> !a=Mul <EOF> -> a;
- write a
multiply.rlexfile:
%require mul
%require unwrap
%ignore space
number [+-]?\d+
space \s+
- codegen
sh> rbnf-pygen multiply.rbnf multiply.rlex multiply.py --k 1 --traceback
- run statically-generated parsers and lexers and enjoy its efficiency
from rbnf_rts.rts import Tokens, State
from multiply import run_lexer, mk_parser
import operator
def unwrap(x: Token):
return int(x.value)
scope = dict(mul=operator.mul, unwrap=unwrap)
parse = mk_parser(**scope)
tokens = list(run_lexer("<current file>", "-1 * 2 * (3 * 4)"))
got = parse(State(), Tokens(tokens))
print(got)
Got (True, -24), where True indicates the parsing succeeded.
If False, a list of errors will be given in the second element of
the return tuple.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rbnf_rts-0.4-py3-none-any.whl.
File metadata
- Download URL: rbnf_rts-0.4-py3-none-any.whl
- Upload date:
- Size: 82.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7be02ecd2998bfd2c55877efd270f42c185db80935dbb87c09a1fbd14152da5d
|
|
| MD5 |
93342ffb5d6f2484e2ffe072e4ab012c
|
|
| BLAKE2b-256 |
dac126aab984bce4fb8ce7859a3879bd2086129e7a6a6f9ec9199a129f19f724
|