Compiler
Thunder to C# compiler
Write a program in Thunder, the human programming language, and get C#. The same program gives the same output in all six languages Thunder compiles to.
✓ Thunder understands this program.
Type or paste your own. It converts as you type, in your browser: nothing is sent anywhere.
In C#
// Generated by the Thunder compiler from main.thunder.
// A build artifact: change main.thunder and build again, or keep this file and edit it as C#.
// It needs only .NET and ThunderRuntime.cs (written next to it). "// thunder:N" marks the Thunder line.
#nullable disable
#pragma warning disable CS0162, CS0168, CS0219, CS0472, CS1717, CS8321
namespace ThunderProgram
{
using Thunder;
public static class M_main
{
const string FILE = "main.thunder";
public static object shipping_cost(object weight, object express) // thunder:1
{
var F = T.enterCall(FILE, 1, 3);
try
{
object cost = null;
F.line = 3; // thunder:3
if (T.at(F, 3) && T.compare("<=", weight, T.I("0"))) { // thunder:3
F.line = 4; throw T.Stop(T.pyStr("weight must be positive")); // thunder:4
}
F.line = 5; cost = T.add(T.I("5"), T.mul(weight, T.I("2"))); // thunder:5
F.line = 6; // thunder:6
if (T.at(F, 6) && (T.yesNo(express) == true)) { // thunder:6
F.line = 7; cost = T.mul(cost, T.dec("1.5")); // thunder:7
}
F.line = 8; return cost; // thunder:8
return null;
}
catch (System.Exception __t_e1) { throw T.fail(__t_e1); }
finally { T.leave(); }
}
public static object grade(object score) // thunder:10
{
var F = T.enterCall(FILE, 10, 12);
try
{
F.line = 12; // thunder:12
if (T.at(F, 12) && T.compare(">=", score, T.I("90"))) { // thunder:12
F.line = 13; return "A"; // thunder:13
} else if (T.at(F, 14) && T.compare(">=", score, T.I("80"))) { // thunder:14
F.line = 15; return "B"; // thunder:15
} else if (T.at(F, 16) && T.compare(">=", score, T.I("70"))) { // thunder:16
F.line = 17; return "C"; // thunder:17
}
F.line = 18; return "F"; // thunder:18
return null;
}
catch (System.Exception __t_e2) { throw T.fail(__t_e2); }
finally { T.leave(); }
}
public static void Init()
{
}
public static readonly (string, System.Action, int)[] THUNDER_TESTS = new (string, System.Action, int)[]
{
};
public static void main()
{
var F = T.enterFrame(FILE, 0);
try
{
F.line = 20; T.say(T.show(shipping_cost(T.I("3"), false))); // thunder:20
F.line = 21; T.say(T.pyStr(grade(T.I("85")))); // thunder:21
}
catch (System.Exception __t_e3) { throw T.fail(__t_e3); }
finally { T.leave(); }
}
}
}What you get
- C# that runs and gives the same results as every other language Thunder compiles to: exact decimals, the same errors, the same output. The same test programs check every target.
- Generated code, not hand-written style. Values are dynamic, and the code uses a small Thunder runtime file that
thunder buildwrites next to it. It runs, and you can keep and edit it, but it won't read like C# a person would write. - Each line ends with a mark showing the Thunder line it came from, so you can trace any line back.
What compiles today
- Thunder Core programs: functions, decisions, lists, records, either/or data, saved data, tests, and more. Thunder Core guide.
- Some features work on some targets only (for example, HTTP endpoints on Python, TypeScript, and the Thunder engine). When a program can't be written in C#, the converter says so instead of writing something different.
The example, step by step
Written by the Thunder compiler 2.0.0 while this page was built, not by hand.
Thunder
To shipping cost:
Receive weight and express
When weight is at most 0:
Stop with "weight must be positive"
Set cost to 5 + weight * 2
When express is true:
Set cost to cost * 1.5
Give cost
To grade:
Receive score
When score is at least 90:
Give "A"
Otherwise when score is at least 80:
Give "B"
Otherwise when score is at least 70:
Give "C"
Give "F"
say shipping cost with 3 and false
say grade with 85C#
// Generated by the Thunder compiler from main.thunder.
// A build artifact: change main.thunder and build again, or keep this file and edit it as C#.
// It needs only .NET and ThunderRuntime.cs (written next to it). "// thunder:N" marks the Thunder line.
#nullable disable
#pragma warning disable CS0162, CS0168, CS0219, CS0472, CS1717, CS8321
namespace ThunderProgram
{
using Thunder;
public static class M_main
{
const string FILE = "main.thunder";
public static object shipping_cost(object weight, object express) // thunder:1
{
var F = T.enterCall(FILE, 1, 3);
try
{
object cost = null;
F.line = 3; // thunder:3
if (T.at(F, 3) && T.compare("<=", weight, T.I("0"))) { // thunder:3
F.line = 4; throw T.Stop(T.pyStr("weight must be positive")); // thunder:4
}
F.line = 5; cost = T.add(T.I("5"), T.mul(weight, T.I("2"))); // thunder:5
F.line = 6; // thunder:6
if (T.at(F, 6) && (T.yesNo(express) == true)) { // thunder:6
F.line = 7; cost = T.mul(cost, T.dec("1.5")); // thunder:7
}
F.line = 8; return cost; // thunder:8
return null;
}
catch (System.Exception __t_e1) { throw T.fail(__t_e1); }
finally { T.leave(); }
}
public static object grade(object score) // thunder:10
{
var F = T.enterCall(FILE, 10, 12);
try
{
F.line = 12; // thunder:12
if (T.at(F, 12) && T.compare(">=", score, T.I("90"))) { // thunder:12
F.line = 13; return "A"; // thunder:13
} else if (T.at(F, 14) && T.compare(">=", score, T.I("80"))) { // thunder:14
F.line = 15; return "B"; // thunder:15
} else if (T.at(F, 16) && T.compare(">=", score, T.I("70"))) { // thunder:16
F.line = 17; return "C"; // thunder:17
}
F.line = 18; return "F"; // thunder:18
return null;
}
catch (System.Exception __t_e2) { throw T.fail(__t_e2); }
finally { T.leave(); }
}
public static void Init()
{
}
public static readonly (string, System.Action, int)[] THUNDER_TESTS = new (string, System.Action, int)[]
{
};
public static void main()
{
var F = T.enterFrame(FILE, 0);
try
{
F.line = 20; T.say(T.show(shipping_cost(T.I("3"), false))); // thunder:20
F.line = 21; T.say(T.pyStr(grade(T.I("85")))); // thunder:21
}
catch (System.Exception __t_e3) { throw T.fail(__t_e3); }
finally { T.leave(); }
}
}
}On your computer
The same conversion with the thunder command (Node.js 18+). Nothing is sent anywhere, and no AI is involved.
npm install -g @skillstech/thunderlang
thunder build shipping.thunder --core --target csharp # writes generated/csharp/