GithubHelp home page GithubHelp logo

mulan-szechuan-sauce / javelin Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 1.0 21 KB

Python3 to C++11 transpiler written in C++

Makefile 1.44% Shell 1.37% C++ 63.56% Lex 7.17% Yacc 21.42% Python 5.04%
transpiler python compiler cpp

javelin's Introduction

What is Javelin?

Javelin is a Python3 to C++11 transpiler written in C++11. When possible, it implies types automatically in Python.

Examples

Recursive Fibonacci

Fibonacci is a nice example of how recursive calls are compiled.

def fib(n):
  if n == 0 or n == 1:
    return 1
  return fib(n - 1) + fib(n - 2)

i = 0
while i < 10:
  print("Fibonacci number " + str(i) + ": " + str(fib(i)))
  i = i + 1

Will transpile into:

#include "inc/javelin.h"
int fib(int n);
int main() {
  int i = 0;
  while (i < 10) {
    std::cout << std::string("Fibonacci number ") +
        std::to_string(i) + std::string(": ") +
        std::to_string(fib(i)) << std::endl;
    i = i + 1;
  }
}
int fib(int n) {
  if (n == 0 || n == 1) {
    return 1;
  }
  return fib(n - 1) + fib(n - 2);
}

List support

We currently support limited list functionality:

i = [[1, 2, 3], [4, 5, 6, 7]]

for foo in i:
    for bar in foo:
        print(bar)
    print("    ")

Compiles into:

#include "inc/javelin.h"
int main() {
  std::vector<std::vector<int>> i = {{1,2,3},{4,5,6,7}};
  for (std::vector<int> foo : i) {
    for (int bar : foo) {
      std::cout << bar << std::endl;
    }
    std::cout << std::string("    ") << std::endl;
  }
}

javelin's People

Contributors

elimirks avatar anonymouscommitter avatar wolfecub avatar

Stargazers

Cairdac avatar Andrew Johnson avatar  avatar  avatar  avatar Andrea Zanelli avatar  avatar Xhark avatar X Caminhante avatar JaredYeah avatar  avatar Alexei Frolov avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

vamuvetv

javelin's Issues

Division is Broken

The expression (3 / 4) in Python will be translated to (3/4) in C++ (which of course evaluates to 0). However, in Python, it should evaluate to the float value 0.75.

For now, we could force users to use the “//” operator… But in the future, we should support floats of course.

Great Project

Hi,
i like this (Python3-to-C++11) "javelin" transpiler project.
its useful.
i have Starred this project.
it needs to be improved further.

Thanks.

EXTRA INFO : BTW , i have mentioned it in a Transpiler List here in SO(StackOverflow) site , would you please UPVOTE it here ( or vote to UNDELETE it ) ? please upvote my Question+Answer, both, if you find it useful or if you think it will be helpful for other users related to this type of transpiler projects . By the way, Transpiler-List can be seen from here or here or find it under my repo(s) here.
( and please downvote user Caleb's answer, as that is incorrect answer . Correct-answer must answer my questions first , My question is about "Transpiler" tools & which "transpiler" tool can keep high-level algorithms/structures intact , Question/article is NOT about language learning, when to transpile & when-not, etc.
In SO site, user Flimzy (and Caleb) doesn't give advice When "C/C++",etc to "Go" conversion related question is posted or when "C/C++" is criticized , But when "Go"-to-"C/C++",etc conversion Question is posted or when Google based products (like "Go"-language) are criticized , then those users, especially Flimzy "Close" the question & downvotes, & gives many un-asked advices, etc, Because those users are Google PUSHERS & google based product (like "Go", Google-Advertisements,etc) PUSHERS . Flimzy edited-out important text from my post criticizing Advertisements . Google Crimes1, 2, 3, 4, 5, 6. Problems in "Go"1, 2, 3, 4, 5, 6, 7. )

EDIT : i have Starred this project.
EDIT : updated the upvote para.
EDIT : added few links for Transpiler-List new page.
EDIT : added links for "Go"/"Golang"-Problems.

Redeclarations should be allowed

Potentially, we should be able to support redeclarations by numbering NIdentifiers. For instance, setting "foo = 2" will set foo to an int type, but then evaluating "foo = 'hi'" should redefine it as a string, EXCEPT the first foo is "foo1" and the second is "foo2". This way, we can reuse identifiers for different types, and it shouldn't break anything.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.