Identification of a C # or C ++ function runs in a string counting program

I have a program written in C # that, when specifying a C ++ or C # file, counts lines in a file, counts how many of them are in comments and in designer blocks of code. I want to add the ability to count the number of functions in a file and the number of lines in these functions. I cannot figure out how to determine if a line (or a series of lines) is the beginning of a function (or method).

At the very least, a function declaration is a return type, followed by an identifier and a list of arguments. Is there a way to determine in C # that a token is a valid return type? If not, is it easy to determine if a line of code is the beginning of a function? Basically, I need to be able to reliably distinguish something like.

bool isThere() 
{
...
}

of

bool isHere = isThere()

and from

isThere()

.

+3
5

. { }, , , . ///*... */ , , - , . #if, , , .

, . , , , . ( - , - " Fred" . " Fred {". , - , " " __DECLSPEC MYWEIRDMACRO Fred {'. : " " " ? , .

, , , . ?

:

  • . ( "__DLLEXPORT const unsigned myInt32typedef * &" ). , .
  • . ( "operator =" ..)
  • , "". .
  • , (, , , ..). (template, const ..), .

, , ; {}, /. . . , (enum, struct, class ..).

" " , . , . , "", ( ), , , .

+1

, , #. , . SO.

, , , , , ,

int
?
/* this 
is */
main /* legal */ (code c) { 
}
+2

, , , , /, . , Regex (untested), :

(private|public|internal|protected|virtual)?\s+(static)?\s+(int|bool|string|byte|char|double|long)\s+([A-Za-z][A-Za-z_0-9]*)\s*\(

( ) , .

, , , , .

+1

( , ), ANTLR. ,

0

#, ?

, , (, , ). , , "" .

.

-1

Source: https://habr.com/ru/post/1728977/


All Articles