Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Taking Ben Griswold advice, I think it is a good idea to implement it myself. And while just a little into implementing code generator in C#, I realized few things -<br> 1. Need text manipulation language like Python etc.<br> 2. Need to learn Regular expressions </p> <p>I do intend to implement it in Ruby but for now, I implemented it in C# as -</p> <pre><code>static void Main(string[] args) { CodeGenerator gen = new CodeGenerator(); gen.ReadFile("Input.txt"); } public class CodeGenerator { public void ReadFile(string filename) { StreamReader fs = new StreamReader(filename); string line; CSharpCode CG = new CSharpCode(); while ((line = fs.ReadLine()) != null) { line = line.TrimEnd('\n'); if (Regex.IsMatch(line, @"^\s*S")) CG.BlankLine(); else if (Regex.IsMatch(line, @"^\#(.*)")) // match comments CG.Comment(line.TrimStart('#')); else if (Regex.IsMatch(line, @"^M\s*(.+)")) // start msg CG.StartMsg(line.Split(' ')[1]); else if (Regex.IsMatch(line, @"^E")) // end msg CG.EndMsg(); else if (Regex.IsMatch(line, @"^F\s*(\w+)")) // simple type CG.SimpleType(Regex.Split(line, @"^F\s*(\w+)")[1], Regex.Split(line, @"^F\s*(\w+)")[2]); else Console.WriteLine("Invalid line " + line); } } } // Code Generator for C# public class CSharpCode { public void BlankLine() { Console.WriteLine(); } public void Comment(string comment) { Console.WriteLine("//" + comment); } public void StartMsg(string name) { Console.WriteLine("public struct " + name + "{"); } public void EndMsg() { Console.WriteLine("}"); } public void SimpleType(string name, string type) { if(type.Contains("char[")) type = "string"; Console.WriteLine(string.Format("\t{0} {1};", type.Trim(), name)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload