百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cppparser

> 编程语言
开源

一个用于解析 C/C++ 源代码的库,以生成 AST

378 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个用于解析 C/C++ 源代码的库,以生成 AST

CppParser

An easy, fast, and robust library to parse C/C++ source code.

Features

  • No preprocessing; preprocessor constructs are part of the AST.
  • Preserves most comments.
  • Implemented from scratch using backtracking Yacc (BtYacc), so no dependency on libclang.
  • Parses into a structured AST where file elements form a tree.
  • Minimal dependencies: Flex on Unix-like platforms (Linux, macOS, etc.). On Windows, Flex for Windows is bundled for out-of-the-box usage.
  • Supports parsing multi-file programs.

Motivation

CppParser can be used to build tools that need parsing of C/C++ files. It is also used to develop cib, which implements ABI-stable SDK architecture for C++ libraries.

Example

To begin with we will see an example of parsing a hello-world program and see the AST that CppParser creates:

…

This example is real and is part of the actual unit tests for CppParser.

For AST traversal, see CppWriter, which uses the generated AST to create files.

Building CppParser

Get the source

bash
git clone https://github.com/satya-das/CppParser.git

Configure and build

bash
cd cppparser
mkdir builds
cd builds
cmake ..
make

Alternatively, if you prefer Ninja instead of make:

bash
cd cppparser
mkdir builds
cd builds
cmake -G Ninja ..
ninja

For contributors who need to run tests

Make sure you also clone the dependencies. Run the following command in the parent directory of the root of cppparser.

bash
git clone https://github.com/satya-das/common.git

After this command the common and cppparser folders should be side by side.

Configure and run tests

bash
cd cppparser
mkdir builds
cd builds
cmake -G Ninja .. -DCPPPARSER_BUILD_TESTS=ON
ninja && ninja test

Modify the command by removing -G Ninja if you prefer make.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++astback-tracking-parsingc-plus-plus-parserc-plus-plus-parsing

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言