in Education by
Like lots of you guys on SO, I often write in several languages. And when it comes to planning stuff, (or even answering some SO questions), I actually think and write in some unspecified hybrid language. Although I used to be taught to do this using flow diagrams or UML-like diagrams, in retrospect, I find "my" pseudocode language has components of C, Python, Java, bash, Matlab, Perl, Basic. I seem to unconsciously select the idiom best suited to expressing the concept/algorithm. Common idioms might include Java-like braces for scope, pythonic list comprehensions or indentation, C++like inheritance, C#-style lambdas, Matlab-like slices, and matrix operations. I noticed that it's actually quite easy for people to recognize exactly what I'm trying to do, and quite easy for people to intelligently translate into other languages. Of course, that step involves considering the corner cases and the moments where each language behaves idiosyncratically. But in reality, most of these languages share a subset of keywords and library functions which generally behave identically - maths functions, type names, while/for/if, etc. Clearly, I'd have to exclude many 'odd' languages like Lisp, APL derivatives, but... So my questions are, Does code already exist that recognizes the programming language of a text file? (Surely this must be a less complicated task than eclipse's syntax trees or than Google Translate's language guessing feature, right?) In fact, does the SO syntax highlighter do anything like this? Is it theoretically possible to create a single interpreter or compiler that recognizes what language idiom you're using at any moment and (maybe "intelligently") executes or translates to a runnable form. And flags the corner cases where my syntax is ambiguous with regards to behavior. Immediate difficulties I see include: knowing when to switch between indentation-dependent and brace-dependent modes, recognizing funny operators (like *pointer vs *kwargs) and knowing when to use list vs array-like representations. Is there any language or interpreter in existence, that can manage this kind of flexible interpreting? Have I missed an obvious obstacle to this being possible? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Yes, there exists a code that recognizes the programming language of a text file. we have to implement a simple pseudocode interpreter which has very basic functionality as well as a contiguous memory store. Here is how it works: You feed the program a CRLF separated list of valid syntax. The files named “pseudocode.txt” should be in the same directory as the program. The program is able to read, parse, and executes the given instructions present in the text. Any errors that are identified, are reported, else the program runs until STOP instruction or EOF. The instruction set is very limited. There are about 18 operations which can have 2 operands. If something is contained in [brackets] then that is referring to one of the 1000 available memory locations ([0] to [999]). To detect what programming language has used is the method used in spam filters. You split the snippet into words. Then you compare the occurrences of these words with known snippets and compute the probability that this snippet is written in language X for every language you're interested in.Bayesian_spam_filtering If you have the mechanism of adding new languages then just train the detector with a few snippets in the new language (you could feed it an open source project). This way the system is likely to appear in C# snippets and "puts" in Ruby snippets.

Related questions

0 votes
    In the MNIST beginner tutorial, there is the statement accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) tf ... (x,1)? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am looking for an open source neural network library. So far, I have looked at FANN, WEKA, and OpenNN. Are the ... , and ease of use. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    What is the difference between informed and uninformed searches? Can you explain this with some examples? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm looking for some examples of robot/AI programming using Lisp. Are there any good online examples available ... in nature)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm working through my AI textbook I got and I've come to the last homework problem for my section: "Implement the ... in C# or Java? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm teaching a kid programming, and am introducing some basic artificial intelligence concepts at the moment. To begin ... and boxes)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I am searching for information on algorithms to process text sentences or to follow a structure when creating sentences ... be great. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm looking to try and write a chess AI. Is there something I can use on the .NET framework (or maybe ... making a chess game? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm writing a game that's a variant of Gomoku. Basically a tic tac toe on a huge board. Wondering if anyone ... [self put randomly]; } Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm Working on document classification tasks in java. Both algorithms came highly recommended, what are the ... Processing tasks? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I'm trying to implement stochastic gradient descent in MATLAB however I am not seeing any convergence. Mini-batch ... cost of 420. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am currently working on an AI Agent that will be able to identify both the start state and the goal ... be greatly appreciated. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    The problem is that I cannot make a script that makes the enemy rotate so that "up" is pointing against the ... something simple... Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am building a model for binary classification problem where each of my data points is of 300 dimensions (I am ... the 300 dim space? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I'm wondering how to calculate precision and recall measures for multiclass multilabel classification, i.e. classification ... labels? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
...