tags:

views:

522

answers:

6

I'm looking for a parser for C. Here is what I need:

  1. Written in C (not C++).
  2. Handwritten (not generated).
  3. BSD or similarly permissive license.
  4. Capable of nontrivially parsing itself (can be a subset of C).

It can be part of a project as long as it's decoupled so that I can pull out the parser.

Is there an existing parser that fulfills these requirements?

A: 

GCC has one in gcc/c-parser.c.

Grandpa
That doesn't really fill the licensing requirements. Just saying.
Whisty
A: 

How about Sparse?

blwy10
A: 

Check elsa, it uses the Generalized LR algorithm.

Its main use is for C++, but it also parses C code.

Check on its page, on the section called "How much C can Elsa parse?" which says it can parse most C programs, including the Linux kernel.

It's released under a BSD license.

Elsa is not entirely hand-written; it uses Elkhound as a parser generator. The main grammar file is a .gr file that is passed through Elkhound to generate a parser
blwy10
A: 

You could try TCC. It's licensed under the Lesser GPL.

themis
+3  A: 
Norman Ramsey
A: 

It seems that nwcc sufficiently agrees with your requirements.

lazyden