Show HN: Cdecl-dump - represent C declarations visually
35 points| bluetomcat | 2 months ago |github.com
The program uses a table-driven lexer and a hand-written, shift-reduce parser. No external dependencies apart from the standard library.
35 points| bluetomcat | 2 months ago |github.com
The program uses a table-driven lexer and a hand-written, shift-reduce parser. No external dependencies apart from the standard library.
xvilka|2 months ago
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
coherentpony|2 months ago
bluetomcat|2 months ago
As per the screenshot, “arr” is an array of 4 elements. Consequently, “arr[0]” is an array of 8 elements. Then, “arr[0][0]” is a pointer. And so on, until we arrive at the specifier-qualifier list.
pcfwik|2 months ago
TL;DR: you declare a variable in C _in exactly the same way you would use it:_ if you know how to use a variable, then you know how to read and write a declaration for it.
https://eigenstate.org/notes/c-decl https://news.ycombinator.com/item?id=12775966
userbinator|2 months ago
In other words, the precedence of operators in a declaration have exactly the same precedence as in its use.
nitrix|2 months ago
It's the intended way to read/write declarations/expressions. As a consequence, asterisks ends up placed near the identifiers. The confused ones will think it's a stylistic choice and won't understand any of this.