Writing an interpreter for language similar to python!!

Discussion in 'Python' started by luvsat, Feb 28, 2007.

  1. luvsat

    luvsat Guest

    Hello all,

    I am new to python and working on a project that involves designing a
    new language. The grammar of the language is very much inspired from
    python as in is supports nearly all the statements and expressions
    that are supported by python. Since my project is in initial stage, so
    I think it would be appropriate if I clarify the following questions:

    1. Would it make sense if I parse the whole program from scratch and
    then construct the valid python strings back so that they can be
    executed using ''exec'' and ''eval'' commands?
    2. Recently, I came across PLY (Python-Lex-Yacc) module that can be
    used to implement interpreters. It seems quite friendly to work with.
    Is there any implementation of python interpreter using ply? Any such
    reference would be extermely helpful for me to continue.

    Any kind of suggestions/ comments would be highly appreciated.

    Thanks,
    Luvish Satija
     
    luvsat, Feb 28, 2007
    #1
    1. Advertising

  2. "luvsat" <> wrote:


    > Hello all,
    >
    > I am new to python and working on a project that involves designing a
    > new language. The grammar of the language is very much inspired from
    > python as in is supports nearly all the statements and expressions
    > that are supported by python.


    8<-----------------------------

    This post begs the following questions:

    - Why make a new language, when
    - It is going to be an inferior subset of Python -
    - What can the motivation be to do this instead of contributing to the python
    effort?

    Dont forget about GNU Bison, if you persist...

    - Hendrik
     
    Hendrik van Rooyen, Mar 1, 2007
    #2
    1. Advertising

  3. luvsat

    greg Guest

    Hendrik van Rooyen wrote:

    > - It is going to be an inferior subset of Python -


    From what the OP said, it isn't necessarily a subset of
    Python, just something whose surface syntax is similar.
    The semantics could be quite different.

    However, if the semantics *are* to be similar as well,
    it makes a lot of sense to consider whether Python itself
    could be used.

    --
    Greg
     
    greg, Mar 1, 2007
    #3
  4. > I am new to python and working on a project that involves designing a
    > new language. The grammar of the language is very much inspired from
    > python as in is supports nearly all the statements and expressions
    > that are supported by python. Since my project is in initial stage, so
    > I think it would be appropriate if I clarify the following questions:
    >
    > 1. Would it make sense if I parse the whole program from scratch and
    > then construct the valid python strings back so that they can be
    > executed using ''exec'' and ''eval'' commands?
    > 2. Recently, I came across PLY (Python-Lex-Yacc) module that can be
    > used to implement interpreters. It seems quite friendly to work with.
    > Is there any implementation of python interpreter using ply? Any such
    > reference would be extermely helpful for me to continue.
    >
    > Any kind of suggestions/ comments would be highly appreciated.



    You might want to look at the pypy project:

    http://codespeak.net/pypy/dist/pypy/doc/news.html

    A javascript interpreter has already been written using pypy:

    http://codespeak.net/svn/user/santagada/javascript_interpreter_sop.txt
     
    Daniel Nogradi, Mar 2, 2007
    #4
  5. luvsat

    Paul Boddie Guest

    On 28 Feb, 18:38, "luvsat" <> wrote:
    >
    > I am new to python and working on a project that involves designing a
    > new language. The grammar of the language is very much inspired from
    > python as in is supports nearly all the statements and expressions
    > that are supported by python. Since my project is in initial stage, so
    > I think it would be appropriate if I clarify the following questions:


    Sounds interesting!

    > 1. Would it make sense if I parse the whole program from scratch and
    > then construct the valid python strings back so that they can be
    > executed using ''exec'' and ''eval'' commands?


    I wouldn't bother parsing the program from scratch - there's a module
    called "compiler" in the standard library which will give you an
    abstract syntax tree for virtually all of the syntax supported by the
    version of Python you're using. Despite complaints about the API, it's
    quite easy to work with and will save you from dealing with the
    tedious details of actually parsing the source code. If you want to
    produce the source code from the AST, some people have written visitor
    classes which will probably do what you want.

    Paul
     
    Paul Boddie, Mar 2, 2007
    #5
  6. luvsat

    Jim Guest

    On Mar 1, 1:16 am, "Hendrik van Rooyen" <> wrote:
    > This post begs the following questions:
    >
    > - Why make a new language, when
    > - It is going to be an inferior subset of Python -
    > - What can the motivation be to do this instead of contributing to the python
    > effort?

    Perhaps the OP only wants to learn something about compilers or
    parsing, or something like that?

    Jim
     
    Jim, Mar 2, 2007
    #6
    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. eyalkz
    Replies:
    3
    Views:
    5,162
    Alexei Cioina
    Oct 29, 2003
  2. Replies:
    3
    Views:
    764
    Ziga Seilnacht
    Jan 3, 2007
  3. Shravani
    Replies:
    8
    Views:
    803
    Bartc
    Mar 16, 2008
  4. Edgard Riba
    Replies:
    1
    Views:
    94
    Ross Bamford
    Feb 1, 2006
  5. jkn
    Replies:
    8
    Views:
    159
    Chris Angelico
    Jan 13, 2013
Loading...

Share This Page