http://www.geocities.com/dunric/triple.html
Triple-Sec is a simple BASIC-like interpreter with 36 variables
and 8 non-dimensional strings. Here are the basic commands
used in Triple-Sec:
---------------------------------------------------------------
WRITE '<text>' (where <text> is up to 240 characters)
CLEAR (clears screen)
ADD x TO <variable> (add x to a variable: A-Z,Z0-Z9)
SUB x FROM <variable> (sub x from a variable: A-Z,Z0-Z9)
IF A=B THEN B=C (1-level IF command, like BASIC, but no ELSE)
JUMP x (like GOTO, where x is a line number)
INPKEY '<text>',var$ (get INPUT from var$: A-G$)
READ var$ (like READ in BASIC, from var$: A-G$)
@ '<text>',num,etc. (like DATA, using '@' instead)
GETKEY var$ (wait for keypress, from var$: A-G$)
MEM x (display available memory)
CLVAR (clear all variables of data)
RUN (or EXEC) (RUN the current program)
SAVE (SAVEs program; prompted for filename)
LOAD (LOADs program; prompted for filename)
LIST (LISTs program; Lines 1 through 9999)
BYE (or QUIT) (Exits Triple-Sec)
---------------------------------------------------------------
Limitations:
Triple-Sec is meant to be as 'BASIC' as possible. That is, it currently
only accepts 1 command per line, up to 9999 lines. A program cannot
exceed
9999 lines.
It also only allows 36 total variables (A through Z, plus Z0 through
Z9) and 8 total strings (A$ to G$, non-subscripted). Strings
cannot be subscripted, but variables can be (up to 255 elements, single
subscript).
Triple-Sec is being coded in PowerBASIC for DOS. If you'd like to help
me on this project, please e-mail me.
Program Examples:
Here is an example of a simple Triple-Sec program:
0: CLVAR
1: WRITE 'Hello World!'
2: A(1)=1.2:A$="Triple-Sec Version "
3: WRITE A$;A(1)
4: READ B$
5: @ 'This is the contents of variable B$'
6: READ C$
7: @ 'This is the contents of variable C$'
8: READ Z0
9: @ 25
10: WRITE B$
11: WRITE C$
12: WRITE 'The contents of variable Z0 is:';Z0
13: INPKEY 'Press the 'y' key to continue';D$
14: IF D$="y" OR D$="Y" THEN JUMP 17
15: WRITE 'Please enter 'y'...'
16: JUMP 13
17: ADD 1 TO Z0
18: WRITE 'Z0 is now: ';Z0
19: SUB 10 FROM Z0
20: WRITE 'Z0 is now: ';Z0
21: CLVAR
22: WRITE 'Variables cleared.'"
23: WRITE 'Memory is now: '
24: WRITE MEM x
25: WRITE 'Press any key to clear screen...'"
26: GETKEY E$
27: CLEAR
E-mail the author (Paul Panks, a/k/a "Dunric"):
If you'd like to help me with this project, also please e-mail me and
offer suggestions on how to code this interpreter, or other ideas.
Paul
You are joking aren't you?
> If you'd like to help me with this project, also please e-mail me and
> offer suggestions on how to code this interpreter, or other ideas.
You must be joking!!!!!!
You post this to two groups (comp.lang.functional and
comp.lang.scheme) full of people who would rather give
up programming that program in BASIC.
Then I see that you cross-posted it to alt.lang.basic
where your post is 100% on topic. This makes me wonder
if you even know what a functional programming language
is, but then if you knew what a functional programming
language is, you wouldn't be reading alt.lang.basic.
Anyway .....
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo nos...@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
The idea that Bill Gates has appeared like a knight in shining armour to
lead all customers out of a mire of technological chaos neatly ignores
the fact that it was he who, by peddling second-rate technology, led them
into it in the first place. - Douglas Adams in Guardian, 25-Aug-95
Paul
Not according to this:
http://en.wikipedia.org/wiki/Functional_programming
BASIC, in all its forms is an imperative programming language.
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo nos...@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
Linux: the only OS that makes you feel guilty when you reboot
-- Kenneth Crudup in comp.os.linux.misc
Uhm. Triple-sec. is that what you were drinking when you thought this
up?
The reply-to email address is olczy...@yahoo.com.
This is an address I ignore.
To reply via email, remove 2002 and change yahoo to
interaccess,
**
Thaddeus L. Olczyk, PhD
There is a difference between
*thinking* you know something,
and *knowing* you know something.
<dun...@yahoo.com> wrote in message
news:1118806403.8...@o13g2000cwo.googlegroups.com...
Or a couple of hours if you use a language designed to write compilers and
interpreters in, like ML.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com
Brent
... Or a couple of hours (not more) to write the parser and to make a
compiler which translates Triple-Sec to C++, using CodeWorker, a
parsing tool and a source code generator (http://www.codeworker.org).
Proof. Here is the translation of the example code to C++, done by the
compiler written in CodeWorker:
#include <process.h>
#include <conio.h> // Windows only (sorry!), for GETKEY
#include <iostream>
#include <string>
#include <vector>
int arrayIndex(std::vector<double>& array, unsigned int iIndex) {
if (array.size() < iIndex) array.resize(iIndex);
return iIndex - 1;
}
// the data declared into the program:
const char* tcData[] = {"This is the contents of variable B$", "This is
the contents of variable C$", "25"};
int iDataCursor = 0;
// this program uses 7 variables:
std::vector<double> A_arr; // variable 'A()'
std::string A_str; // variable 'A$'
std::string B_str; // variable 'B$'
std::string C_str; // variable 'C$'
double Z0 = 0.0; // variable 'Z0'
std::string D_str; // variable 'D$'
std::string E_str; // variable 'E$'
void CLVAR() {
A_arr.clear();
A_str = "";
B_str = "";
C_str = "";
Z0 = 0.0;
D_str = "";
E_str = "";
}
size_t usedMEM() {
size_t iUsedMEM = 0;
iUsedMEM += A_arr.size() * sizeof(double) +
sizeof(std::vector<double>);
iUsedMEM += A_str.size() + sizeof(std::string);
iUsedMEM += B_str.size() + sizeof(std::string);
iUsedMEM += C_str.size() + sizeof(std::string);
iUsedMEM += sizeof(double);
iUsedMEM += D_str.size() + sizeof(std::string);
iUsedMEM += E_str.size() + sizeof(std::string);
return iUsedMEM;
}
int main(int, char**) {
// The translation of the program to C++:
try {
CLVAR();
std::cout << "Hello World!" << std::endl;
A_arr[arrayIndex(A_arr, (unsigned int) 1)] = 1.2;
A_str = "Triple-Sec Version ";
std::cout << A_str << A_arr[arrayIndex(A_arr, (unsigned int) 1)] <<
std::endl;
if (iDataCursor >= 3) throw "All data are consumed; can't read them
anymore";
B_str = tcData[iDataCursor++];
if (iDataCursor >= 3) throw "All data are consumed; can't read them
anymore";
C_str = tcData[iDataCursor++];
if (iDataCursor >= 3) throw "All data are consumed; can't read them
anymore";
Z0 = atof(tcData[iDataCursor++]);
std::cout << B_str << std::endl;
std::cout << C_str << std::endl;
std::cout << "The contents of variable Z0 is: " << Z0 << std::endl;
line13:
std::cout << "Press the 'y' key to continue ";
std::cin >> D_str;
if (((D_str == "y") || (D_str == "Y"))) {
goto line17;
}
std::cout << "Please enter 'y'..." << std::endl;
goto line13;
line17:
Z0 += 1;
std::cout << "Z0 is now: " << Z0 << std::endl;
Z0 -= 10;
std::cout << "Z0 is now: " << Z0 << std::endl;
CLVAR();
std::cout << "Variables cleared." << std::endl;
std::cout << "Memory is now: " << std::endl;
std::cout << -1*((int) usedMEM())/*implementation of MEM is
platform-dependent: return the used memory as a negative number*/ <<
std::endl;
std::cout << "Press any key to clear screen..." << std::endl;
{
// Windows implementation of 'GETKEY'
int iKey;
for (;;) {
iKey = _getch();
if (iKey != 0 && iKey != 0xE0) break;
_getch();
}
E_str = std::string(1, (char) iKey);
}
std::cout << std::endl << std::endl << std::endl << std::endl <<
std::endl << std::endl << std::endl << std::endl << std::endl <<
std::endl << std::endl << std::endl << std::endl << std::endl <<
std::endl << std::endl << std::endl << std::endl << std::endl <<
std::endl << std::endl << std::endl << std::endl << std::endl <<
std::endl << std::endl << std::endl << std::endl << std::endl <<
std::endl << std::endl << std::endl << std::endl << std::endl <<
std::endl << std::endl << std::endl << std::endl << std::endl <<
std::endl;
} catch(const char* tcError) {
std::cout << tcError << std::endl;
return 1;
}
return 0;
}
[ deleted ]
> std::cout << std::endl << std::endl << std::endl << std::endl <<
> std::endl << std::endl << std::endl << std::endl << std::endl <<
> std::endl << std::endl << std::endl << std::endl << std::endl <<
> std::endl << std::endl << std::endl << std::endl << std::endl <<
> std::endl << std::endl << std::endl << std::endl << std::endl <<
> std::endl << std::endl << std::endl << std::endl << std::endl <<
> std::endl << std::endl << std::endl << std::endl << std::endl <<
> std::endl << std::endl << std::endl << std::endl << std::endl <<
> std::endl;
I must say, I'm truly impressed :)
Cheers,
D. Tenev
I'll say it's an interesting project for you and hope it is proving a
good exercise.
As a language it's far too restricted to be useful (compared to other
freebies) but i don't think it matters!
In time you may find comp.compilers or comp.lang.basic.misc a better
place to target your message
You could also look up the old Moonrock basic and BASM projects as
comprehensive tools for translating a reasonably useful BASIC variant
to assembly, or check out the occasional 'all new' BASIC compiler,
interpreter porject that comes along
> I must say, I'm truly impressed :)
Yes I know, It's very ugly! It intends to clear the screen! My lazyness
suggested me to write @repeatString(" << std::endl", 40)@ for
generating the statement, and I wasn't capable to resist.
It isn't the only piece of this code I'm ashamed of, but I wanted to
spend less than 2 hours.
You only have 40 lines?
$ echo $LINES
56
John
--
use Perl;
program
fulfillment
> $ echo $LINES
> 56
No 25, but if it's important for you, I'll think about adding 16
carriage returns more... or 200 if somebody else has more lines (screen
projected on a building wall for instance) and for keeping a margin.
Perhaps to serve demand:
-PB/DOS is a compiler.
-New Product is an interpreter.
MCM
> Maybe I'm alone on this, but I fail to see the point in creating a new
> BASIC-like dialect using another flavour of BASIC ....
Self-education. (The OP is obviously very green.)
**VERY***
I can't imagine a language more ill suited to writing a language
compiler or interpretter than BASIC.
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo nos...@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"The power of accurate observation is commonly called cynicism by those
who don't have it." -- George Bernard Shaw
<snip>
>I can't imagine a language more ill suited to writing a language
>compiler or interpretter than BASIC.
It's not all that hard, if you know BASIC well enough. BCET is
self-compiling. 2nd URL in Sig.
--
ArarghMail506 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html
To reply by email, remove the garbage from the reply address.
> Programmer Dude wrote:
> >
> > budgie writes:
> >
> > > Maybe I'm alone on this, but I fail to see the point in creating a new
> > > BASIC-like dialect using another flavour of BASIC ....
> >
> > Self-education. (The OP is obviously very green.)
>
> **VERY***
>
> I can't imagine a language more ill suited to writing a language
> compiler or interpretter than BASIC.
Thats not quite true! X11-Basic p.ex. is partially witten and compiled by
itself. This is a so called boot-strapping approach to writing new
interpreter/compilers.
regards
M.
> Programmer Dude wrote:
>>
>> budgie writes:
>>
>> > Maybe I'm alone on this, but I fail to see the point in creating a new
>> > BASIC-like dialect using another flavour of BASIC ....
>>
>> Self-education. (The OP is obviously very green.)
>
> **VERY***
>
> I can't imagine a language more ill suited to writing a language
> compiler or interpretter than BASIC.
Have you seen any of the modern BASIC dialects? No more line numbers,
procedures with local variables, more control structures than Pascal, the
best string handling outside the specialized text-processing languages like
SNOBOL, and a full set of bit-banging operators. Even QuickBasic was
powerful enough to let me translate the Turbo Pascal code in Jack
Crenshaw's "Let's Build a Compiler!" tutorial as I went along, and there
has been considerable development since then (but not at Microsoft).
Google FreeBasic for an up-to-date, cross-platform BASIC compiler that is
used to maintain itself.
'tis not so much different from the classic introductory
project in various lisps -- writing a lisp interpreter.
Bear
Actually, I know Paul from other newsgroups, and I suspect many other
motives. Paul is... let's say unique.
>>> Maybe I'm alone on this, but I fail to see the point in creating a new
>>> BASIC-like dialect using another flavour of BASIC ....
>>
>> Self-education. (The OP is obviously very green.)
>
> **VERY***
>
> I can't imagine a language more ill suited to writing a language
> compiler or interpretter than BASIC.
Forth? APL?? COBOL??? LOGO???? :-)
BASIC almost always has native string types and functions (often
built in at a low level) for manipulating them. BASICs can even
just compare two strings usefully.
Ain't the language *I'd* choose, but I can think of worse.
>
> I can't imagine a language more ill suited to writing a language
> compiler or interpretter than BASIC.
>
I disagree. I have written a full C-language compiler entirely with a Visual
Basic. Okey okey, it's not a same thing than writing a compiler with let's
say QBasic. And actually, i only wrote the C-frontend and code generator
with the VB. A maker, an assembler and linker are written in C. But i don't
see why one can't implement a whole compiler toolchain with basic-like
language.
Regards,
Markku Alén
>
>> I can't imagine a language more ill suited to writing a language
>> compiler or interpretter than BASIC.
>
> Forth? APL?? COBOL??? LOGO???? :-)
>
> BASIC almost always has native string types and functions (often
> built in at a low level) for manipulating them. BASICs can even
> just compare two strings usefully.
Forth is fairly low-level, which is actually good if you're going to write a
compiler in a language not specifically designed for such. Of course, by
the time you finished, you might have trouble remembering how to speak to
humans.
I can imagine an APL wizard producing a compiler in one gigantic function,
getting it to work, and not even recognizing his own code once the
amphetamines wore off.
Programmers' Purgatory: You have to write and verify an Ada compiler, but
the only compiler you have is Grace Hopper's original COBOL, running on
contemporary punched-cards-and-vaccuum-tubes hardware. In Hell all you
have is LOGO running on an eight-bit TV-output microcomputer that doesn't
have a printer or _any_ mass storage, not even a floppy drive. You need to
save your work? Copy it from the screen by hand before the next power
failure.
Steve Rush wrote:
[...snip...]
> In Hell all you
> have is LOGO running on an eight-bit TV-output microcomputer that doesn't
> have a printer or _any_ mass storage, not even a floppy drive. You need to
> save your work? Copy it from the screen by hand before the next power
> failure.
Geez, use a cassette!
Then your imagination is quite limited. XBasic is entirely written in
XBasic, is free, open-source, GPL and cross-platform (Windows and Linux).
Furthermore, it has both interpreted and compiled modes, is powerful,
elegant and beautiful. I only know 2 languages superior to it as a tool for
expressing algorithms ( APL and J, which are really the same language
anyway). Here is a quine written in XB which uses no numbers and only a
single PRINT statement
DECLARE FUNCTION Q()
FUNCTION Q() STRING
_="_"
__="="
___="\""
____="\n"
_____="\\"
______="n"
_______="DECLARE FUNCTION Q()"
________="FUNCTION Q() STRING"
_________="PRINT
_______;____;________;____;_;__;___;_;___;____;_;_;__;___;__;___;____;_;_;_;
__;___;_____;___;___;____;_;_;_;_;__;___;_____;______;___;____;_;_;_;_;_;__;
___;_____;_____;___;____;_;_;_;_;_;_;__;___;______;___;____;_;_;_;_;_;_;_;__
;___;_______;___;____;_;_;_;_;_;_;_;_;__;___;________;___;____;_;_;_;_;_;_;_
;_;_;__;___;_________;___;____;_;_;_;_;_;_;_;_;_;_;__;___;__________;___;___
_;_________;____;__________"
__________="END FUNCTION"
PRINT
_______;____;________;____;_;__;___;_;___;____;_;_;__;___;__;___;____;_;_;_;
__;___;_____;___;___;____;_;_;_;_;__;___;_____;______;___;____;_;_;_;_;_;__;
___;_____;_____;___;____;_;_;_;_;_;_;__;___;______;___;____;_;_;_;_;_;_;_;__
;___;_______;___;____;_;_;_;_;_;_;_;_;__;___;________;___;____;_;_;_;_;_;_;_
;_;_;__;___;_________;___;____;_;_;_;_;_;_;_;_;_;_;__;___;__________;___;___
_;_________;____;__________
END FUNCTION
Here is yet another nice XB quine
DECLARE FUNCTION Q()
DECLARE FUNCTION P(STRING s)
FUNCTION P(STRING s)
SHARED k
SELECT CASE 4*(k<13)-3*(k<15)+(k<30)-2*(k<43)
CASE 0: PRINT s
CASE 1: PRINT CHR$(80)+CHR$(40)+CHR$(34)+s+CHR$(34)+CHR$(41)
END SELECT
INC k
END FUNCTION
FUNCTION Q()
SHARED k
DO
P("DECLARE FUNCTION Q()")
P("DECLARE FUNCTION P(STRING s)")
P("FUNCTION P(STRING s)")
P("SHARED k")
P("SELECT CASE 4*(k<13)-3*(k<15)+(k<30)-2*(k<43)")
P("CASE 0: PRINT s")
P("CASE 1: PRINT CHR$(80)+CHR$(40)+CHR$(34)+s+CHR$(34)+CHR$(41)")
P("END SELECT")
P("INC k")
P("END FUNCTION")
P("FUNCTION Q()")
P("SHARED k")
P("DO")
P("LOOP UNTIL k>44")
P("END FUNCTION")
LOOP UNTIL k>44
END FUNCTION
Vic
> Maybe I'm alone on this, but I fail to see the point in creating a new
> BASIC-like dialect using another flavour of BASIC ....
A common criticism to functional programming languages is "the only
major use of ___ is writing a compiler or interpreter for ___".
The purpose of the OP is obviously to bring this criticism to BASIC.
I recommend the OP to write a theorem prover in BASIC as the next
project.
P.S. What has happened to that guy who claimed to write a theorem
prover in Javascript "because it's OO" many years ago? Is he done
yet?
You can write compilers in BASIC, of course, in just the same way that you
can nail a chicken to your head...
I haven't compromised nothing when wrote the C-compiler in Visual Basic. In
a matter of fact, the Visual Basic gave me a good tools for example managing
a memory and error-conditions. The source code is clean and elegant, no
hacks at all. Then again, the Visual Basic is a bit different than a
"traditional" BASIC.
Today, i could write my C-compiler with the c-language and the
implementation would also be very clean because of memory and error handling
concepts are already designed. But why should i? The VB version works great
and it is a very big source code. Maintaining the source code is a lot
easier in VB than in C.
PS. One, and only one, thing i missed in Visual Basic is an unsigned data
types. That could be tolerable if the Visual Basic's overflow exception
could be disabled.
-- Markku
> P.S. What has happened to that guy who claimed to write a theorem
> prover in Javascript "because it's OO" many years ago? Is he done
> yet?
Maybe this is it?
http://www.umsu.de/logik/trees/
- Torbjörn
I was surprised. I didn't think Javascript was Turing - complete. Of
course, it doesn't really take much. Look at the original Turing machine.
_That_ would be a hellish programming job: construct a general theorem
prover as a Turing machine.
"Erik de Castro Lopo" <nos...@mega-nerd.com> wrote in message
news:42B28C67...@mega-nerd.com...
>
> **VERY***
>
> I can't imagine a language more ill suited to writing a language
> compiler or interpretter than BASIC.
You have no imagination :-)
In the mid-90s I wrote a compiler using QuickBASIC 4.5 that was
faster and friendlier than its C counterpart. (The trick to
efficient BASIC is leveraging the built in commands. For example,
using a substring search command to turn a text token into a
number which can be used for lookups, switch statements, etc.)
It generated a byte code file that was interpreted by a simple
65816 assembly-based interpreter. The compiler handled all the
nasty bits like nested conditionals, expression parsing (with
precedence and parentheses), symbol table, string tokenizing
and compression (recursively removing common strings), etc.
Being BASIC it was dead easy to throw in new features as needed
or requested. (And easy to tighten up the syntax checking
every time someone found a way to break it :-) -Wm
> "Erik de Castro Lopo" <nos...@mega-nerd.com> wrote in message
> news:42B28C67...@mega-nerd.com...
>
>> **VERY***
>>
>> I can't imagine a language more ill suited to writing a language
>> compiler or interpretter than BASIC.
>
> You have no imagination :-)
>
> In the mid-90s I wrote a compiler using QuickBASIC 4.5 that was
> faster and friendlier than its C counterpart. (The trick to
> efficient BASIC is leveraging the built in commands. For example,
> using a substring search command to turn a text token into a
> number which can be used for lookups, switch statements, etc.)
Back in eight-bit days, I wrote some Adventure programs on a TRS-80. I
was amazed at how much faster the INSTR() function worked than any BASIC
search routine I could come up with. I assume that this was the
difference between well-optimized machine code and interpreted BASIC. I
know that Microsoft BASIC doesn't represent strings in memory as trees, as
some newer BASICs do.
I suspect that most of the people bad-mouthing BASIC haven't really looked
at BASIC since the days of line numbers and two-character variable names.