C++ to simpler language (Python, Lua, etc) converter? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I know Python and I've come across a small C++ source file I would like to convert to Python. But the C++ code is too complex for me to understand without learning the language.
So I was wondering if there is a tool that does the opposite of what many people want: convert C++ code to Python, or another simpler language I could understand.
I know these tools work on very simple code and hardly do a perfect job even then, but the code I have is pretty small and simple.
I have found "ctopy", but there is no usage example, if I just pass a .cpp file to it, it just hangs, no error message or anything.
And maybe it won't work for C++ at all.
http://www.catb.org/~esr/ctopy/

Most translators produce inferior code which you can't really use anywhere; and the more complicated your code is, the worse the results are. Only real human brains can do that perfectly. I'd suggest that you learn the language. If you already know python, learning another language shouldn't be too difficult.

I've seen (and wanted) such a programming code converter and found exactly what you want in cpp2py although I personally haven't tried it for myself website https://github.com/hlamer/cpp2python

It's a little painful, but I have gotten some python code using
https://code.google.com/p/ctypesgen/
For some reason it doesn't handle bool's.
It probably uses regex substitutions, and other things like that, but it sure beats writing out your own ctypes wrapper without it.
http://docs.python.org/2/library/ctypes.html
Another option you could look into, is compiling your C++ into an executable and then running the executable using python.
And if you decide you need the power of C/C++ in your tool belt:
https://stackoverflow.com/questions/3973899/learning-c-java-coming-from-python
Hope that helps.

Related

Good Python Module for Saving Data [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
Okay, so I'm new to coding, so don't kill me. I just started about a year ago and I use repl.it. I want to learn how to save user data. Also I want to know what python IDE is best suited for this.
If you want human-readable cross-programming-language data files, check out the json module.
If you want data that is faster, but that only python can read, check out the pickle module.
About your IDE Question:
From my point of view, you don`t need an full featured IDE at this point, though PyCharm is quite nice, despite the fact that it's written in java xD... (and it has a ton oof features that will be noise for a beginner (ME 2 ...)) you can make sth. like VS Code quite easy to sth. like a lightweight IDE. If you don't like Microsoft, go for Sublime, or Atom (both also Editors with nice plugins and extensions for Python and other languages...)
If you want to go for scientific python features: check out https://www.spyder-ide.org/
Have fun :-)

Looking for a collection of parsers to extract function/class definitions [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I'm preparing to make a little IDE that allows to expand function/macro calls to their definitions right in the place they are called (and do that recursively if needed, so that if funciton A calls B, I expand B, then B calls C - I expand C in the code of B etc.):
Question 1: do you know of existing IDEs with this feature?
Question2: How would you implement that? My approach is as follows: I'd like to have the IDE being able to understand various programming languages. In order to extract function definitions, I'll seemingly have to use parsers. Is there any collection of parsers for various languages? I've looked into Ctags and Pygments lexers, but their output is insufficient to accomplish this task.
Preferable language for IDE is Python (although Java and C suggestions are ok, too), graphial library - gtk+2. Thanks.
Question 1: do you know of existing IDEs with this feature?
Not perhaps quite what you describe, but Visual Studio's Code Definition Window shows the definition of any symbol at the current cursor position. It differs of course in that it shows the definition in a separate window to the editor window, but to be honest I would find your proposition somewhat jarring and counter-intuitive since the calls are not semantically in-line.
What you want is called "goto definition" in most IDEs. Granted, they don't expand inline, but you have to put the definition somewhere.
As a general rules, many IDEs have split windows so the definition can be seen at the same time with the original call. It seems to me that you essentially want to automate the setup of splitting the windows, and going the definition point.
Many IDEs contain internally programmable interfaces. You can probably do with with Eclipse; you could certainly do this with Emacs, if M-x goto-definition-in-new-window isn't already built in :-}

What is the best way to learn and master Python, from a procedural programmer perspective? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am Mathematician and I currently work mainly on Operations Research field, building algorithms for solving Mathematical Programming or Optimization problems.
I learnt Fortran, Pascal and C (oh, and Visual Basic) when I was a student, not very deeply, but in the case of C I managed quite well with pointers, structs and so on, for example.
Later, I've been using Visual C++ for my research, building algorithms for my problems and so on. I am not able to create any GUI and I don't use objects but a classical procedural perspective, so in fact I use C with some characteristics from C++.
There was a moment when I tried to learn Python. It seemed so friendly, fresh, interesting, simple but powerful...  But at the end, I was a little bit confused, because of many different reasons, for example:
I was used to procedural languages, and Python is functional oriented, a little bit at least.
I was used to languages that can create .exe files (compiled), and Python is interpreted. Also, I learnt that for that reason C is ---generally speaking--- faster than Pyhton, when we talk about creating complex algorithms and so on.
There are different versions of Python, all of them stable and up-to-date! I mean, there is Python 2.x, and Python 3.x. And there are things that work in version 3 but not in version 2, etc.
Maybe this is even more subjective than the previous reasons, but I find more, better and more stable or reliable libraries in C than in Python.
Also, I found it a bit difficult to choose between different GUIs for Python programming and different flavors, as Python IDE, Tkinter, IronPython...
I do think that Python is a powerful language despite being interpreted. And also I still think it is more beautiful than C. I like Python, but I would like that I liked more!
So, finally, my question is, how can I truly learn and master Python, in a sure way, so that I am able to use it as my main choice for programming mathematical algorithms?
When I say "sure", I mean, which are (in your opinion) the safest path and tools for learning and using Python in a reliable way?, which are the more mature and stable libraries, GUIs, and so on?
Sorry if this question is a little bit strange, but I guess there could be more people with the same kind of doubts about Python as me.

Python: Programming 8051 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Can I program 8051 using Python?
I'm not getting any of the to program 8051 in python environment.
If anybody knows, please help me.
There is Python-on-a-Chip, but note its "disclaimer":
"The PyMite VM DOES NOT HAVE:
A built-in compiler
Any of Python's libraries (no batteries included)
A ready-to-go solution for the beginner (you need to know C and how to work with microcontrollers)"
Thus, if the questioner's goal for python was to avoid dealing with the strangeness of the 8051, this may not help.
In particular, the 8051 is a "Harvard" style architecture, with separate RAM and ROM codespaces, and with very limited internal RAM, and larger external RAM that can be accessed only via loading the special DPTR register and then reading or writing indirectly, plus there's no external RAM stack support, nor intrinsic support for stack-based variables. Thus, most "general purpose" high-level languages need lots of customization and reworking to run on the 8051.
A good 8051-specific C-compiler can hide many of these low-level details, but you wind up burning lots of cycles to do things that are single instructions on desktop CPUs and even on most newer embedded controller architectures, and even if you can live with that level of in-efficiency, you still need to sort out the various memory spaces and other specifics.
So, getting Python to work on the 8051 is likely to be a challenging project for someone deeply familiar with its quirky architecture. If your goal is to dump a python onto the 8051 to avoid needing to learn these quirks, I'm not sure that is possible. (But, I suppose the C compilers keep getting better and better...)
Python-on-a-Chip looks about as close as you're going to get. It can run on some things that are just a bit beefier than the 8051.

Where can I learn more about PyPy's translation function? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I've been having a hard time trying to understand PyPy's translation. It looks like something absolutely revolutionary from simply reading the description, however I'm hard-pressed to find good documentation on actually translating a real world piece of code to something such as LLVM. Does such a thing exist? The official PyPy documentation on it just skims over the functionality, rather than providing anything I can try out myself.
This document seems to go into quite a bit of detail (and I think a complete description is out of scope for a stackoverflow answer):
http://codespeak.net/pypy/dist/pypy/doc/translation.html
The general idea of translating from one language to another isn't particularly revolutionary, but it has only recently been gaining popularity / applicability in "real-world" applications. GWT does this with Java (generating Javascript) and there is a library for translating Haskell into various other languages as well (called YHC)
If you want some hand-on examples, PyPy's Getting Started document has a section titled "Trying out the translator".
PyPy translator is in general, not intended for more public use. We use it for translating
our own python interpreter (including JIT and GCs, both written in RPython, this restricted
subset of Python). The idea is that with good JIT and GC, you'll be able to speedups even
without knowing or using PyPy's translation toolchain (and more importantly, without
restricting yourself to RPython).
Cheers,
fijal
Are you looking for Python specific translation, or just the general "how do you compile some code to bytecode"? If the latter is your case, check the LLVM tutorial. I especially find chapter two, which teaches you to write a compiler for your own language, interesting.
It looks like something absolutely revolutionary from simply reading the description,
As far as I know, PyPy is novel in the sense that it is the first system expressly designed for implementing languages. Other tools exist to help with much of the very front end, such as parser generators, or for the very back end, such as code generation, but not much existed for connecting the two.

Categories

Resources