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.
Built Distribution
Close
Hashes for cparser-0.1.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80567f699740b5244c80bd3649ef53850f4f3590ebc69a1f9c5f07fb06baf740 |
|
MD5 | 04cfe3480bd4385808a554264fc84df7 |
|
BLAKE2-256 | ce2d2907cc4a6645ebba73dd904a4295dff2649fceed375f8fe59eb6222f8d17 |