All Projects → uxmal → Pytocs

uxmal / Pytocs

Licence: apache-2.0
Converts Python source to C#

Programming Languages

python
139335 projects - #7 most used programming language
csharp
926 projects

Projects that are alternatives of or similar to Pytocs

escapin
Escapin is a JS/TS transpiler for escaping from complicated usage of cloud services and APIs
Stars: ✭ 20 (-93.06%)
Mutual labels:  transpiler
BashClass
BashClass is an Object Oriented Programming language that compiles to BASH 4.4
Stars: ✭ 40 (-86.11%)
Mutual labels:  transpiler
wxml-transpiler
Port of wcc.exe to JavaScript. wxml 文件编译器 --- 里面有很多无用代码,有空再整理下
Stars: ✭ 21 (-92.71%)
Mutual labels:  transpiler
js-slang
Implementations of the Source languages, which are small sublanguages of JavaScript designed for SICP JS
Stars: ✭ 41 (-85.76%)
Mutual labels:  transpiler
grizzly
A Python-to-SQL transpiler as replacement for Python Pandas
Stars: ✭ 27 (-90.62%)
Mutual labels:  transpiler
Go2SourcePawn
Go2SourcePawn is a transpiler that transforms a subset of Golang-like code to equivalent SourcePawn.
Stars: ✭ 13 (-95.49%)
Mutual labels:  transpiler
ShenScript
Shen for JavaScript
Stars: ✭ 40 (-86.11%)
Mutual labels:  transpiler
Go On Rails
🚄 Use Rails to Develop or Generate a Golang Application.
Stars: ✭ 275 (-4.51%)
Mutual labels:  transpiler
rewrite-imports
Rewrite `import` statements as `require()`s; via RegExp
Stars: ✭ 31 (-89.24%)
Mutual labels:  transpiler
Yuescript
A Moonscript dialect compiles to Lua.
Stars: ✭ 172 (-40.28%)
Mutual labels:  transpiler
bck2brwsr
Bck2Brwsr VM to transpile Java bytecode to JavaScript
Stars: ✭ 93 (-67.71%)
Mutual labels:  transpiler
sqlglot
Python SQL Parser and Transpiler
Stars: ✭ 310 (+7.64%)
Mutual labels:  transpiler
go2cpp
Go to C++20 transpiler
Stars: ✭ 51 (-82.29%)
Mutual labels:  transpiler
Headache
Programming Language that compiles to 8 Bit Brainfuck
Stars: ✭ 59 (-79.51%)
Mutual labels:  transpiler
idealingua-v1
IdeaLingua RPC for Scala, TypeScript, C#, Go
Stars: ✭ 13 (-95.49%)
Mutual labels:  transpiler
sugartex
SugarTeX is a more readable LaTeX language extension and transcompiler to LaTeX. Fast Unicode autocomplete in Atom editor via https://github.com/kiwi0fruit/atom-sugartex-completions
Stars: ✭ 74 (-74.31%)
Mutual labels:  transpiler
go2hx
Go -> Haxe -> JS Java C# C++ C Python Lua
Stars: ✭ 49 (-82.99%)
Mutual labels:  transpiler
Js2php
JavaScript (ES6) to PHP source-to-source transpiler.
Stars: ✭ 290 (+0.69%)
Mutual labels:  transpiler
Il2c
IL2C - A translator for ECMA-335 CIL/MSIL to C language.
Stars: ✭ 270 (-6.25%)
Mutual labels:  transpiler
grumpy
Grumpy is a Python to Go source code transcompiler and runtime.
Stars: ✭ 378 (+31.25%)
Mutual labels:  transpiler

pytocs

Join the chat at https://gitter.im/uxmal/pytocs

Converts Python source to C#

pytocs is a command line tool I wrote as a hobby project to convert Python source code to C#. I've uploaded it here in case someone finds it useful.

How to run pytocs

Just git clone the project, and use Visual Studio or MSBuild to compile the pytocs.sln file. If you're unable or unwilling to build pytocs from source, the latest continuous integration build is available at appveyor.com.

Examples

To convert a Python file, hand it to pytocs:

pytocs foo.py

To convert all files in a directory (recursively), use the -r parameter:

pytocs -r 

The following python fragment:

# Some code below
def hello():
   print "Hello World";

Translates to:

public static class hello {

    public static object hello() {
	    Console.WriteLine("Hello World");
    }
}

A more ambitious sample:

class MyClass:
    # member function calling other function
    def calc_sum(self, x, y):
       return self.frobulate('+', x, y)

    # arithmetic and exceptions
    def frobulate(self, op, x, y):
        if op == '+':
            return x + y
        elif op == '-':
            return x - y
        else:
            raise ValueError("Unexpected argument %s" % op)

    # static method using for..in and enumerate, with tuple comprehension
    def walk_list(lst):
        for (i,strg) in lst.iterate():
            print "index: %d strg: %s\n" % (i, strg)
 
    # list comprehension, generating linQ output.
    def apply_map(mapfn, filterfn):
        return [mapfn(n) for n in lst if filterfn]

Translates to:

using System;

using System.Linq;

public static class readme {
    
    public class MyClass {
        
        // member function calling other function
        public virtual object calc_sum(object x, object y) {
            return this.frobulate("+", x, y);
        }
        
        // arithmetic and exceptions
        public virtual object frobulate(object op, object x, object y) {
            if (op == "+") {
                return x + y;
            } else if (op == "-") {
                return x - y;
            } else {
                throw new ValueError(String.Format("Unexpected argument %s", op));
            }
        }
        
        // static method using for..in and enumerate, with tuple comprehension
        public static object walk_list(object lst) {
            foreach (var _tup_1 in lst.iterate()) {
                var i = _tup_1.Item1;
                var strg = _tup_1.Item2;
                Console.WriteLine(String.Format("index: %d strg: %s\n", i, strg));
            }
        }
        
        // list comprehension
        public static object apply_map(object mapfn, object filterfn) {
            return (from n in lst
                where filterfn
                select mapfn(n)).ToList();
        }
    }
}

Roadmap

The next big items on the list are:

  • Take the types that are inferred and apply them to the code to get away from everything being object.
  • Place local variable declarations at the statement that dominates all definitions of said variables.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].