Treelang Programming Language

Treelang is a "toy" programming language distributed with the GNU Compiler Collection to demonstrate the features of its code-generation backend. It was developed by Tim Josling, based on a language called Toy created by Richard Kenner.

Overview

Treelang is loosely based on the C programming language, but omits complex features such as pointers, arrays, and structures. It is currently incomplete, although there are plans to gradually add more demonstrative features. From the documentation distributed with gcc:
Treelang is a sample language, useful only to help people understand how to implement a new language front end to GCC. It is not a useful language in itself other than as an example or basis for building a new language. Therefore only language developers are likely to have an interest in it.

Example

The following example is from the Treelang documentation, and is included to give an impression of the Treelang syntax and semantics:
   // function prototypes      // function 'add' taking two ints and returning an int      external_definition int add(int arg1, int arg2);      external_definition int first_nonzero(int arg5, int arg6);      external_definition int double_plus_one(int arg7);            // function definition      add      {      // return the sum of arg1 and arg2        return arg1 + arg2;      }          double_plus_one      {      // aaa is a variable, of type integer and allocated at the start of the function        automatic int aaa;      // set aaa to the value returned from add, when passed arg7 and arg7 as the two parameters        aaa=add(arg7, arg7);        aaa=add(aaa, aaa);        aaa=subtract(subtract(aaa, arg7), arg7) + 1;        return aaa;      }            first_nonzero      {      // C-like if statement        if (arg5)          {            return arg5;          }        else          {          }        return arg6;      }  
Note that C-style comments (with the /* */ syntax) are not legal in Treelang.

Commentary

As a simple, C-like language, Treelang is interoperable with C and C++ with some minor datatype caveats. The designated filename extension for Treelang source code files is .tree. Treelang source code can be compiled by invoking gcc normally or as treelang. Both invocations run the Treelang frontend (internally labelled tree1) and produce machine code as output. Treelang does not issue "warning" messages; either the program is correct and is compiled, or it is not.

 

<< PreviousWord BrowserNext >>
washington mean time
bhubaneshwar
modesto cartagena
primoz peterka
wartsila sulzer rta96 c
greg laurie
david breashears
list of publications in biology
list of publications in economics
shear (mathematics)
roald jensen
lion war
ching chong
westmead, new south wales
america scores
st bartholomew the less
beartooth highway
st katherine cree
pitchfork
st mary woolnoth
the mercury
eximbills
engelberg abbey
william moore
cloud gate dance theater
john davies (publisher)
provins
arild
lionel johnson
uss hornet (1805, brig)
uss hornet (1865)
uss salt lake city (ssn 716)
uss phoenix (ssn 702)
uss boise (ssn 764)
pope john paul
paul alfred biefeld
uss farragut (dd 300)
charles madge
james reserve
voltage multiplier
sabrina lloyd
yibbum
swill
all summer in a day