473,230 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

simple lisp interpreter help needed

Hello,
I am a CS student and I want to write simple lisp interpreter. The code
should be entierly in C. I don't want to use any compiler generators like
Bison or Yak, since wrinting this in raw C will give me more experience. I
wrote a simple lexer ( changes leksems into the streams of tokens). The Lisp
dialect I have to implement is not defined in any formal way, but I have a
description of how it should behave (say its a >>writen halformal
description which leads me to confusion <<). I ask for some tips, materials
or guidence. Oh and it should use some garbage collector, but I think this
should be implemented in the end. I suppose I need to define data
structures in a clear way. I don't give a description of that machine lisp
abstraction, since all are similar. The fragment of the descripion is this :
(...)Program in Ansi C an interpreter of Lisp dialect described above. It
should contain efective implementation of the associate list, agregeting
atoms linked with values by the pseudofunction define and using some simple
garbage collector algorithm (the cell is alive, if it is possilble to reach
it starting from the atom belonging to the association list. The symbolic
data constructed during interpreter run should be put in array dyn_mem
define for example like this:

================================================== ====================

#define MEMSIZE 1024
struct cell {
union data *left, *right;
};
union data {
int atom; /* when MSB == 1 */
struct cell *next; /* when MSB == 0 */
};
struct cell dyn_mem[MEMSIZE];

================================================== ====================

Notice that this structure doesn't have MSB, to add in the orginal MacArthy
lisp it was the redundant part of data register ( 36 -th bit or something),
suppose this trick wouldn't go by on a 386 .....
Aug 24 '07 #1
4 2089
On Fri, 24 Aug 2007 16:16:51 +0200, "Thomas" <ar*****@o2.plwrote in
comp.lang.c:
Hello,
I am a CS student and I want to write simple lisp interpreter. The code
should be entierly in C. I don't want to use any compiler generators like
Bison or Yak, since wrinting this in raw C will give me more experience. I
wrote a simple lexer ( changes leksems into the streams of tokens). The Lisp
dialect I have to implement is not defined in any formal way, but I have a
description of how it should behave (say its a >>writen halformal
description which leads me to confusion <<). I ask for some tips, materials
or guidence. Oh and it should use some garbage collector, but I think this
should be implemented in the end. I suppose I need to define data
structures in a clear way. I don't give a description of that machine lisp
abstraction, since all are similar. The fragment of the descripion is this :
(...)Program in Ansi C an interpreter of Lisp dialect described above. It
should contain efective implementation of the associate list, agregeting
atoms linked with values by the pseudofunction define and using some simple
garbage collector algorithm (the cell is alive, if it is possilble to reach
it starting from the atom belonging to the association list. The symbolic
data constructed during interpreter run should be put in array dyn_mem
define for example like this:

================================================== ====================

#define MEMSIZE 1024
struct cell {
union data *left, *right;
};
union data {
int atom; /* when MSB == 1 */
struct cell *next; /* when MSB == 0 */
};
struct cell dyn_mem[MEMSIZE];

================================================== ====================

Notice that this structure doesn't have MSB, to add in the orginal MacArthy
lisp it was the redundant part of data register ( 36 -th bit or something),
suppose this trick wouldn't go by on a 386 .....
I don't understand what your C question is, if indeed you have one.

The common method to implement a union which might hold two different
types at different times, the type to be determined at run-time when
it is accessed, is usually something like this:

enum { is_ptr, is_atom } cell_type;

union cell_data { int atom; struct cell *next; };

struct cell { enum cell_type type; union cell_data data; };

Then when accessing a cell, the code first reads the type member to
determine which member of the data union is present.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Aug 24 '07 #2
Jack Klein <ja*******@spamcop.netwrites:
[...]
enum { is_ptr, is_atom } cell_type;
This declares a single object of an anonymous enum type. You want:

enum cell_type { is_ptr, is_atom };
union cell_data { int atom; struct cell *next; };

struct cell { enum cell_type type; union cell_data data; };
[...]

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 24 '07 #3

Uzytkownik "Jack Klein" <ja*******@spamcop.netnapisal w wiadomosci
news:7n********************************@4ax.com...
On Fri, 24 Aug 2007 16:16:51 +0200, "Thomas" <ar*****@o2.plwrote in
comp.lang.c:
Hello,
I am a CS student and I want to write simple lisp interpreter. The
code
should be entierly in C. I don't want to use any compiler generators
like
Bison or Yak, since wrinting this in raw C will give me more experience.
I
wrote a simple lexer ( changes leksems into the streams of tokens). The
Lisp
dialect I have to implement is not defined in any formal way, but I have
a
description of how it should behave (say its a >>writen halformal
description which leads me to confusion <<). I ask for some tips,
materials
or guidence. Oh and it should use some garbage collector, but I think
this
should be implemented in the end. I suppose I need to define data
structures in a clear way. I don't give a description of that machine
lisp
abstraction, since all are similar. The fragment of the descripion is
this :


(...)Program in Ansi C an interpreter of Lisp dialect described above.
It
should contain efective implementation of the associate list, agregeting
atoms linked with values by the pseudofunction define and using some
simple
garbage collector algorithm (the cell is alive, if it is possilble to
reach
it starting from the atom belonging to the association list. The
symbolic
data constructed during interpreter run should be put in array dyn_mem
define for example like this:

================================================== ====================

#define MEMSIZE 1024
struct cell {
union data *left, *right;
};
union data {
int atom; /* when MSB == 1 */
struct cell *next; /* when MSB == 0 */
};
struct cell dyn_mem[MEMSIZE];

================================================== ====================

Notice that this structure doesn't have MSB, to add in the orginal
MacArthy
lisp it was the redundant part of data register ( 36 -th bit or
something),
suppose this trick wouldn't go by on a 386 .....

I don't understand what your C question is, if indeed you have one.

The common method to implement a union which might hold two different
types at different times, the type to be determined at run-time when
it is accessed, is usually something like this:

enum { is_ptr, is_atom } cell_type;

union cell_data { int atom; struct cell *next; };

struct cell { enum cell_type type; union cell_data data; };

Then when accessing a cell, the code first reads the type member to
determine which member of the data union is present.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Ok, thanks that makes sense. Well, maybe my C question is not well defined,
but I have not found any better places for this post.
Aug 24 '07 #4
On Fri, 24 Aug 2007 12:06:37 -0700, Keith Thompson <ks***@mib.org>
wrote in comp.lang.c:
Jack Klein <ja*******@spamcop.netwrites:
[...]
enum { is_ptr, is_atom } cell_type;

This declares a single object of an anonymous enum type. You want:

enum cell_type { is_ptr, is_atom };
union cell_data { int atom; struct cell *next; };

struct cell { enum cell_type type; union cell_data data; };
[...]
Yes of course, thanks.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Aug 25 '07 #5

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
2
by: Gregory S Moy | last post by:
I'm looking for SQL code to do the following. TableA GrpID,IndID,Locked 50001,10001,0 50001,10002,0 50002,10003,0 50002,10004,1
1
by: Ramza Brown | last post by:
Crazy, I know, but that is my question. Even google let me down: Anybody know of a lisp interpreter in php? And, I tried c.l.l. No dice. Even something similar. If you have worked with...
5
by: emanuel.levy | last post by:
I have a table called tbl_employers. One of the fields is start_date. I'm trying to make a query that will show all entries where todays date is 275 days and 305 days after the start date. Any...
0
by: hOSAM | last post by:
Hi, I would like to make my application's configuration very customizable. So I thought it would be suitable to make a configuration file where I could specify command execution steps. for...
2
by: Toby | last post by:
I'm trying to write a simple commandline wrapper: a script that runs another program as a child and relays unbuffered stdin and stdout to/from the child process, possibly filtering it. The...
5
by: Joel | last post by:
In the course of my project, I must include some custom logic and would like to integrate a small script language in my application for that purpose. In C++, I used the LUA script language and I...
1
by: Bambers | last post by:
hi all i have an contact us form with validation. the submit button make the script re-run and do the validation. the problem i have is; when all the validation is done and the user input is...
4
by: bhanab | last post by:
Please can you help me with syntax? I have two table t1 and t2, T1 id Des 1 Door 2 Book T2
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.