I need to create a porting software that will convert Java code to C# (and vice verse, but I will look into that after). The software will aim at people who are proficient in one language and know completely nothing about the other one, and also if you have a very good piece of source code on one platform and want to use it on another without having to manually change it.
I know there are existing works similar to this, but I need to create my own (also for practice purposes), and I’m not really sure how to start. I have considered making a C# project which will call a .Java source code, and go through it line by line and convert the text to what C# looks like. Example: public class Car extends Vehicle {} change to public class Car : Vehicle {} and go on about changing every difference between the two languages.
Is this the proper approach and are there any other ones?
*Note: I have found articles about it, and I saw AST and Parsing come out a lot, as well as several parsers such as NRefactory. Can anyone explain how are those terms related to my problem, and how does a parser(NRefactory) works? The definitions gave me an overview, but I’m still not sure if I understand the concept.
Java has features that don’t exist in C# and C# has features that don’t exist in Java so a simple one to one correspondence conversion is impossible.
Look here to see where you’ll start running into problems.
A parser is necessary to properly convert syntax of one language which doesn’t exist in another, so you’ll essentially need to build an interpreter which is not a trivial project.
Compilers, like interpreters are based on a syntax parser. You can find lots of good tutorials and resources online for compiler constructions by google search. For example, here is a good one.