473,799 Members | 3,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BASIC advice wanted.

After some days' hard work I am now the proud possessor of an ANSI C BASIC
interpreter.

The question is, how is it most useful?

At the moment I have a function

int basic(const char *script, FILE *in, FILE *out, FILE *err);

It returns 0 on success or -1 on fail.
and I'm calling it with stdin, stdout and stderr (err is for reporting
errors in the script, not for user errors).

This is fine for test purposes, but realistically it is not going to be
useful for anything beyond teaching newbies how to program in BASIC.

The main motive is to use the BASIC interpreter as a component of editors.
The idea is that a game designer can write a little BASIC program, maybe to
control the diffusion pattern of smoke particles, or maybe for some
AI-related stuff. Since the script is interpreted there is no reason to
recompile.

However setting up temporary files to pass data in and out of the BASIC
seems clumsy. There is also no way in C to specify a "user" FILE *,
something that pops up a Window to get input, for example.

I'm also not happy with the BASIC INPUT statement, it's fine for stdin, but
not so good for reading values from a typical formatted text file. However I
don't want to stray too far from core BASIC, or else the user will have to
learn a new programming language to use the program.
Nov 14 '05 #1
9 2242
"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote in message
news:bt******** **@news8.svr.po l.co.uk...
After some days' hard work I am now the proud possessor of an ANSI C BASIC
interpreter.
I doubt it. How do you deal with things like PEEK, POKE, PLOT and all the
other graphics or sound commands in ANSI C?
The question is, how is it most useful?


No, the question is, what is your C question? ;-)

Peter
Nov 14 '05 #2
Peter Pichler <pi*****@pobox. sk> scribbled the following:
"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote in message
news:bt******** **@news8.svr.po l.co.uk...
After some days' hard work I am now the proud possessor of an ANSI C BASIC
interpreter.
I doubt it. How do you deal with things like PEEK, POKE, PLOT and all the
other graphics or sound commands in ANSI C?


Perhaps his interpreter interprets a BASIC version which doesn't have
them? ANSI BASIC is incredibly small. It's even smaller than C=64 BASIC
V2.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The question of copying music from the Internet is like a two-barreled sword."
- Finnish rap artist Ezkimo
Nov 14 '05 #3
"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote:

ANSI BASIC is incredibly small.


ANSI BASIC? One learns something new every day!
Nov 14 '05 #4
Peter Pichler <pi*****@pobox. sk> scribbled the following:
"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote:
ANSI BASIC is incredibly small.
ANSI BASIC? One learns something new every day!


Yes. I didn't know about it either until Dan Pop told me. Apparently
it's even missing the IF... THEN structure. The only thing ANSI BASIC
can do in an IF statement is a GOTO. Several other BASIC dialects allow
calling other statements too.
(Though I would be surprised if this was valid BASIC:)

10 FOR I=1 TO 10
20 IF I<9 THEN NEXT I

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"As a boy, I often dreamed of being a baseball, but now we must go forward, not
backward, upward, not forward, and always whirling, whirling towards freedom!"
- Kang
Nov 14 '05 #5
Joona I Palaste <pa*****@cc.hel sinki.fi> scribbled the following:
Peter Pichler <pi*****@pobox. sk> scribbled the following:
"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote:
ANSI BASIC is incredibly small.
ANSI BASIC? One learns something new every day!
Yes. I didn't know about it either until Dan Pop told me. Apparently
it's even missing the IF... THEN structure. The only thing ANSI BASIC
can do in an IF statement is a GOTO. Several other BASIC dialects allow
calling other statements too.
(Though I would be surprised if this was valid BASIC:) 10 FOR I=1 TO 10
20 IF I<9 THEN NEXT I


Well, C=64 BASIC V2 seems to accept it... it's treating "NEXT I" as
"increment I and go back to the FOR command". So therefore the above
is equivalent to:

10 FOR I=1 TO 10
20 IF NOT(I<9) THEN END
30 NEXT I

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
Nov 14 '05 #6

"Peter Pichler" <pi*****@pobox. sk> wrote in message
After some days' hard work I am now the proud possessor of an
ANSI C BASIC interpreter.
I doubt it. How do you deal with things like PEEK, POKE, PLOT
and all the other graphics or sound commands in ANSI C?

It's a cut down BASIC without any hardware-specific commands.
The question is, how is it most useful?


No, the question is, what is your C question? ;-)

That's the C question. Given that I've got a BASIC interpreter, what is the
most useful interface to the rest of the C program that calls it?
Nov 14 '05 #7
Malcolm <ma*****@55bank .freeserve.co.u k> scribbled the following:
"Peter Pichler" <pi*****@pobox. sk> wrote in message
No, the question is, what is your C question? ;-)

That's the C question. Given that I've got a BASIC interpreter, what is the
most useful interface to the rest of the C program that calls it?


Your BASIC interpreter is written in ANSI C, but is your program around
it also written in ANSI C? If not, then you can use a non-standard "pipe
stream" and pass it as an argument to your interpreting function. That
way you can send data between your outer program and your interpreter
efficiently.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"That's no raisin - it's an ALIEN!"
- Tourist in MTV's Oddities
Nov 14 '05 #8
On Sun, 04 Jan 2004 10:43:19 +0000, Joona I Palaste wrote:
Malcolm <ma*****@55bank .freeserve.co.u k> scribbled the following:

Given that I've got a BASIC interpreter, what is the
most useful interface to the rest of the C program that calls it?


