
FTCBASIC
Homepage: http://lucidapogee.com/index.php?page=ftcbasic
FTCBASIC means fast tiny compiled BASIC. It is a BASIC compiler for x86 DOS. The compiler is written in QuickBasic and generates FASM output. Using batch files, you may compile your source to com files instantly.
Generated com files are tiny and fast. They start at less than 50 bytes.
The compiler and language is derived from the Pebble language. Many of the great features of Pebble have been kept in translation. As a result, there's support for inline asm, include files, and more. There's even some basic 1D array and string data type support.
In all, there's integer, integer array, and string data types. Floating point is not supported, but may be implemented with libraries.
Only unsigned integers may be used in expressions. Operator precedence is *, /, +, -, <, >, <=, >=, =, <>, AND, and OR. Parenthesis override operator precedence.
** Notice: This Alpha version is fresh off the press and probably has issues. Also, the documentation is incomplete. I will be working on it, but wanted to make an early release to get some feedback. **
Examples...
Code: Select all
rem periodic table lookup example
rem uses carry command to perform modulus
rem compile with FTCBASIC
define e = 0, i = 0, m = 0, r = 0, c = 0, q = 0
dim a[1, 2, 5, 13, 57, 72, 89, 104]
dim b[-1, 15, 25, 35, 72, 21, 58, 7]
do
cls
print "Periodic Table Lookup"
crlf
print "0 to continue or 1 to quit: " \
input q
cls
if q = 0 then
gosub displaytable
gosub searchtable
crlf
print "Press any key to continue..."
pause
endif
loop q <> 1
end
sub searchtable
print "Atomic number: " \
input e
let i = 8
do
let i = i - 1
loop @a[i] > e
let m = e + @b[i]
let r = ( m / 18 ) + 1
carry c
let c = c + 1
cursor 19,20
print "Period: " \
print r \
print " Group: " \
print c \
crlf
return
sub displaytable
print " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18"
crlf
print " 1 H He"
crlf
print " 2 Li Be B C N O F Ne"
crlf
print " 3 Na Mg Al Si P S Cl Ar"
crlf
print " 4 K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr"
crlf
print " 5 Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe"
crlf
print " 6 Cs Ba * Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn"
crlf
print " 7 Fr Ra ** Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og"
crlf
print " 8 Lantanoidi* La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu"
crlf
print " 9 Aktinoidi** Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr"
crlf
return
Code: Select all
rem Nim game example
rem compile with FTCBASIC
define tokens = 12, take = 0
gosub intro
do
print "There are " \
print tokens \
print " tokens remaining."
crlf
print "How many would you like to take? " \
input take
if take > 3 or take < 1 then
print "You must take between 1 to 3 tokens."
endif
if tokens - take < 0 then
print "You cannot take that many."
endif
if take <= 3 and take >= 1 and tokens - take >= 0 then
let tokens = tokens - take
if tokens = 0 then
bell
print "Congratulations. You got the last token."
pause
end
endif
let take = 4 - take
if tokens >= 15 then
let take = 3
endif
if tokens <= 3 then
let take = tokens
endif
print "I will take " \
print take \
print " of the tokens."
let tokens = tokens - take
if tokens = 0 then
print "I got the last token. I win. Better luck next time."
pause
end
endif
endif
loop
sub intro
cls
print "NIM game"
crlf
print "Press any key to play..."
cls
return
Code: Select all
rem bubble sort benchmark example
rem compile with FTCBASIC
use time.inc
use random.inc
define const size = 32000
dim list[size]
define sorting = 0, index = 0, elements = 0
define timestamp = 0, sorttime = 0
define temp1 = 0, temp2 = 0
cls
print "Bubble sort benchmark test"
do
print "How many elements to generate and sort (max " \
print size \
print ")? " \
input elements
loop elements > size
gosub fill
gosub sort
print "done!"
print "sort time: " \
print sorttime
print "Press any key to view sorted data..."
pause
gosub output
pause
end
sub fill
print "filling..."
0 index
do
gosub generaterand
let @list[index] = rand
+1 index
loop index < elements
return
sub sort
print "sorting..."
gosub systemtime
let timestamp = loworder
do
0 sorting
0 index
do
let temp1 = index + 1
if @list[index] > @list[temp1] then
let temp2 = @list[index]
let @list[index] = @list[temp1]
let @list[temp1] = temp2
let sorting = 1
endif
+1 index
loop index < elements - 1
loop sorting = 1
gosub systemtime
let sorttime = ( loworder - timestamp ) / 18
return
sub output
print "printing..."
0 index
do
print @list[index]
+1 index
loop index < elements
return