Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/typhoon-hil/cparser
C parser writen in Python
https://github.com/typhoon-hil/cparser
c parsing python
Last synced: 5 days ago
JSON representation
C parser writen in Python
- Host: GitHub
- URL: https://github.com/typhoon-hil/cparser
- Owner: typhoon-hil
- License: mit
- Created: 2018-10-02T09:12:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-12-27T09:05:14.000Z (about 1 month ago)
- Last Synced: 2025-01-28T03:34:04.002Z (13 days ago)
- Topics: c, parsing, python
- Language: Python
- Homepage:
- Size: 460 KB
- Stars: 12
- Watchers: 6
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
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... code:: python
from cparser import CParser
from cparser.visitor import ASTVisitorcode = """
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 nodeparser = CParser()
ast = parser.parse(code)visitor = IDVisitor()
visitor.visit(ast)# Output should look like this:
# element
# weight
# Atom
# Atom
# heliumInstallation
------------- Stable version:
.. code:: shell
$ pip install cparser
- Development version:
.. code:: shell
$ git clone https://github.com/typhoon-hil/cparser.git
$ pip install -e cparserLicence
-------MIT
Python versions
---------------Tested with 3.6-3.9