Search code examples
javajavascriptpythonprogramming-languagesnlp

Detect Programming Language from code snippet


Possible Duplicate:
Detecting programming language from a snippet

Is there a way to identify the following for a text snippet?

  1. Whether it is a piece of code
  2. The programming language in which it is written

Solution

  • Depends on how long is the code snippet, for extremely short code sample it may not be possible at all, and still not easy for long code snippets.

    But anything that is developed for this purpose cannot ensure 100% accuracy of detecting the programming language for any length of code snippet (except if everything in the language is in the code snippet).

    A lot of the programming languages is similar. One very accurate (not 100% though) is to look for the header files or libraries etc that are included in the code, and how they are added (using, #include etc), it can be a huge and very accurate hint about the programming language.