A simple LISP transpiler that handles only binary operators.
ID: 1416
using uCalcSoftware;
var uc = new uCalc();
var t = uc.ExpressionTransformer;
t.FromTo("({op:1} {a:1} {b:1})", "({a} {op} {b})");
Console.WriteLine("LISP: (+ 10 20)");
Console.WriteLine($"uCalc: {t.Transform("(+ 10 20)")}");
Console.WriteLine($"Result: {uc.Eval("(+ 10 20)")}");
LISP: (+ 10 20)
uCalc: (10 + 20)
Result: 30 using uCalcSoftware; var uc = new uCalc(); var t = uc.ExpressionTransformer; t.FromTo("({op:1} {a:1} {b:1})", "({a} {op} {b})"); Console.WriteLine("LISP: (+ 10 20)"); Console.WriteLine($"uCalc: {t.Transform("(+ 10 20)")}"); Console.WriteLine($"Result: {uc.Eval("(+ 10 20)")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.ExpressionTransformer();
t.FromTo("({op:1} {a:1} {b:1})", "({a} {op} {b})");
cout << "LISP: (+ 10 20)" << endl;
cout << "uCalc: " << t.Transform("(+ 10 20)") << endl;
cout << "Result: " << uc.Eval("(+ 10 20)") << endl;
}
LISP: (+ 10 20)
uCalc: (10 + 20)
Result: 30 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.ExpressionTransformer(); t.FromTo("({op:1} {a:1} {b:1})", "({a} {op} {b})"); cout << "LISP: (+ 10 20)" << endl; cout << "uCalc: " << t.Transform("(+ 10 20)") << endl; cout << "Result: " << uc.Eval("(+ 10 20)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.ExpressionTransformer
t.FromTo("({op:1} {a:1} {b:1})", "({a} {op} {b})")
Console.WriteLine("LISP: (+ 10 20)")
Console.WriteLine($"uCalc: {t.Transform("(+ 10 20)")}")
Console.WriteLine($"Result: {uc.Eval("(+ 10 20)")}")
End Sub
End Module
LISP: (+ 10 20)
uCalc: (10 + 20)
Result: 30 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.ExpressionTransformer t.FromTo("({op:1} {a:1} {b:1})", "({a} {op} {b})") Console.WriteLine("LISP: (+ 10 20)") Console.WriteLine($"uCalc: {t.Transform("(+ 10 20)")}") Console.WriteLine($"Result: {uc.Eval("(+ 10 20)")}") End Sub End Module