[cfe-dev] Lenient lexing/parsing of code snippets

David Chisnall David.Chisnall at cl.cam.ac.uk
Sun Dec 7 01:55:08 PST 2014


On 7 Dec 2014, at 02:55, Will Hawkins <whh8b at virginia.edu> wrote:

> I'm trying to use cfe to lex/parse code snippets. The snippets will be
> complete functions but they will be taken mostly out of their original
> context. I'd like to generate an AST for the code

This problem doesn't sound possible.  When you have a code snippet taken out of any context, then you have no information about the types of any variable (or the definition of most of the types).  This makes constructing an AST impossible (you don't say what language you're using, but if it's C++ then you don't even know from a snippet whether a+b is an arithmetic operation or a method invocation, even if it's C, then you don't know what the type promotion should be).

I think, to answer the question that you want to be asking, we need to know what you want to do with the AST.

David





More information about the cfe-dev mailing list