orangeduck/mpc
FreeA Parser Combinator library for C
About orangeduck/mpc
mpc is a lightweight and powerful Parser Combinator library for C, designed for building parsers for programming languages, data formats, and domain-specific languages (DSLs). It provides type-generic, predictive, recursive descent parsing with automatic error message generation. mpc is easy to integrate as a single ANSI C source file and header, and includes both a regular expression parser generator and a language/grammar parser generator for defining grammars directly. The library avoids reliance on garbage collection, setjmp/longjmp, and namespace pollution. It offers a grammar specification mode where users can define parsing rules as strings, enabling rapid parser development. It is used for tasks such as building new languages, parsing existing ones, and embedding DSLs.
Key Features
Pros & Cons
- Lightweight and easy to integrate (single ANSI C file)
- Type-generic, allowing use with arbitrary user data types
- Automatic generation of clear error messages
- Supports both combinator-based and grammar-string-based parsing
- No external dependencies or garbage collection required
- Predictive recursive descent parsing with good performance
- Well-documented with examples and quickstart guide
- Requires C programming knowledge and compilation
- Limited to C/C++ projects; not a standalone application
- Grammar syntax may have a learning curve for beginners