Git Product home page Git Product logo

tmg's Introduction

Port of Unix TMG to C99.

About TMG

TMG is an early compiler-compiler, or, according to McIlroy:

TMG is a string processing language especially intended for writing translators for computer languages. It deals with string scanning, building of tables and output generation, and provides some integer arithmetic.

Initially created by Robert McClure (1965) to work on supercomputers and mainframes of the time, TMG was cross-compiled for PDP-7 microcomputer by Douglas McIlroy to work under Unix operating system. Soon after that the language was further developed by McIlroy for Unix on PDP-11, creating a unique and powerful dialect of McClure's TMG. This version of TMG was included into Unix from Version 2 to Version 6, after which it was phased out in favor of Stephen Johnson's YACC.

This is a translation of TMG from PDP-11 assembly to portable C. To the best of our knowledge, it is the first implementation of TMG in a high-level language, done more than 50 years after the tool first appeared.

Usage

Installation:

./install.sh

Compiling:

tmg examples/hello_world.t

Running executable:

touch input
./a.out input

Quotes about TMG

TMG was an early inspiration for Donald Knuth and his TAOCP. According to him:

I was impressed by the metacompiler of Val Schorre and by the more powerful (though less elegant) "transmogrifier" of Bob McClure. I told Peter [Wegner] about my draft manuscript for Chapter 12 of The Art of Computer Programming, which included an example system of a similar kind, called TROL ("Translation-Oriented Language").

Stephen C. Johnson, creator of YACC, about his experience of working with Unix TMG:

There was a compiler/compiler in use at the Labs, imported I think by Doug McIlroy, called TMG. It was a backtracking recursive descent compiler that could compile almost anything but was unbearably slow and, if it encountered a syntax error would backtrack back to the first character of the input file and say, in effect, "something's wrong in here somewhere".

Doug McIlroy, creator of the Unix dialect of TMG:

And in some ways, TMG was nicer than YACC. Not specification of grammar, but it actually helps you do the translation. YACC only helps you do the parsing, it's up to you to do the translation after that.

Tom Duff, Bell Labs employee:

It made syntax-directed translation really easy, but with an abstruse syntax and semantics that any esoteric language enthusiast could appreciate.

Wishlist

This is a working implementation of TMG in C. Self-compilation achieved (albeit in two phases).

However, there is still room for improvement:

  • make the makefile
  • prepare a release for Windows
  • figure out how to use LR-parsing builtins, contributed by Johnson and Aho, but not documented in the Manual
  • achieve self-compilation in a single phase (very hard).

The language itself is extremely spartan and could be improved by addition of more builtins (like reverse operation for char) and more language features (like better arrays, more flexible tables and strings). However, this might go against McIlroy's own liking, who is a well-known proponent of mathematical elegance and conciseness in programming, as well as smaller-sized systems.

License

All code except the original TMG implementation is published under the BSD 2-Clause License.

References

tmg's People

Contributors

amakukha avatar philbudne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tmg's Issues

calloc - reverse order of parameters

calloc (libs.h) has reverse order of parameters - size first, then number of elements.
Google search for calloc gives the reverse order (I guess it's not a big deal if it works despite that).

nt build

You mentioned preparing a windows build in your readme. I wanted to let you know that it built ok for me using the Microsoft 32-bit compiler (19.16.27040). There were two changes that I made:

  • the symbol_t struct in tmgc.h has a gcc-specific packed attribute that I ifdef'd on _MSC_VER, using a pack,1 pragma for msc, otherwise the gcc attribute.

  • the build script asks gcc to align functions. The msvc compiler doesn't support function alignment.

I built a few of the examples by hand and they worked as expected. It'd be fairly simple to make nt-batch file versions of the bash scripts, then run all the test bits.

It's very cool that you took the time to do this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.