←back to thread

35 points bluetomcat | 1 comments | | HN request time: 0s | 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.

Show context
coherentpony ◴[] No.46187406[source]
I don’t understand what the visualisation screenshot in the README is trying to communicate to me.
replies(1): >>46187666 #
bluetomcat ◴[] No.46187666[source]
It starts from the identifier. At every stage, it outputs a sub-expression which is the “mirrored use” and corresponds to the boxed representation below it. When it reaches the top of the expression, it prints the final type of the expression which is the lone specifier-qualifier list.

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.

replies(2): >>46188920 #>>46213011 #
1. ◴[] No.46188920[source]