473,657 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing an interpreter for language similar to python!!

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

Feb 28 '07 #1
5 1836
"luvsat" <lu*****@gmail. comwrote:

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


Mar 1 '07 #2
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
Mar 1 '07 #3
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/santag...preter_sop.txt
Mar 2 '07 #4
On 28 Feb, 18:38, "luvsat" <luv....@gmail. comwrote:
>
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

Mar 2 '07 #5
Jim
On Mar 1, 1:16 am, "Hendrik van Rooyen" <m...@microcorp .co.zawrote:
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

Mar 2 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1616
by: Gabriele Farina | last post by:
I guys I planned to create a new programming language to use to develop web applications for my company. I'd like to develop it using Python, but I don't know if python is fast enaught. Someone could help me and give me some ideas?
13
1745
by: Alejandro Lombardo | last post by:
Dear sirs: I need to create a programming language. Can this be done with the latest version of python? Is python the best computer programming language development tool in the entire universe? If it isn´t could you please tell me the name of the best computer programming language development tool in the entire universe? So that I can download it from the Internet for free? I would apreciate it if you could answer these questions as soon...
4
4315
by: Daniel Cloutier | last post by:
Hi, is it possible to edit or write Word-files out of a Python-Program? thx in advance daniel
29
2131
by: Steven Bethard | last post by:
Fuzzyman wrote: > Cameron Laird wrote: > > >>This is a serious issue. >> >>It's also one that brings Tcl, mentioned several >>times in this thread, back into focus. Tcl presents >>the notion of "safe interpreter", that is, a sub- >>ordinate virtual machine which can interpret only
4
1855
by: WX | last post by:
I love Python, and the unicode support is wonderful. The character set I am using is the Hindi/Devanagari character set at unicode range U+901.) I have TWO newbie questions: (#1) If I paste some unicode stuff from the clipboard into IDLE, it accepts it, but it can't execute a PRINT command like this:
8
1786
by: Aziz McTang | last post by:
Hi Group, I am not an experienced programmer at all. I've learned html and css well enough to hand-write simple websites. I'm now looking to move to the next step. Initially, I'd like to do 3 things: 1) Generate web pages This one's fairly obvious maybe. 2) Create a simplified translation package specific to my line of work:
19
1663
by: Vincent Delporte | last post by:
Hello I'm thinking of using Python to build the prototype for a business web appplication. The development and test machine is XP, while ultimate deployment will be on a shared Unix web host. What would you recommend I get, besides the Python engine itself? Good IDE (Kodomo?) ? Some kind of GUI designer? Add-on's? Other tools? Thank you.
2
1194
by: psychofish25 | last post by:
It's been about 2 hours since I started writing code for a programming language I made in python called XSSIV (excessive). Anyway the code can be found at psychofish25.freewebspace.com/xssiv.py The language works similarly to the Python Interactive Window, except >>> is replaced with =>. So far there are only 7 commands, 2 of which I have not programmed. They are explained as so... Help -Not listed yet Commands -Not listed yet
3
1879
by: R. Bernstein | last post by:
The next release of pydb will have the ability to go into ipython from inside the debugger. Sort of like how in ruby-debug you can go into irb :-) For ipython, this can be done pretty simply; there is an IPShellEmbed method which returns something you can call. But how could one do the same for the stock python interactive shell? To take this out of the realm of debugging. What you want to do is to write a python program that goes...
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.