public override void EnterFile(SwiftParser.FileContext context) { OutLine("using System;"); OutLine("using System.Linq;"); OutLine(""); OutLine("class Program {"); OutLine("static bool CompareWithTypes(object one, object another)"); OutLine("{"); OutLine("if(one is int && another is int) {"); OutLine("return (int)one == (int)another;"); OutLine("}"); OutLine("else if(one is double && another is double) {"); OutLine("return (double)one == (double)another;"); OutLine("}"); OutLine("else if(one is bool && another is bool) {"); OutLine("return (bool)one == (bool)another;"); OutLine("}"); OutLine("else {"); OutLine("return false;"); OutLine("}"); OutLine("}"); OutLine("static string Print(object o)"); OutLine("{"); OutLine("if(o is double) {"); OutLine("return String.Format(\"{0:0.0###########} \", (double)o);"); OutLine("}"); OutLine("else {"); OutLine("return o.ToString() + \" \";"); OutLine("}"); OutLine("}"); OutLine("public static void Main() {"); }
public override void ExitFile(SwiftParser.FileContext context) { if (!Valid.HasValue) { Valid = true; } }
public override void EnterFile(SwiftParser.FileContext context) { OutLine("using System;"); OutLine(""); OutLine("class Program {"); OutLine("static bool CompareWithTypes(object one, object another)"); OutLine("{"); OutLine("return one.GetType() == another.GetType() && one == another;"); OutLine("}"); OutLine("static bool LessThanEvenForStrings(object one, object another)"); OutLine("{"); OutLine("if(one is string && another is string) {"); OutLine("return String.Compare((string)one, (string)another) < 0;"); OutLine("}"); OutLine("else {"); OutLine("throw new Exception($\"< cannot be applied to objects of types {one.GetType()} and {another.GetType()}\");"); OutLine("}"); OutLine("}"); OutLine("static bool GreaterThanEvenForStrings(object one, object another)"); OutLine("{"); OutLine("if(one is string && another is string) {"); OutLine("return String.Compare((string)one, (string)another) > 0;"); OutLine("}"); OutLine("else {"); OutLine("throw new Exception($\"> cannot be applied to objects of types {one.GetType()} and {another.GetType()}\");"); OutLine("}"); OutLine("}"); OutLine("static string Print(object o)"); OutLine("{"); OutLine("if(o is bool) {"); OutLine("if((bool)o) {"); OutLine("return \"true\";"); OutLine("}"); OutLine("else {"); OutLine("return \"false\";"); OutLine("}"); OutLine("}"); OutLine("else {"); OutLine("return o.ToString();"); OutLine("}"); OutLine("}"); OutLine("public static void Main() {"); }
public override void ExitFile(SwiftParser.FileContext context) { OutLine("}"); Out(ClassDeclrsOutput); OutLine("}"); }
public override void ExitFile(SwiftParser.FileContext context) { OutLine("}"); OutLine("}"); }