using System;
using System.IO;
namespace PascalToCSharp
{
class Program
{
static void Main()
{
Console.Write("Enter name file: ");
string fileName = Console.ReadLine();
if (File.Exists(fileName))
{
StreamReader filePascal = File.OpenText(fileName);
StreamWriter fileCSharp = File.CreateText(fileName.Substring(0, fileName.Length - 3) + "cs");
string line;
do
{
line = filePascal.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) == ";"))
{
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.WriteLine(line);
}
}
while (line != null);
filePascal.Close();
fileCSharp.Close();
}
}
}
}