请输入您要查询的百科知识:

 

词条 Treelang
释义

  1. Overview

  2. Example

  3. Commentary

  4. References

  5. See also

Treelang is a "toy" programming language distributed with the GNU Compiler Collection (GCC) 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. During the GCC 4.3 release cycle, a patch was committed to remove the language,[1] because of high maintenance costs outweighing its benefits and also because it was no longer considered a good front-end example by GCC developers.[2]

Overview

Treelang is loosely based on the C programming language, but omits complex features such as pointers, arrays, and records. It has never been completed, although there were plans to gradually add more demonstrative features.

From the documentation distributed with GCC:[3]

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, modified by adding the main function, 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 subtract(int arg3, int arg4);     external_definition int first_nonzero(int arg5, int arg6);     external_definition int double_plus_one(int arg7);     external_definition int main();
     // function definition     add     {       // return the sum of arg1 and arg2       return arg1 + arg2;     }       subtract     {       return arg3 - arg4;     }
     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;     }
     // Like C, 'gtreelang' needs the main to be defined to create an executable.     main     {          return double_plus_one(5);     }

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 gtreelang. Both invocations run the Treelang frontend (internally labelled tree1) and produce machine code as output. Treelang can also issue some warning messages.[4]

References

1. ^[https://gcc.gnu.org/wiki/TreeLang GCC Wiki (online)]
2. ^https://gcc.gnu.org/ml/gcc-patches/2008-03/msg00391.html
3. ^Treelang Documentation {{Webarchive|url=https://web.archive.org/web/20110719061051/http://stderr.org/doc/treelang-4.1-doc/treelang.html |date=2011-07-19 }}
4. ^Treelang Documentation, § 5 - Compiler Overview {{Webarchive|url=https://web.archive.org/web/20110719061051/http://stderr.org/doc/treelang-4.1-doc/treelang.html#index-warnings-36 |date=2011-07-19 }}

See also

  • Toy language

1 : C programming language family

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/23 18:26:08