Click the tiny-c logo above to visit tiny-c Programming Group on Facebook. Click here to get into the details (tiny-c basic language constructs, etc.) 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 /* ** tiny-c error codes */ #define STATERR 1 /* illegal statement error */ #define CURSERR 2 /* cursor ran off end of program - look for missing ] or ) */ #define SYMBOLERR 3 /* symbol error - name expected */ #define RPARENERR 5 /* right parenthesis missing */ #define RANGERR 6 /* subscript out of range */ #define CLASSERR 7 /* using a pointer as a variable or vice versa */ #define SYNTAXERR 9 /* more expression expected */ #define LVALERR 14 /* illegal equals sign */ #define POPERR 15 /* pop error */ #define PUSHERR 16 /* stack overflow - expression too tough / functions / recursion too deep */ #define TMFUNERR 17 /* too many active functions */ #define TMVARERR 18 /* too many active variables */ #define TMVALERR 19 /* too many active values - "squeeze" program (remove comments) and error may go away */ #define LINKERR 20 /* startup error - a missing [ or ] may cause this */ #define ARGSERR 21 /* arguments needed and number given don't match */ #define LBRACERR 22 /* function body must begin with [ */ #define MCERR 24 /* illegal invocation of MC */ #define DECLARERR 26 /* undefined symbol - variable misspelled, need int or char statement or function not loaded */ #define KILL 99 /* program interrupted by user */
Click the tiny-c logo above to visit tiny-c Programming Group on Facebook. Click here to get into the details (tiny-c basic language constructs, etc.)
|