package PascalToCSharp;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
System.out.print("Enter name file: ");
String fileName = new Scanner(System.in).nextLine();
if ((new java.io.File(fileName)).isFile())
{
java.io.FileReader filePascal = new java.io.FileReader(fileName);
java.io.BufferedReader filePascalBufferedReader = new java.io.BufferedReader(filePascal);
java.io.FileWriter fileCSharp = new java.io.FileWriter(fileName.substring(0, fileName.length() - 3) + "cs");
String line;
do
{
line = filePascalBufferedReader.readLine();
if (line != null)
{
line = line.replace("writeLn", "Console.WriteLine");
line = line.replace(" = ", "==");
line = line.replace(" :=", "=");
line = line.replace("'", "\"");
line = line.replace("begin", "{");
line = line.replace("end;", "}");
line = line.replace("end.", "}");
line = line.replace("end", "}");
if ((line.contains("program ")) && (line.substring(line.length() - 1).equals(";")))
{
line = line.replace("program ", "class ");
line = line.replace(";", "\n{\n static void Main()\n{");
}
if (line.contains("readLn("))
{
line = line.replace("readLn(", "");
line = line.replace(");", "");
line += " = Convert.ToInt32(Console.RadLine());";
}
line = line.replace("var", "");
if (line.contains(": integer;"))
{
line = line.replace(": integer;", "");
line = "int " + line.trim() + ";";
}
/* if ((line.Contains("for ")) &&
(line.Contains(" to ")) &&
(line.Contains(" do ")))
{
line = line.Replace("for ", "for (");
line = line.Replace(" to", "");
line = "int " + line.Trim() + ";";
}
fileCSharp.write(line + System.lineSeparator());
}
} while (line != null);
filePascal.close();
fileCSharp.close();
}
}
}