Writing an interpreter for language similar to python!!

L

luvsat

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
 
H

Hendrik van Rooyen

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
 
G

greg

Hendrik said:
- 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.
 
D

Daniel Nogradi

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
 
P

Paul Boddie

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
 
J

Jim

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
 

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