Thread: Regex to parse function names?

  1. #1
    Registered User
    Join Date
    Nov 2008

    Regex to parse function names?

    This isn't exactly C++ related, with the exception of I'm dealing with C++ function names. I'm trying to write a regex that can parse the function names of C++ functions but I only want standalone function names. So the text is also pretty much identicle to a var name except it will end with a (. I can come kind of close and this is what I have so far

    To give a better idea of what I'm trying to match, this should match


    This shouldn't match


    Are there any regex gurus out there that can help me out with this?

  2. #2
    The larch
    Join Date
    May 2006
    I don't think it is that simple.

    struct A
    A a(10); //this is not a function
    A b(int(0)); //this is not a function
    int n;
    A c(int(n)); //this is a function
    A d((int(n))); //this is not a function
    A e(n); //this is not a function
    The language is context sensitive. In order to tell whether a pattern is or isn't a function name, you actually have to know if the tokens involved in the expressions are typenames or not.

    Apart from not being able to tell whether it is a function declaration (call) or an instance declaration, you'll probably also not be able to spot cases where operator() is involved and probably some other cases.
    Last edited by anon; 03-30-2011 at 02:03 PM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Nov 2008
    Well that quickly pointed out some outliers I missed. I now have

    While what I have listed as being matches may not guarentee it to be a function, it is a high probability that it is. I'll be pruning the results manually after. I'm just trying to get a good candidate list.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM