Changing the names of python keywords and functions

V

vedrandekovic

Hello,

I am trying to make a program for 3D modelling with "programming".And
I want make my own program commands,

for example when user type code in my program:

"<<koristiti>> OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),

my program must write this code in some user file, but my

program must read this command like: "import os".How

can I do something like that??

Please, HELP ME somebody!!!
 
M

moegoldberg

I'm not quite clear on what you are asking, but
you can use the __import__() function to import modules by name.
 
V

vedrandekovic

(e-mail address removed) je napisao/la:
I'm not quite clear on what you are asking, but
you can use the __import__() function to import modules by name.


I want to invent something like my "programming language" like Python
with the same keywords just changed,
for example if user type in my "programming language":

This line of code my program must write in some file, and my program
(when it run this user file) must read this
line of code like:
 
?

=?ISO-8859-2?Q?=22Martin_v=2E_L=F6wis=22?=

"<<koristiti>> OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),

my program must write this code in some user file, but my

program must read this command like: "import os".How

can I do something like that??

The keywords are listed in Grammar/Grammar. You need to edit
this file, then recompile.

Regards,
Martin
 
B

Ben Finney

Martin v. Löwis said:
The keywords are listed in Grammar/Grammar. You need to edit
this file, then recompile.

To clarify, are you suggesting changing the source code of the Python
implementation and recompiling it?

If the keywords are changed in the Python executable, won't that break
the import of any Python module written for the standard keywords --
such as many of those in the standard library?

My understanding of the original poster's requirement was that the
keywords should be additional to, not replacement for, the existing
Python keywords.
 
G

Guest

To clarify, are you suggesting changing the source code of the Python
implementation and recompiling it?
Correct.

If the keywords are changed in the Python executable, won't that break
the import of any Python module written for the standard keywords --
such as many of those in the standard library?

Most certainly, yes.
My understanding of the original poster's requirement was that the
keywords should be additional to, not replacement for, the existing
Python keywords.

So he should make them additional in the grammar, too.

It is entirely beyond me *why* the OP wants to do that, but changing
the compiler would be the proper way of implementing that change.

Regards,
Martin
 
S

Stargaming

Hello,

I am trying to make a program for 3D modelling with "programming".And
I want make my own program commands,

for example when user type code in my program:

"<<koristiti>> OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),

my program must write this code in some user file, but my

program must read this command like: "import os".How

can I do something like that??

Please, HELP ME somebody!!!

Besides your request is sorta weird (languages are mostly meant to give
a ruleset of expressions, not a framework of mutability, at least the
more widespread ones), Python does not support something like this out
of the box. There have been several discussions about such features and
they were all abandoned due to unification.

You can, of course, follow the "normal" track to implement any language
and write a parser, lexer, compiler and whatever. Tools like
`pyparsing`_ or `PLY`_ might help you (there are much more).
Though, there *is* a mutable codeset of Python called `Logix`_. As far
as I glanced at it, it is pretty mutable and might fit your needs perfectly.

Ah, and if you perhaps remove the leading << there, this might be pretty
much implementable by overloading __rshift__ at your koristiti object.

HTH,
Stargaming

... _pyparsing: http://pyparsing.wikispaces.com/
... _PLY: http://www.dabeaz.com/ply/ply.html
... _Logix: http://livelogix.net/logix/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top