Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursive Descent Parser for C

Tags:

c

parsing

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?

like image 399
Imagist Avatar asked Nov 27 '09 14:11

Imagist


People also ask

What is recursive descent parser used for?

Parsing is the process to determine whether the start symbol can derive the program or not. If the Parsing is successful then the program is a valid program otherwise the program is invalid.

What is recursive descent parser example?

Recursive Descent Parser uses the technique of Top-Down Parsing without backtracking. It can be defined as a Parser that uses the various recursive procedure to process the input string with no backtracking. It can be simply performed using a Recursive language.

What is recursive descent parser in compiler design?

Recursive descent is a top-down parsing technique that constructs the parse tree from the top and the input is read from left to right. It uses procedures for every terminal and non-terminal entity. This parsing technique recursively parses the input to make a parse tree, which may or may not require back-tracking.


2 Answers

If you don't need C99, then lcc is a slam dunk:

  • It is documented in a very clear, well-written book.
  • Techniques used for recursive-descent parsing of operators with precedence are well documented in an article and technical report by Dave Hanson.
  • Clear, handwritten ANSI C code.

One potential downside is that the lcc parser does not build an abstract-syntax tree—it goes straight from parsing to intermediate code.

If you must have C99 then I think tinycc (tcc) is your best bet.

like image 74
Norman Ramsey Avatar answered Oct 05 '22 04:10

Norman Ramsey


How about Sparse?

like image 34
blwy10 Avatar answered Oct 05 '22 04:10

blwy10