tiny-c for the PC (DOS/Linux) (http://primepuzzle.com/tiny-c/tinyc-doc.html)

https://www.facebook.com/groups/299317782048/ will send you to the not just tiny-c Programming Group on Facebook.

http://primepuzzle.com/tc/tiny-c%20basic%20language%20constructs%20cover%20page.html will send you to a menu page of basic language constructs, the system library, gotchas, the shell, machine calls, error codes, appendices and tiny-c programs.

0. Background

tiny-c for the PC is an interpreted language that runs on a computer under either DOS or Linux. tiny-c was developed in the mid 1970's and 1980's. The original tiny-c interpreter was written in 8080 assembly language and ran on CP/M machines. An archive which contains this version may be found at http://primepuzzle.com/tiny-c/tiny-c.zip. The archive http://primepuzzle.com/mouse/maxz80.zip contains a Z80 emulator and many CP/M programs, including this tiny-c interpreter. Herb Johnson has compiled a copy of the tiny-c owner's manual of 1979, with HDOS, PDP-11 and CP/M support documents, and some associated source files. These are available at http://primepuzzle.com/tc/tiny_c_docs_8080_PDP11.zip.

The PC tiny-c interpreter is written in C (and tiny-c). tiny-c supports a subset of the C language. The syntax of tiny-c differs in several ways from C. "Learning C with tiny-c" by Scott Guthery, published in 1985 by TAB BOOKS, Inc. documents the tiny-c PC language. It has been scanned and is available at Learning C with tiny-c and Appendices. 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 PC 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.


tiny-c/PC Interpreter  Version PC-01-07
Copyright (c) 1984 by Scott B. Guthery
Implemented 5/16/09 by Lee Bradley / Ed Davis

tiny-c shell - 7/26/2010

tc>.r hello.tc
 0 5 34 24475
Hello, tiny-c!


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.
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 is 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.

else if((ln(2)==0)+(alpha(ln(2))==0))[
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 a function launcher.