Skip to main content

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-pgen in PATH.

    If ~/.local/bin is already in PATH:

    git clone https://github.com/thautwarm/RBNF.hs
    cd RBNF.hs
    stack install .
    

Example: Multiplications

  1. write a multiply.rbnf file:
# '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;
  1. write a multiply.rlex file:
%require mul
%require unwrap
%ignore space
number [+-]?\d+
space \s+
  1. codegen
sh> rbnf-pygen multiply.rbnf multiply.rlex multiply.py --k 1 --traceback
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rbnf_rts-0.4-py3-none-any.whl (82.8 kB view details)

Uploaded Python 3

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

Hashes for rbnf_rts-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7be02ecd2998bfd2c55877efd270f42c185db80935dbb87c09a1fbd14152da5d
MD5 93342ffb5d6f2484e2ffe072e4ab012c
BLAKE2b-256 dac126aab984bce4fb8ce7859a3879bd2086129e7a6a6f9ec9199a129f19f724

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page