Parser generator
Project description
syntactes
Python parser generator
Quick start
from syntactes import Grammar, Rule, SLRGenerator, Token
EOF = Token.eof()
S = Token("S", is_terminal=False)
E = Token("E", False)
T = Token("T", False)
x = Token("x", True)
PLUS = Token("+", True)
tokens = {EOF, S, E, T, x, PLUS}
# 0. S -> E $
# 1. E -> T + E
# 2. E -> T
# 3. T -> x
rule_1 = Rule(0, S, E, EOF)
rule_2 = Rule(1, E, T, PLUS, E)
rule_3 = Rule(2, E, T)
rule_4 = Rule(4, T, x)
rules = (rule_1, rule_2, rule_3, rule_4)
grammar = Grammar(rule_1, rules, tokens)
generator = SLRGenerator(grammar)
parsing_table = generator.generate()
print(parsing_table.pretty_str())
Running the above example produces this output:
GRAMMAR RULES
-------------
0. S -> E $
1. E -> T + E
2. E -> T
3. T -> x
-------------
LR0 PARSING TABLE
-------------------------------------------------
| | $ | + | E | S | T | x |
-------------------------------------------------
| 1 | -- | -- | s3 | -- | s4 | s2 |
-------------------------------------------------
| 2 | r4 | r4 | -- | -- | -- | -- |
-------------------------------------------------
| 3 | a | -- | -- | -- | -- | -- |
------------------------------------------------
| 4 | r2 | s5 | -- | -- | -- | -- |
-------------------------------------------------
| 5 | -- | -- | s6 | -- | s4 | s2 |
-------------------------------------------------
| 6 | r1 | -- | -- | -- | -- | -- |
-------------------------------------------------
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
syntactes-0.1.2.tar.gz
(7.9 kB
view details)
Built Distribution
File details
Details for the file syntactes-0.1.2.tar.gz
.
File metadata
- Download URL: syntactes-0.1.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3fb055c0288a4d53b1dae3f5950edd95921e7c8e397b13a4c1f65d35e08bc82 |
|
MD5 | 94b9f4ba4ad8c9460abb182ec39efd2d |
|
BLAKE2b-256 | 6386462a2af6b0ae3c77b831be026d238baa90634d884e2054c04a31058ba5cb |
File details
Details for the file syntactes-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: syntactes-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a138b857aa93ed35735d4dfac875423bad7a6e2a04aacde272e788670626c566 |
|
MD5 | d854f39044eefb65a9beb0450e3a5c84 |
|
BLAKE2b-256 | 6d60349a4f517bd1b187c5c701c5be2234178927d7333e31511e774c85fa3110 |