[cfe-users] Help needed: ANTLR-like API on top of clang AST

Marcin WyszyƄski via cfe-users cfe-users at lists.llvm.org
Sun Feb 21 07:14:58 PST 2016

Hi there,

total clang/llvm n00b here. I'm building a multilingual static analysis
tool which has parsers for individual languages export an appropriately
tagged language-agnostic AST for a single analyser binary to process. So
far I've been using native parsers for Ruby and Go and ANTLR
<http://www.antlr.org/>-based one for Swift.

ANTLR in particular won my heart because of it's Listener API
3 generic methods are provided:

void enterEveryRule(ParserRuleContext ctx)
void exitEveryRule(ParserRuleContext ctx)
void visitTerminal(TerminalNode node)

You can also subscribe to 'enter' and 'exit' events for particular rules
that you find particularly interesting. So for a given rule you'd have four
callbacks triggered - enterEveryRule, enterParticularRule,
exitParticularRule, exitEveryRule - in this particular order. There is also
concept of TerminalNodes which are things like literals etc.

Since this sort an API what feels most natural for the task at hand I would
kindly like to solicit your advice on how to go about replicating it in

Thanks in advance!

Marcin Wyszynski

*-- Everyone you meet is fighting a battle you know nothing about. Be kind.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20160221/e64a1141/attachment.html>

More information about the cfe-users mailing list