tiny-c/PC

1. 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. It's a lot easier to use an external editor. Your file must be linefeed delimited, not carriage return linefeed delimited. The editor I use can save files in linefeed delimited (Unix-style) form. Programs created and saved using the tiny-c Shell are automatically linefeed delimited.

You invoke the interpreter by typing tinyc at a DOS prompt. 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. 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:\11-2-07\tc>tinyc.exe

tiny-c/PC Interpreter  Version PC-01-01
Copyright (c) 1984 by Scott B. Guthery
Implemented 12/11/2007 by Lee Bradley

tiny-c Shell - 12/10/2007

tc>.r hello.tc
 31
 0 4 31 11969
tc>.hello
Hello, tiny-c!
tc>.x

c:\11-2-07\tc>
2. Background

tiny-c/PC (which we will call tiny-c from here on) is an interpreted language that runs on IBM PC compatibles. 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.

To obtain source and executable code for tiny-c and to see documentation on several tiny-c programs, visit http://primepuzzle.com/tiny-c/.

The book mentioned above contains the C source code for the interpreter as well as the so-called Standard tiny-c IPL file. These files are included in the archive http://primepuzzle.com/tc/tiny-c-pc.zip.

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 now available free of charge at http://www.desmet-c.com/.

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 so-called 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) []             /* Read non-empty line
    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 thus 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