Skip to main content

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

Release files for cparser 0.5.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for cparser 0.5.4
File Interpreter ABI Platform
cparser-0.5.4-py3-none-any.whl Python 3 none any Details

Release files / cparser-0.5.4-py3-none-any.whl

Download URL cparser-0.5.4-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de2b984a3230c5530608e12b596eb32f072dd13e748b70313355bc1b3d9f5a82
BLAKE2b-256 checksum
How to use checksums
037e0229d8940a21effab4ac78f4e549f25c6a7644fc9f8cb79d042e1c00513d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.5.4 This release

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page