Hi Folks,
I am trying to fetch the output of Clang’s lexical analyzer. After some discovery, I came across Clang’s front-end option “-dump-raw-tokens” which dumps the output of the lexical analyzer. However, I get the data in the form of plain text which makes it difficult to parse the data. I wonder if there is any way to get the output of the lexical analyzer in the JSON format that would make it easier to parse the data. When I asked the same question to Chat-GPT, it said that the Clang plugin could be added to make it work. Please let me know if there is any existing plugin for this or any other way to fetch the output of the lexical analyzer in JSON format.
Any input would be highly appreciated! Thank you in advance!
Currently, with “clang -E -P -Xclang -dump-raw-tokens foo.c” command I get the below output:
Source code:
#define one 1
#pragma startup thisFunc
#include “header.h”
#if one > 2
#undef one
#else
#define two 2
#endif
int main(){
return 0;
}
int thisFunc(){
return 0;
}
Output of a Lexical Analyzer: