Skip to main content

Context-free grammars and parsing

Project description

cfgrammar : Context-free grammars, parsing and semantic

Table of Contents

Main features

  • Grammar properties
    • accessible and productive rules / variables
    • ε-productive rules / variables
    • reduced grammar
    • "First" and "Follow" sets
  • LL1 parsing
    • computes and displays LL(1) table
    • constructs parser
  • LR parsing
    • computes and displays LR(0) automaton
    • constructs LR(0), SLR(1), LALR(1) tables and parsers
  • Semantic
    • parsing with semantic actions
  • Abstract Syntax Tree
    • predefined semantic classes to produce AST
      • Graphviz / dot output
      • Latex + Tikz output

Example

Code :

from cfgrammar import Grammar

g = Grammar.from_string('S -> ( S ) S | a')

print(g)
print('productives variables : ', g.productive.vars)
print('Follow sets : ', g.follow)
print(g.tableLL1().to_markdown())

Output:

Grammar(
     terminals : ( ) a
     variables : S
     axiom : S
     rules : ['S → ( S ) S', 'S → a']
    )
productives variables :  {'S'}
Follow sets :  {'S': {')', '#'}}
|    | S           |
|:---|:------------|
| (  | S → ( S ) S |
| )  |             |
| a  | S → a       |
| #  |             |

API overall graph

schema

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

cfgrammar-0.1.1.1.tar.gz (37.7 kB view details)

Uploaded Source

Built Distribution

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

cfgrammar-0.1.1.1-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file cfgrammar-0.1.1.1.tar.gz.

File metadata

  • Download URL: cfgrammar-0.1.1.1.tar.gz
  • Upload date:
  • Size: 37.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for cfgrammar-0.1.1.1.tar.gz
Algorithm Hash digest
SHA256 52329c36d5eac38ffb0c55c87d8caa4e1f01233b570ed18f77d067432f95ed90
MD5 826206ac06ff2d46dc524384b116d7f8
BLAKE2b-256 ac7ca83849c494ca7229bbc295f6f5003f39634f309d4592315f2db422c26e7b

See more details on using hashes here.

File details

Details for the file cfgrammar-0.1.1.1-py3-none-any.whl.

File metadata

  • Download URL: cfgrammar-0.1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 41.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for cfgrammar-0.1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 046636a3c4278f3489143e333cd0a83043fae3da3909ac5c8e0148ec73d49bd4
MD5 2b2aa6666d0d9eef7f424655aa88bca5
BLAKE2b-256 3aa12cfee22017264a1febbb6c82b669700e1a38a57d7d9a758e412693bbf93c

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