New to Clang

Dear all;

I am a PhD student in EE at The university of Waterloo. I am planning
to use the Clang front end for my work.

I will be extending the C language to support my needs for the
research i.e. I will be creating some new keywords.

I am an electrical engineer not a compiler person. However, I am
reading on compiler. My question is how to start in the Clang? I see
LEX directory . My understating is to walk through this first in order
to create new tokens. But which file to touch first?

Any guidance regarding how to start this?

Thanking in advance,

Dear all;

I am a PhD student in EE at The university of Waterloo. I am planning
to use the Clang front end for my work.

Welcome!

I will be extending the C language to support my needs for the
research i.e. I will be creating some new keywords.

I am an electrical engineer not a compiler person. However, I am
reading on compiler. My question is how to start in the Clang? I see
LEX directory . My understating is to walk through this first in order
to create new tokens. But which file to touch first?

Any guidance regarding how to start this?

You can start by adding your new keyword in include/clang/Basic/TokenKinds.def Then, go into the parser (lib/Parser) and add code to parse that keyword. After that you'll probably need to add an action (include/Sema/Action.h) and its implementation for semantic analysis (include/Sema/Sema.h, lib/Sema/wherever). In general, pick something in the C family of languages that's close to what you want to do, then follow it through the compiler.

  - Doug

The only part of Lex you'll ever need to touch (unless you're extending the preprocessor) is TokenKinds.td, which actually lives in Basic. It defines the special tokens and keywords that exist in Clang. If you need a new keyword, you simply add it there.
Everything else should probably go into Parser, Sema and CodeGen.

Sebastian