Giter Club home page Giter Club logo

cpptopython's Introduction

cppTopython

This code has been written in Python. Works and tested well with python 3.5+

About the project:

  • This program takes a CPP file as input and produces a python file as output with the required code conversion form C++ to python
  • The program is written in python language and is written in simple language for better readability.The program makes use of several core concepts of python programming language such as defining functions,using inbuilt functions,file concepts along with multiple iterative and conditional statements and basic concepts of lists,tuples and dictionaries to read,create and print the lines of code in C++ into another file after conversion
  • The program relies heavily on line by line iteration of the input data after which defined functions are called to detect the presence of specific statements or words in the line of code to change it to the corresponding python code syntax
Note:

The above code doesnt work for any of the OOP principles in C++. It works well with simple C++ programs. This program was designed, keeping in mind those individuals who transition from C++ to Python, and almost want to quickly get to know the syntax of the the language.

To run:

  1. Execute the cpptopy.py file on a terminal or an IDE etc.
  2. Enter the name of your input file in .cpp or .txt format.(Sample C++ files are placed in Sample_Cpp folder)
  3. Enter the name of the final output file in a .py file. You can execute the newly created .py file to check if it works. !! Ensure you take care of brackets !!

Limitations:

  • The C++ code taken as the input should always contain only one line of code in a single line and should NOT include multiple lines separated by ";" Ex:"cout<<"hello"; cin>>a;" works but "cout<<"hello";cin>>a;" doesn't work.
  • Multiple variable declaration is not supported in the same line but inizialization works. Ex: "int a=10; int b=10; int a,b=10;" works but "int a,b" doesn't work.
  • Multiple cin and cout cascading not supported. Ex:"cin>>a>>b;" doesn't work.
  • Prototypes are required before function call regardless of where the function is defined. Ex: void amstr(int); void amstr(int a) {... .... ....} works but void amstr(int a) {... .... ....} without prototype will not be identified as a function.
  • condition statements or iterative statements won't work if they do not contain flower brackets. Ex: if (a==5) cout<<"hello"; works in C++ but for proper conversion it has to be in the form if (a==5) { cout<<"hello"; }
  • Opening and Closing of Brackets for each block should be in seperate lines and these lines should not have any statememnts. Ex: "if(i<=90) { cout<"if(i<=90) {cout<<i; }"doesn't work

    "if(i<=90) { cout<<i;}"doesn't work

  • void main() works but int main() dosen't.
  • Classes with only inline functions work.
  • int k = func(); doesn't work but func() and cout of func() works

Scope:

-This program can be used in educational institutions for better understanding of how python works.
-Can be used as a tool for beginners to understand Python code by comparing with the corresponding C++ code.
-Is effective when instant switching is required for professionals since python supports much more libraries and is more powerful when compared to C++.

Commits are entertained.

cpptopython's People

Contributors

pvn-a avatar

Watchers

 avatar

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.