Question

I'm building a visual programming tool and was wondering if you could suggest a library or even throw at me ideas about a tool that I can build myself that translates the pseudo-code to a concrete language as PHP, JAVA. For example for a pseudocode like that:

do i = 1 to 100 
   print "Hello World !!!";
   newline;
end do

I would like to get something similar to:

in PHP:

for ($i = 1; $x <= 100; $x++) {
    echo "Hello World !!!";
    echo PHP_EOL;
}

in Java:

for(int i = 1; x <= 100; x++) {
    System.out.print("Hello World !!!");
    System.out.print("\n");
}

I don't just want a translator from PHP to Java or vise versa. I guess my question is: Will I be able to generate code in all kinds of languages after specifying some basic language structure rules and writing the pseudo-code? I want to break the gap between the pseudocode and code in a concrete language so I won't need to translate the code by hand. Also by writing the algorithm in pseudocode once, I would generate the code in a whatever language I want.

Thank you for your feedback!

edit: ok, so not "pseudo" code then, defining a language that will work as a intermediate. Does any one have a suggested library for that I can look into?

Was it helpful?

Solution

The whole point of pseudo-code is that it has no definite syntax and no definite semantics. It is a way for human beings to communicate algorithms to other human beings in a way that avoids the reader and writer having to worry about such details.

That means that it impossible to translate automatically. Instead, you need a human being to understand what the pseudo-code means and then write code in a concrete programming language that has the same effect.


Another way to look at this is that if "pseudo-code" had defined syntax and semantics, it wouldn't be "pseudo". It would be real code.

Of course, there is nothing stopping you from defining a language of this nature ... but then you'd need to implement compilers and/or translators for your pseudo-pseudo-code ( :-) ).


There are various tools that you could use to help you build a source code to source code translator. Search for "parser generator" and "template engine".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top