Tg

From Esolang
Jump to navigation Jump to search

Introduction

Tg is a postfix-expression programming language created by User:SteloKim. It is, as yet, incomplete.

Tg is quite simple. A Postfix program consists of a list of operators and operands.

Tg uses lazy evaluation and type inference.

Types

Example Type
3 Int
3.0 3. rand Float
"Hello" String

Functions

Symbol Function

a b + a b - a b * a b / a b =

Returns (a+b), etc.

a b +. a b -. a b *. a b /.

Returns (a+.b), etc. (Float type)
a b car Returns a.
a b cdr Returns b.
condition then-part else-part ? if expression
a display Displays the item a to the standard output.
newline Displays a new line to the standard output.
expression parameter \ Returns an anonymous function. Only one parameter is allowed.
rand Returns a random number [0.0, 1.0].

Usage

  • Compile to a.out:

tgc test.tg

  • Compile and run:

tgrun test.tg

  • Compile the standard input and run:

tgi

Examples

10 20 + display newline;
1 1 = 2 0 / 3 cdr 10 ? display newline;;
"Hello, world!" display newline;;
3 x 2 * x \ display newline;;
3 4 x y + y \ x \ display newline;;
"Tg" "Hello, " display str display ; "!" display ; newline ; str \ ;

=>

30
3
Hello, world!
6
7
Hello, Tg!

Implementation

Currently, Tg is implemented in OCaml. It produces an OCaml code as an intermediate language and then compiles it to get a binary.

Tg compiler source code

Tg compiler source code(20080616)

Tg compiler source code(20121113)