Source: https://yellorn.com/programming/regex-building-a-smart-ide-programming-language-detection
We are trying to hack together a smart programming IDE. Help us build a feature that auto-detects the programming language, given the source code. There are only three languages which we are interested in “auto-detecting”: Java, C, and Python.
We will provide you with links to a few short or medium size programs for Java, C and Python. In case you aren’t familiar with some of these languages, these samples will help you make observations about the lexical structure and syntax of these programming languages. These sample programs are only for your manual inspection. You cannot read or access these sample programs from the code you submit.
After this, you will be provided with tests, where you are provided the source code for programs - or partial code snippets, but you do not know which language they are in. For each test, try to detect which language the source code is in.
You might benefit from using regular expressions in trying to detect the lexical structure and syntax of the programs provided.
Sample Programs to Understand the Lexical Structure of different Programming Languages
Sample Programs and Code Snippets in C
Sample Programs and Code Snippets in Java
Sample Programs and Code Snippets in Python
INPUT FORMAT
Source code of a program, or a code snippet, which might be in C, Java or Python.
OUTPUT FORMAT
Just one line containing the name of the Programming language which you have detected: This might be either C or Java or Python.
SAMPLE INPUT
import java.io.*;
public class SquareNum {
public static void main(String args[]) throws IOException
{
System.out.println("This is a small Java Program!");
}
}
SAMPLE OUTPUT
Java
Testcase
Input
# let us create a test string
testString1 = "Hello World!"
print "Original String: "+ testString1
# Print this string in lower case
# Converting a string to lower case
print "Converting to LowerCase"
print testString1.lower()
# Converting a string to upper case
print "Converting to Upper Case"
print testString1.upper()
# Capitalizing a string
Output
Python
Solution
import re
import sys
java = r"import .+;"
c = r"#include<.+>"
# python = r"class .+:"
python = r"# .+"
text = sys.stdin.read()
if re.search(java, text):
print("Java")
elif re.search(c, text):
print("C")
elif re.search(python, text):
print("Python")
If you’re interested in slot machine wagers and winnings in Connecticut, you'll find information for revenues (AKA “win”) from every on line casino's video slot machines on theGaming Revenue and Statistics page. When these wins turn out to be etched in your brain, your Dopamine reward system is more likely to to|prone to} be activated everytime you consider slot machines. This helps 바카라사이트 to maintain even essentially the most casual of gamblers interested in slots for a long time|for a really long time}, potentially even years after spinning the reels. Similarly, slot machines provoke cognitive dissonance amongst gamers. Every licensed slot machine in a land-based on line casino or online has a Return to Player share that gamers can easily entry. Mega Boost Wheelcharge™ offers the traditional wheel recreation a super charged boost.
ReplyDelete