G
G
GOleg2015-06-11 12:20:18
Programming
GOleg, 2015-06-11 12:20:18

Autodetect programming language by code?

Good afternoon! Are there ready-made solutions (open source) for automatically detecting a programming language from a given source code? How difficult is it to create something like this yourself?
Is it enough to detect a few keywords, or do you need to parse the code more deeply?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jackroll, 2015-06-11
@GOleg

Warm lamp https://github.com/github/linguist

D
Denis Ineshin, 2015-06-11
@IonDen

IMHO you need to parse deeply, many PLs have very similar syntax.

B
bobrovskyserg, 2015-06-11
@bobrovskyserg

A few keywords are not enough - Lisp needs brackets, Python needs indents, and so on.
If the list of languages ​​is given, and the code is valid, by feeding it in turn to compilers/interpreters, you can find out which languages ​​consider this code as their own. If the code is invalid, everything is bad, for example, by gluing a piece of python and a piece of lisp, I will get a code, which should I take it to? That's right, in the trash.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question