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 ..... 4 2110
On Fri, 24 Aug 2007 16:16:51 +0200, "Thomas" <ar*****@o2.plw rote 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.l earn.c-c++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jack Klein <ja*******@spam cop.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_Keit h) 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"
Uzytkownik "Jack Klein" <ja*******@spam cop.netnapisal w wiadomosci
news:7n******** *************** *********@4ax.c om...
On Fri, 24 Aug 2007 16:16:51 +0200, "Thomas" <ar*****@o2.plw rote 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.l earn.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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. Yahoo store was originally written in Lisp.
c. Emacs
The issues with these will probably come up, so I might as well
mention them myself (which will also make this a more balanced
|
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
|
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 lisp, you know what I am talking about. Something to handle
symbols, tags, keywords for example.
--
|
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 help would be appreciated
|
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 example, when user clicks on the command "Get Amount", the program looks
up the configuration file to find that this command maps to a custom script
that could look like:
| |
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 usefulness of such a program lies in the filtering stage, in a
possible integration with readline, or in other interface enhancements.
Still, I'd like to discuss with you the unfiltered, unembellished
version, because I'm not satisfied with it and...
|
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 know that bindings exists
for a LUA/c# integration, but only using the binary DLL.
However, I would prefer a native c# solution and for a small language,
not a huge interpreter like Python.
Has anybody seen such implementation ?
Thanks,
|
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 correct, how do i make the brouser go to the next page.
i need it to pass vaiables into contact.php which sends the email
i cannot understand how to do it becuase the only form action i have is one that recalls itself.
any help would be great
|
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
|
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...
|
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...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |