A C11 parser written in TypeScript with GCC extensions support. Zero runtime dependencies.
Try the online playground.
Built for use with AST Explorer.
npm install c11-parserimport { parse } from 'c11-parser';
const ast = parse(`
int main(void) {
return 0;
}
`);
console.log(JSON.stringify(ast, null, 2));parse(source, {
gnuExtensions: true, // Enable GCC extensions (default: true)
loc: false, // Compute line/column locations on demand (default: false)
});import adapter from 'c11-parser/adapter';| Export | Description |
|---|---|
parse |
Parse C source into an AST |
AST |
All AST node type definitions |
Scanner |
Lexer class for tokenization |
Parser |
Parser class with token helpers |
TokenKind |
Token kind enumeration (180+ tokens) |
- Full C11 syntax support
- GCC
__attribute__extensions - Inline assembly (
asm/__asm__) - Byte-range tracking on every AST node (
start,end) - Optional line/column location tracking (
loc) when enabled - Dual package: ESM + CommonJS
pnpm build # Build with tsup
pnpm test # Run tests
pnpm lint # Lint with oxlint
pnpm fmt # Format with oxfmtMIT