The ETA C compiler project

Copyright © Stephen Sykes, 2003.

ETACC is a working C compiler for Mike Taylor’s ETA language. Yes, that’s right, this C compiler generates ETA code. ETA is an esoteric language that consists of only 7 instructions. It has some bizarre features, such as the fact that all numbers are written in a program in base 7. Obviously there are a few constraints on what you can do in an ETA program, but I was able to support quite a large subset of C, detailed below.

The C compiler should run on any reasonable UNIX system. You need a system C compiler, ruby, gnu make, and a great deal of patience whilst your programs compile. It is known to not work under cygwin, for reasons not yet understood.


The supported features of C are as follows:

  • int short long char
  • unary ops & * + – ~ !
  • prefix ++ —
  • postfix ++ —
  • binary ops * / % + – << >> < > <= >= == != & ^ | && ||
  • ternary op ?:
  • assignment = *= /= %= += -= <<= >>= &= |= ^=
  • arrays, subscripts
  • if
  • if else
  • while
  • do while
  • for
  • continue
  • break
  • return
  • goto
  • sizeof

Pointers, arrays, strings, character constants and so on are fully supported, and even recursion works. However, I haven’t yet been able to support some features.

The non-supported features are:

  • struct union
  • static
  • enum
  • float double unsigned
  • typedef
  • va_args
  • switch case
  • linking of multiple files together
  • multiple dimension arrays in global space
  • function pointers
  • array initialisers
  • fancy numeric constant formats – eg 0x1234

I aim to be able to support switch case, multi-d arrays in global space, function pointers, number formats and array initialisers in the near future. The remaining features will not be supported in this compiler because of the ridiculously enormous technical challenges they present.


The compiler is not much good without some libraries to help you do stuff.

There are three built-in fuctions that are always present in every program:

  • printf
  • putchar
  • getchar

Missing from this list at the moment are malloc & free, which will go here once I write them.

There are currently 12 library functions which you can access if you #include “libeta.h” in your program.

  • strcpy
  • strncpy
  • strchr
  • memset
  • strcmp
  • strlen
  • atoi
  • isalpha
  • isupper
  • islower
  • tolower
  • toupper

There will be more library functions as soon as I write them.

Including libeta.h in your program significantly increases the compilation time, so it is not recommended unless you really need one of the functions listed.

Differences from a standard C compiler

The main differences you will come across are the lack of features already mentioned above. And the compiler uses the system’s cpp preprocessor, so #defines and so on should work as expected. However, there are some things you need to know about how this compiler works in order to understand how to use it.

The code generated works on an ETA machine. ETA is a language that only has a single stack on which to store stuff. No registers, memory or anything. This means that either you need an enormously complex framework to keep track of the size of the stack at all times, or you build fixed size structures into the stack at compile time that hold the variable data that is generated at runtime. I went for the latter approach. This means that the stack size, and hence the amount of memory available to the program, is fixed during compilation.

The ETA code will be smaller and will compile and run faster if there is less space placed on the stack. So I have gone for quite low values for testing. However, you can specify more stack space if you require it in the parser command. The default value in the compiler shell script is 30.

If you run out of stack space, either your program will not work correctly, or it will exit after printing “!!”. Try changing the stack size value higher.

Another difference between an ETA interpreter and a more standard machine model is that all data types are the same size (actually a signed 32 bit int). Because everything, including chars in strings, are this size I decided to make sizeof return the value 1 for a variable of any data type. This perhaps is not quite ANSI, but it seems logical to me. There are some sizeof tests included that demonstrate this.

You can declare main() as main(argc, argv) if you like, but only zero/null will passed into these as there is no command line concept in an ETA interpreter.

The inplementation of printf will recognise %d, %s and %c only. No additional formatting parameters are allowed. %% will result in a single % being printed.

Finally, it’s better to present correct C programs to this compiler. There is practically no error checking. If there is a problem in the program, you may get a parse error, you may get an error from the ruby code generation phase, or you may get nothing at all. One option is to run your program through the system compiler first to find the errors.

Installation Package

The compiler consists of the following files:

  • c.lex – the flex lexer
  • c.y – the bison parser
  • main.c – the compiler main function
  • eta-rb.rb – the ruby code generation libraries
  • optimise.rb – the ruby optimiser
  • eta-cc-libs.rb – the built in function libraries
  • libeta.h – the C libraries
  • – the compiler shell script
  • sseta.c – the optimising ETA interpreter
  • Makefile – the makefile

The package includes the files, and lex.yy.c, which should enable you to compile the parser even if you don’t have bison and flex.

There is also a suite of test programs, which demonstrate various features and do various things. The test programs will compile with a standard C compiler if you make the include path point to the directory libeta.h is in. This is useful for checking results.

Finally, I included various ETA interpreters that you can run your programs with. However, unless your machine is a TeraOp-per-second supercomputer, I recommend using the optimising interpreter sseta. It is included in the package.

You can download the whole thing in a gzipped tar file.


Untar the package, and type “make” in your etacc directory. Everything will hopefully compile fine, please let me know any problems.

Then edit – you need to change the ETAPATH variable to point to the directory etacc resides in.