Your BASIC interpreter is written in ANSI C, but is your program around
it also written in ANSI C? If not, then you can use a non-standard "pipe
stream" and pass it as an argument to your interpreting function. That
way you can send data between your outer program and your interpreter
efficiently.


How about callback functions? Something like:

typedef int (*input_handler )(char**);
typedef int (*output_handle r)(const char*);
typedef int (*error_handler )(int,int,char* ); /* errno, line, text */

int basic(const char *script,
input_handler ih,
output_handler oh,
error_handler eh);

Giving the calling program the opportunity to define functions to deal
with input, output or errors. These programs may then write to file or
process the error or do whatever they feel like.

(And you can provide handler functions that writes to files if that's
what the user wants them to do.)
--
NPV

"the large print giveth, and the small print taketh away"
Tom Waits - Step right up

Nov 14 '05 #9
Nils Petter Vaskinn <no@spam.for.me .invalid> scribbled the following:
On Sun, 04 Jan 2004 10:43:19 +0000, Joona I Palaste wrote:
Malcolm <ma*****@55bank .freeserve.co.u k> scribbled the following:
Given that I've got a BASIC interpreter, what is the
most useful interface to the rest of the C program that calls it?
Your BASIC interpreter is written in ANSI C, but is your program around
it also written in ANSI C? If not, then you can use a non-standard "pipe
stream" and pass it as an argument to your interpreting function. That
way you can send data between your outer program and your interpreter
efficiently.

How about callback functions? Something like: typedef int (*input_handler )(char**);
typedef int (*output_handle r)(const char*);
typedef int (*error_handler )(int,int,char* ); /* errno, line, text */ int basic(const char *script,
input_handler ih,
output_handler oh,
error_handler eh); Giving the calling program the opportunity to define functions to deal
with input, output or errors. These programs may then write to file or
process the error or do whatever they feel like. (And you can provide handler functions that writes to files if that's
what the user wants them to do.)


I think this design is good. If this were Java, I'd design the BASIC
interpreter so that I/O is handled by calling interfaces, one called
Input, the other called Output. Implementors of the outside system
would have to implement these interfaces and pass the implementations
as parameters to the interpreter object.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It's not survival of the fattest, it's survival of the fittest."
- Ludvig von Drake
Nov 14 '05 #10

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

Similar topics

75
6199
by: Howard Nease | last post by:
Hello, everyone. I would appreciate any advice that someone could give me on my future career path. Here is my situation: I am a bright Junior in a very well-respected private high school, taking almost all AP and accelerated classes. I am HIGHLY interested in technology, more specifically the field of Computer Science and software engineering. I have heard a whole lot about the fact that the market for software engineers nowadays is...
8
1653
by: JotM | last post by:
Hi all, I am currently fooling around trying to produce a very basic webpage that can be shown on both computer screens and Nokia series 60 GSM cell phones featuring an XHTML browser. (XHTML-MP | XHTML Mobile Profile) I found XHTML-MP to be the W3C XHTML-Basic + WML extensions, that is why I have chosen to base a web page on XHTML Basic 1.0 Doing that I am running into the following problem: Nokia phones do not support the media...
0
279
by: Mark Stokes | last post by:
Hi there, I wanted a bit of advice on a program (a prototype) that I am trying to write that uses threads. I will outline what I am attempting to do, and if anyone has any advice on the way I am trying to work I would be most grateful. I am writing a windows forms application. This application defines a class, lets call this myObject. I instanciate objects of this class and store the myObjects in an ArrayList.
2
3185
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the problems that I have encountered to date and the solutions (if any) that I found. http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm This page also has all of the source code in a compressed file that you are free to download...
1
1826
by: john_20_28_2000 | last post by:
Using asp.net, c#, mysql or SQL Server. I have a image uploading and wanted it to be "secure." Each user has their own section to login and upload images. Should I store the images in a database or on the drive as files? Not sure how to make it secure any other way but put in the database, but wanted to know if that would make it extremely slow when downloading the images on the webpage showing them. Thanks for any advice.
0
901
by: Alex Pavluck | last post by:
Hello. I have always wanted to learn how to write programs as a hobby and Visual Basic 2005 Express seems like the perfect platform. Can someone who is more experience let me know if this is a good language to learn with and also let me know if this product will be cost prohibitive once it is out of beta. Thanks, Alex
6
4751
by: BJMurphy | last post by:
Hi All, I am used to other SQL engines, and have a few basic questions-- 1)If I wanted to conditionally drop a table, does SQL Server have a way to natively do this? Many SQL implementations will allow something like: CREATE OR REPLACE tablename AS SELECT
6
3147
by: Simon Walsh | last post by:
I'm an Electronics student in college and I'm currently working on a project. I was given a circuit diagram for my project, from which I had to design a printed circuit board to be sent off and manufactured. I got my printed circuit board back and populated it with components. On my circuit board, I have a chip holder for a Basic STAMP microcontroller. To those unfamiliar with it, the Basic STAMP is a microcontroller which has an onboard...
16
1839
by: Ark Khasin | last post by:
I have a memory-mapped peripheral with a mapping like, say, struct T {uint8_t read, write, status, forkicks;}; If I slap a volatile on an object of type struct T, does it guarantee that all accesses to the members are byte-wide, or is the compiler free to read or read-modify-write in any data width it chooses? Is slapping a volatile on each member of the struct definition any different? better? worse?
0
9541
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
10484
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
10251
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...
0
10027
tracyyun
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...
1
7565
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
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
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...
1
4141
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
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.