A lightweight and powerful parser combinator library for C, enabling easy parsing of languages and data formats.
mpc is a parser combinator library for C that allows developers to build parsers by combining smaller parsers using intuitive operators. It simplifies parsing tasks such as building programming languages, data formats, or domain-specific languages by enabling grammar specification directly or through combinators.
C developers building parsers for new or existing programming languages, data formats, or embedded domain-specific languages.
Developers choose mpc for its simplicity, single-file integration, type-generic design, and powerful features like automatic error generation and regex support, all without external dependencies.
A Parser Combinator library for C
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Distributed as a single ANSI C source file, mpc can be integrated into any C project with minimal setup, avoiding complex build dependencies.
Supports generic types through function pointers, allowing parsers to output custom data structures like ASTs or computed values, as shown in the maths language case study.
Generates clear, contextual error messages automatically, such as expected tokens and line numbers, which aids in debugging without extra user code.
Includes mpca_lang for specifying grammars in a concise domain-specific language, enabling rapid parser development from string-based rules.
Explicitly does not support Unicode, restricting its use to ASCII text parsing, which is a significant drawback for modern international applications.
Requires users to provide destructor and fold functions for custom types, increasing complexity and risk of memory leaks if not handled correctly.
Cannot parse left-recursive grammars, forcing users to rewrite rules to avoid infinite loops, as admitted in the limitations section.