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):
        return node

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

visitor = IDVisitor()

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


  • Stable version:
$ pip install cparser
  • Development version:
$ git clone
$ pip install -e cparser



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.

Built Distribution

cparser-0.1.4-py2.py3-none-any.whl (15.4 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page