←back to thread

35 points bluetomcat | 1 comments | | HN request time: 0.373s | source

A small tool that parses C declarations and outputs a simple visual representation at each stage, as it encounters arrays, pointers or functions.

The program uses a table-driven lexer and a hand-written, shift-reduce parser. No external dependencies apart from the standard library.

1. xvilka ◴[] No.46192579[source]
We use the tree-sitter[1] for parsing C declarations in Rizin[2] (see the "td" command, for example). See our custom grammar[3] (modified mainstream tree-sitter-c). The custom grammar was sadly necessary, due to the inability of Tree-Sitter to have the alternate roots[4].

P.S. Please add a license for your code.

[1] https://tree-sitter.github.io/

[2] https://github.com/rizinorg/rizin/tree/dev/librz/type/parser

[3] https://github.com/rizinorg/rizin-grammar-c/

[4] https://github.com/tree-sitter/tree-sitter/issues/711