Changing the names of python keywords and functions

Discussion in 'Python' started by vedrandekovic@v-programs.com, Jun 21, 2007.

  1. Guest

    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!!!
    , Jun 21, 2007
    #1
    1. Advertising

  2. Guest

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

    On Jun 21, 3:07 pm, wrote:
    > 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!!!
    , Jun 21, 2007
    #2
    1. Advertising

  3. Guest

    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":

    >>> koristiti os


    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:

    >>> import os (I just want to change names of keywords)
    , Jun 21, 2007
    #3

  4. > "<<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
    =?ISO-8859-2?Q?=22Martin_v=2E_L=F6wis=22?=, Jun 21, 2007
    #4
  5. Ben Finney Guest

    "Martin v. Löwis" <> writes:

    > (unattributed author) wrote:
    > > "<<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.


    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.

    --
    \ "The way to build large Python applications is to componentize |
    `\ and loosely-couple the hell out of everything." -- Aahz |
    _o__) |
    Ben Finney
    Ben Finney, Jun 22, 2007
    #5
  6. >>> "<<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.

    >
    > 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
    =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=, Jun 22, 2007
    #6
  7. Stargaming Guest

    schrieb:
    > 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/
    Stargaming, Jun 22, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xiangliang Meng
    Replies:
    1
    Views:
    1,591
    Victor Bazarov
    Jun 21, 2004
  2. fBechmann
    Replies:
    0
    Views:
    399
    fBechmann
    Jun 10, 2004
  3. Andr? Roberge
    Replies:
    8
    Views:
    335
    Sridhar R
    Oct 9, 2004
  4. Replies:
    6
    Views:
    390
    Michael Hoffman
    Jul 2, 2007
  5. Simon Wigzell

    SQL Keywords and Field names

    Simon Wigzell, Jun 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    114
    Aaron [SQL Server MVP]
    Jun 10, 2004
Loading...

Share This Page