Answer the question
In order to leave comments, you need to log in
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
IMHO you need to parse deeply, many PLs have very similar syntax.
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 questionAsk a Question
731 491 924 answers to any question