After this, you will want to run the tests. Change to the Tests directory, and type “make” (or try typing “gmake” if this doesn’t work). Even better, type “make -j” if you have more than one processor, or one of them fancy hyperthreading processors.

Then go and make a cup of tea.

When you get back, everything should have compiled. If not, make some marmite on toast.

Finally you should be able to type “make test”. The tests are interactive, but they tell you what to do. Some of the tests rely on a visual comparison of the results produced with the expected results (in brackets).


There are probably many bugs, my testing has been far from extensive. Please send reports here:

ETA Program Examples

Other ETA Example Programs

I will place more programs here as I write them. Comments welcome – mail

Rev Utility

.dalas a ni gge ym yrt
uoy nehw yrraM .nup tes tup n'tfo ym evoba snup yrT .eurT .duola lla kculc kculc yas
neh ynuP .tolb desu a tnuP .raet
liarf a yrc naem stib desreveR::
::Reversed bits mean cry a frail 
tear. Punt a used blot. Puny hen
say cluck cluck all aloud. True. Try puns above my oft'n put set pun. Marry when you
try my egg in a salad.

Hi Program

A suitable reply to the standard Hello World!

Drunk today, 
Me awfully rather bladdered,
Do unlawful butchery coldly nine new ways at home, 
Do crazy new nuts (red, and blue salty), but
Mummy normally says hear this: 
Untold envy tends to make a tired owl... 

Noughts and Crosses Program

Also known as Tic Tac Toe. It’s too long to list here, but the simple source is here, the beautified version is here, and the eta-builder source is here.

Bi-lingual Cat Detector

This is a version of my cat detector program (as described in the ETA for Palm Pilot pages) that can be interpreted by any standard ETA interpreter, and also will interpret itself if you run it with Ruby.

f>0?$6?ant<<c&&c=f=0:(c="htaoins".index($&)+c*7): $1?ant<<l+2: $2?ant<<STDIN.getc: $3?f=
$4?$><<z.chr: $5?ant<<ant[-1-z.abs]&&z>0&&ant.slice!(-2-z):(b=ant.pop
$6?ant<<b/z&&ant<<b%z: $7?ant<<b-z: b!=0&&(l=z-2
   ntiteo: nice cat
   ntsseo: bad cat
   natieo: nice cat
   nahoeo: bad cat
   nttaeo: nice cat
    niieo: no such cat
     tate: mad cat
      ine: happy cat
naehsnteh: nightmare cat
    ntoes: naughty but nice cat
   nanetn: a very fat cat
     naee: nearly a tiger in fact
  atnnhet: a cat came - but nice or not?
   ntiteo: nice cat
   natheo: nice cat
   nahteo: nice cat
   nahoeo: nice cat
    niieo: nice cat
   nahteo: nice cat
   ntsseo: nice cat
   naaieo: nice cat
    nineo: nice cat
 ntoeonet: good kitty
   ntaoeo: bad cat
   ntsseo: bad cat
   nahaeo: bad cat
    niieo: bad cat
   nahteo: bad cat
   ntsseo: bad cat
   naaieo: bad cat
    nineo: bad cat
 ntoeonet: nasty kitty

How To Choose The Perfect Private School

Choosing of languages school is something that takes many people alloy of times. Many consider looking for information online while other prefer visiting different places that are near to get all the content. This is to get all the required things that one ought to have before enrolling in such like classes. One can also love to consider a school that has cultural values, many choices of different languages just to mention a few. Therefore, under this topic, some of the necessary factors that one should consider while choosing languages schools are discussed below.

School accreditation. This refers to the degree of assurance that the given school is capable of giving out the very best for learning Mandarin. Also, it has got knowledgeable teachers who have got wide experience in such matters. The school should have all policies well-set, curriculum schedules, accommodation as well as better learning facilities. Thus, it is important to consider an organization that will offer quality English tuition for Kids in SG for the period will be required to be there.

Nationality mix. One should at all times consider the nationality mix of the given institution such as Pear Tree School. Get to know the various places that most student learning a particular language come from. Due they come from a specific country or from many parts of the world. This will be good since one has a great chance of mingling with many people who can be a great source of knowledge as well as promote faster learning of Chinese enrichment classes. Being a place where there are people from the different corner of the world will give one courage to stand all the challenges encountered while learning the language.

Curriculum and level of instruction. Some schools concentrate much on what is in the English course Singapore textbooks while other prefer not using such tools at all when delivering the message. Hence, there is a high need to get a language school that will give a standardized and well-balanced curriculum that I in a position of meeting the category of the people internationally.  The curriculum should meet all the aspect of learning a language, listening, speaking, reading as well as writing and good grammar pronunciation.

Class size. I t is vital to consider the size of the class that is available in any given Korean language Singapore schools. The big class may not produce that vary best for the learners. A good class should be composed of fifteen students and not more than that, according to Indoslang. This is to encourage easier teaching as well as handling of each person at a time. It will also increase the participation of every student thus increasing the level of performance and understanding among the people. Considering some of these factors will help one in getting the most appropriate language school aimed at.