Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get Lexer output from gcc or clang?

Tags:

c++

c

gcc

clang

Is it possible to get clang or gcc to display the result of the lexing phase?

like image 311
Benno Avatar asked Dec 31 '14 01:12

Benno


People also ask

Is GCC better than Clang?

Clang reduces the single-thread compilation time by 5% to 10% compared with GCC. Therefore, Clang offers more advantages for the construction of large projects.

Is lexer part of compiler?

The lexer and parser together are often referred to as the compiler's front end. The rest of the compiler is called the back end.

Is GCC the same as Clang?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

Why LLVM is better than GCC?

The difference is that GCC supports a number of programming languages while LLVM isn't a compiler for any given language. LLVM is a framework to generate object code from any kind of source code. While LLVM and GCC both support a wide variety languages and libraries, they are licensed and developed differently.


1 Answers

Although the parser does poll the lexer without there being a proper "lexing phase" this does not mean that you cannot dump the tokens as they are lexed. This is done with the command :

clang -fsyntax-only -Xclang -dump-tokens code.c
like image 123
OlivierLi Avatar answered Nov 15 '22 22:11

OlivierLi