hi,
i am making a web application in which user can paste some code...it will also have a drop down which will have list of all languages like java, c, c++
i want to auto detect which language the code is and auto select that language in the drop down.
are there any libraries in javascript etc which can help here ?
or any other way i can achieve this ?
You will have to study basic programs for typical keywords of all the languages you are displaying in a drop-down in your application.
few examples of the basic keywords...
C/C++ -> include
Java -> import
Php -> <?php
Cobol -> Identification Division
FoxPro -> Set command
awking00
I think you'll get closer to determining what language is being used by making the person entering the code to select the language first from the drop down menu. I also think that would be especially true if someone is entering code snippets and not an entire program that would contain various identifying keywords.
SStory
Of course it is easier if the person tells you. However the question was how to identify it programmatically. If you can get them to tell you then I'm not sure what this question is.
As awking00 suggests, you are going to have your work cut out, in what will essentially be a dubious parse exercise, open to imprecision. What would you do when faced with a Java programme that had native code included, and vice-versa?
Notepad++ - which imho is a neat editor - formats all types of code very nicely. Once you tell it from the menu, what language it is you are feeding it.
You will have to study basic programs for typical keywords of all the languages you are displaying in a drop-down in your application.
few examples of the basic keywords...
C/C++ -> include
Java -> import
Php -> <?php
Cobol -> Identification Division
FoxPro -> Set command