|
0. Background tiny-c is an interpreted language that runs on a computer under either DOS or Linux. It was developed in the mid 1970's and 1980's. It supports a subset of the C language. The syntax of tiny-c differs in several ways from C. The definitive documentation of tiny-c is the author's book "Learning C with tiny-c" by Scott Guthery, published in 1985 by TAB BOOKS, Inc. The book has been scanned and is available at and The interpreter is a very interesting and complex set of modules which will be of interest to students who want to learn about interpreter and compiler design. The DeSmet C compiler is mentioned in the book as the compiler the author used to compile the source. This compiler is available free of charge at http://www.desmet-c.com/. 1. To get the software ... The archives http://primepuzzle.com/tc/tiny-c-pc.zip and http://primepuzzle.com/tc/tinyc-linux.zip have source and executables for the tiny-c interpreters. 2. Creating tiny-c programs, running the interpreter, loading a sample program, running the sample program, exiting the interpreter. To create tiny-c programs you may use the tiny-c Shell or an external editor. You invoke the interpreter by typing tinyc.exe at a DOS prompt or by typing ./tinyc in a terminal session under Linux. After some version information is displayed, you read in your tiny-c source file with a .r command. You then may use a .p command to print out (display) your source file. .p 20 for example will print out the first 20 lines. To run your tiny-c program, type a . followed by the name of the "main" function in your program. In the example below, this function is called hello. Finally, exit the interpreter by typing .x. c:\tc>tinyc.exe tiny-c/PC Interpreter Version PC-01-06 Copyright (c) 1984 by Scott B. Guthery Implemented 12/7/8 by Lee Bradley / Ed Davis tiny-c Shell - 12/7/8 tc>.r hello.tc 34 0 5 34 24466 tc>.hello Hello, tiny-c! tc>.x c:\tc> 3. The tiny-c language tiny-c programs, like C programs, are built using functions.
/* guess a number between 1 and 100.
/*
/* t. a. Gibson 11/29/76.
/* lrb - 11/30/2007
/* note - do not put anything after the final bracket of a function
/* other than another function or at most a single blank line!
guessnum [
int guess, number
char answer
ps"seed? ";last=seed=gn
answer = 'y'
while (answer == 'y') [
number = random (1,100)
pl "Guess a number between 1 and 100."
pl"";ps "What is your guess? ";guess = gn
while (guess != number) [
if (guess < number) ps "Too low."
if (guess > number) ps "Too high."
pl "";ps "What is your guess? ";guess = gn
] /* end while loop.
ps "RIGHT!!";pl"";ps "Again (y/n)? "
answer = gc
] /* end of answer loop.
]
Instead of braces ({ }), tiny-c uses brackets ([ ]). Comments use a
single /*, not the paired /* and */. Most of the standard C relations
and arithmetic operators, like ==, != and <= and +, * etc. work.
A set of standard library functions are available. In the above we see pl (print a string on a new line), ps (print a string), gn (get a number) and gc (get a character). tiny-c supports two types of variables, character and integer. In addition, arrays may be used. For example, to declare an 80 character buffer, use char buffer(80) Note the use of parentheses instead of brackets. In the case of the character array above, buffer is a pointer variable. The value of buffer is the address of the element buffer(0). 4. The tiny-c Shell When you run the interpreter, the Standard tiny-c IPL file loads and you are presented with a tc> prompt. You will be under the influence of the tiny-C Shell at this point. Here's the main loop of this Shell. while(1)[ps"tc>" while((ll=gs(ln))==0)[] c=ln(0) if(c=='.')[ if(num(ln+1,v))go(v) else if((ln(2)==0)+(alpha(ln(2))==0))[ c=ln(1) if(c=='p')pt else if(c=='d')dl else if(c=='l')oi else if(c=='c')ch else if(c=='/')fa else if(c=='r')gi else if(c=='w')gu else if(c=='x')return else [ps"???";pl""] ]else st ] else if(c=='-')up else if(c=='+')do else in ] ]You may use a variety of "dot" commands to read, write, insert, delete etc. The Shell is thus a program editor as well as function launcher. 5. tiny-c error codes
6. tiny-c basic language constructs etc. Please visit tiny-c basic language constructs etc.
|