Is there a website that can recognize and identify what programming language is being input (pasted)?

My pastebin dpaste does this - when you paste stuff in the “Content” box and wait three seconds, it makes a guess.

The REST API I use for this feature is not publicized or documented, but you can use it if it suits you.

Here’s a usage example. Enter the curl command given below, then paste your content, then hit Enter, then hit ctrl-D. You get a JSON response with ranked guesses.

  1. $ curl -s -F "content=<-" dpaste.com/api/v2/guess-syntax/  
  2.  
  3. # Python 3: Fibonacci series up to n 
  4. >>> def fib(n): 
  5. >>> a, b = 0, 1 
  6. >>> while a < n: 
  7. >>> print(a, end=' ') 
  8. >>> a, b = b, a+b 
  9. >>> print() 
  10. >>> fib(1000) 
  11.  
  12. ^d 
  13. ["Python console session", "pycon", [["pycon", 1.25], ["python", 0.17]]] 

Actualmente reconoce estos lenguajes/sintaxis:

Bash, BBcode, C, Clojure, C#, diff, HTML, HTML + Django template, HTML + PHP, Java, Javascript, JSON, nginx config, Objective-C, Python console, Python traceback, Python, Ruby, Tex, XML.

Todas las demás herramientas que he visto para esto han tratado de identificar programas completos, más que fragmentos cortos de código. Pero los fragmentos cortos son típicos en un pastebin, así que hice el mío. Es tosco pero funciona.

En algún momento voy a hacer de esto un servicio independiente impulsado por AWS Lambda o algo parecido, y mejorarlo con algo de magia de ML.