Skip to main content

C Parser writen in pure Python

Project description

A C parser based on parglare - a pure Python scannerless LR/GLR parser.

Quick intro

cparser is a parser for C language. This example shows how to collect all IDs from a simple C code.

from cparser import CParser
from cparser.visitor import ASTVisitor

code = """
typedef struct {
    int element;
    int weight;
} Atom;

Atom helium;
"""

class IDVisitor(ASTVisitor):
    """Visitor that collects all identifiers in the code."""

    def visit_id(self, node):
        print(node.value)
        return node

parser = CParser()
ast = parser.parse(code)

visitor = IDVisitor()
visitor.visit(ast)

# Output should look like this:
# element
# weight
# Atom
# Atom
# helium

Installation

  • Stable version:

$ pip install cparser
  • Development version:

$ git clone https://github.com/typhoon-hil/cparser.git
$ pip install -e cparser

Licence

MIT

Python versions

Tested with 2.7, 3.4-3.6

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

cparser-0.1.2-py2.py3-none-any.whl (15.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cparser-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: cparser-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for cparser-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e82e185c5d05426fae919b76d01f6602fbb532dbf3a9e19ca4a4bdcb3e35c46c
MD5 a6af999efcdde17af2848d37d6dafa78
BLAKE2b-256 89b765cf3e5a324ea6683f313e03105448463f344809ab16bee2e9f17d1976e3

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