Skip to main content

Parser generator

Project description

image image image Actions status

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.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

syntactes-0.1.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file syntactes-0.1.1.tar.gz.

File metadata

  • Download URL: syntactes-0.1.1.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

Hashes for syntactes-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f71034c3aa24664b5365216ca0923fdea75eb798576f4f70fe82a62749a48b44
MD5 9015ea02b4015967d8a123a88b6b8c98
BLAKE2b-256 983c55119691dec03a8f6702498829c901f5e1e9a3cb1c33a2831de04e2b728a

See more details on using hashes here.

File details

Details for the file syntactes-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: syntactes-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for syntactes-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f12f3b442c1cacf9446fe05453812d8c9194d99242503714d61da3242f23316e
MD5 08d799cee0afec17cd2969f828d2cd99
BLAKE2b-256 f6f31a0ad3ef13c52ffee138dc36f32fc587d2d4850e31d8a5615d5c05f7f663

See more details on using hashes here.

Supported by

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