Skip to main content

C Parser written 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 3.6-3.9

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.

cparser-0.5.3-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file cparser-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: cparser-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for cparser-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 256bde9d18636d58750f4ca0f7c0f6d9e5fb1c68ed22fa04248eef1e6a0e9c60
MD5 ccb86e72c8a53e90cf2a6242a4c8fe3f
BLAKE2b-256 b77c9f057e1ecef8f6daeffd947807883b324701cf420d4e18039d940ab0d4e0

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