开发者

Detect Programming Language from code snippet [duplicate]

This question already has answers here: Closed 11 years ago.

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


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.


Not in general.

A large part of the problem is that many programming languages are similar - there are snippets of code that may be valid in mulitple languages.

It all depends on the length of the snippet. If you have enough code, you can probably figure out which language it is written in, but it might require quite a lot of code to correctly identify the language.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