News for hackers. Stuff that matters.
Re:T3X – a minimal procedural language by bluetomcat on Friday May 05, 2017 @02:27PM (#14275669)
I have a very similar project (not a compiler but an interpreter for a small, integer-only imperative language): https://github.com/bbu/simple-interpreter

Unlike this recursive-descent parser, my minimalistic language uses a table-driven shift-reduce parser which is entirely contained in the C code. Both the lexer and the parser can be extended very easily in order to accommodate new tokens and new syntactic forms.

Re:T3X – a minimal procedural language by nils-m-holm on Friday May 05, 2017 @02:36PM (#14275745)
T3X9 also uses a table-driven operator-precedence (LR) parser for most binary operators.
Re:T3X – a minimal procedural language by bluetomcat on Friday May 05, 2017 @03:18PM (#14276089)
Kudos for the bootstrapping ability and for the highly skillfully made ELF and code generation. I wouldn't be able to do that :-)
Re:T3X – a minimal procedural language by nils-m-holm on Friday May 05, 2017 @05:15PM (#14276895)
Thanks! Decades of experience! :)
Re:T3X – a minimal procedural language by i336_ on Saturday May 06, 2017 @01:15AM (#14278799)
What might you recommend to someone who wants to to learn more about these subjects?

For example, http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... is extremely interesting, but a lot of it is over my head.

I guess at the end of the day there's no real alternative to "just dive into the source code for a while" with these sorts of things - hence the importance of having "decades of experience" under your belt - but I'm curious if there's anywhere in particular that you might recommend as a startpoint.

Re:T3X – a minimal procedural language by nils-m-holm on Saturday May 06, 2017 @02:58AM (#14279095)
Yes, examples of minimal ELF files are good starting points for getting the back end part up and running. I'm not sure that reading real-life code will get you very far, because it often deals with lots of edge cases and attempts to be efficient and generate clever code. However, there are compilers that have been made as educational tools or with simplicity as a major design goal. I would stick to those in the beginning. See my home page (http://t3x.org) for lots of examples!

Then, books. I'll make a list some day, I promise! ;) From the top of my head: Wirth's "Compiler Construction", Richard's "BCPL, the Language and its Compiler", and - shameless plug - "Practical Compiler Construction" by myself. I have also read the Dragon Book back then - it's good, but too heavy on theory for a beginner.

Re:T3X – a minimal procedural language by i336_ on Sunday May 07, 2017 @05:39AM (#14284645)
> Yes, examples of minimal ELF files are good starting points for getting the back end part up and running.

Mmm, one of several components.

> I'm not sure that reading real-life code will get you very far, because it often deals with lots of edge cases and attempts to be efficient and generate clever code.

Very good point. It takes a bit more time and effort to build a proper mental map, but there's really no worthwhile alternative.

> However, there are compilers that have been made as educational tools or with simplicity as a major design goal. I would stick to those in the beginning.

I agree! These help a lot, and make study almost (if not very) fun :)

> See my home page (http://t3x.org) for lots of examples!

Will do, thanks!

> Then, books. I'll make a list some day, I promise! ;) From the top of my head: Wirth's "Compiler Construction", Richard's "BCPL, the Language and its Compiler", and - shameless plug - "Practical Compiler Construction" by myself. I have also read the Dragon Book back then - it's good, but too heavy on theory for a beginner.

Interesting. I actually stumbled on a copy of the Dragon Book while at an op-shop some time ago. I didn't actually know what I was grabbing at the time, just that it looked like a really good idea to prioritize getting it. I'm very happy to have it, and hope to be able to make sense of it at some point :)

Looks like Wirth's Compiler Construction can be found at http://www.ethoberon.ethz.ch/WirthPubl/CBEAll.pdf

BCPL, the Language and its Compiler and Practical Compiler Construction don't seem to have free options; that's fine, I've added these (and your other books!) to my (burgeoning) wishlist :P

Re:T3X – a minimal procedural language by JdeBP on Saturday May 06, 2017 @06:04AM (#14279566)
There is also Practical Compiling With Pascal-S by Rees and Robinson (ISBN 9780201184877), which took the same approach as you do, 30 years ago.
Re:T3X – a minimal procedural language by nils-m-holm on Saturday May 06, 2017 @09:13AM (#14280085)
Interesting, thanks! Ordered a copy.
Re:T3X – a minimal procedural language by bluetomcat on Saturday May 06, 2017 @03:29AM (#14279165)
Another really cool and intricate aspect of your compiler is that scanning/parsing/generation are all done in a single pass. I'm not too convinced whether there is a practical benefit to that, but it certainly contributes to the small size of the compiler and reduces the memory footprint, since it eliminates the need for keeping the list of tokens or the parse tree in memory, effectively only using the stack as storage?
Re:T3X – a minimal procedural language by nils-m-holm on Saturday May 06, 2017 @09:11AM (#14280077)
The biggest benefit is simplicity, the greatest drawback is lack of extensibility (optimizer, etc).

Memory footprint is not really optimal, because T3X9 keeps both the entire source code and the entire executable in memory all the time. I wanted fast compilation, though. For small footprint, I would have made it a two-pass compiler.

An early T3X compiler ran in tiny on DOS (64KB for code and data).

Re:T3X – a minimal procedural language by stcredzero on Friday May 05, 2017 @02:02PM (#14275471)
It's hard to say what a minimal procedural language is. There are ISAs with a single instruction: https://en.wikipedia.org/wiki/One_instruction_set_computer

This looks like it's a MISC: https://en.wikipedia.org/wiki/Minimal_instruction_set_comput...

I've also invented something like this: NISC. (Or {}ISC) Null Instruction Set Computer. You can arbitrarily reduce the die size for implementations of this architecture, as well as scale the clock speed arbitrarily. It also revolutionizes cooling.

Re:T3X – a minimal procedural language by oddity on Friday May 05, 2017 @02:07PM (#14275518)
I don't think the description as minimal was intended in any formal way. It's informally minimal in the sense that it features less complexity than more well known languages like C or Fortran.

A formal notion of a minimal language/machine gets messy anyway and is of limited utility even in a purely academic context, as far as I know.

Re:T3X – a minimal procedural language by stcredzero on Friday May 05, 2017 @03:50PM (#14276317)
My NISC ISA is minimal in a comedic context.
Re:T3X – a minimal procedural language by zoren on Friday May 05, 2017 @04:47PM (#14276721)
I don't think it was intended in the formal sense either. But "minimalistic" or "small" would probably be more suitable.
Re:T3X – a minimal procedural language by nickpsecurity on Saturday May 06, 2017 @12:04AM (#14278603)
You got me excited then eye rolling with the NISC reference. The author showing up would've been interesting.

https://en.wikipedia.org/wiki/No_instruction_set_computing

Re:T3X – a minimal procedural language by simcop2387 on Friday May 05, 2017 @05:13PM (#14276886)
Someone else invented something similar, https://en.wikipedia.org/wiki/Zero_instruction_set_computer

it's kind of insane how little you need to do computation.

Re:T3X – a minimal procedural language by penpapersw on Friday May 05, 2017 @01:53PM (#14275393)
Very cool! I love minimalistic languages.

How is this able to omit basic type information? Is everything just an int?

> "It is a statement rather than a production tool."

What's the statement supposed to be?

Re:T3X – a minimal procedural language by nils-m-holm on Friday May 05, 2017 @02:14PM (#14275569)
>How is this able to omit basic type information? Is everything just an int?

Data is untyped and operators are typed. So in X+Y, X and Y are integers, in X::Y, X is a byte vector and Y is an integer, and in Y[X], X is an integer and Y is a vector (and the types of its element again depend on the operators applied to them).

Note that not all combinations of data and operators make sense. E.g., "foo"*[1,2,3] is a valid expression, but probably will not deliver any meaningful result.

I'll leave the interpretation of the statement to you! ;)

Re:T3X – a minimal procedural language by lowtolerance on Friday May 05, 2017 @02:11PM (#14275547)
"I made a minimal procedural language"
Re:T3X – a minimal procedural language by nickpsecurity on Friday May 05, 2017 @06:28PM (#14277272)
People who want a simple language like old days should check out Edison language and system. It's like BCPL minimalism meets Wirth's Oberon:

http://brinch-hansen.net/papers/1981b.pdf

He did lots of interesting stuff including a race-free language for concurrency:

http://brinch-hansen.net/papers/

Re:T3X – a minimal procedural language by b1gtuna on Friday May 05, 2017 @04:39PM (#14276668)
Is the author of T3X reputable? I am about to drop $20 for the ebook, but I just want to be sure he has good basis on the subject.
Re:T3X – a minimal procedural language by nils-m-holm on Friday May 05, 2017 @05:14PM (#14276892)
It is, of course, a bit of an oxymoron to answer this question myself but, FWIW, I have been writing compilers since the 1990's, both as a hobby and as a job.

I have written compilers for lots of different processors and virtual machines with varying key aspects, like compilation speed, memory footprint, executable size, etc.

Check out my home page (http://t3x.org), there compilers for many different languages, from mainstream to pretty exotic. There are also excerpts from many of my books and even the full texts of some of the older ones.

Re:T3X – a minimal procedural language by register on Saturday May 06, 2017 @04:57AM (#14279403)
What about your other book "Lightweight Compiler Techniques? Could you put an excerpt online?
Re:T3X – a minimal procedural language by nils-m-holm on Saturday May 06, 2017 @05:44AM (#14279521)
Oh, yes, the homepage needs some reorganization!

For now, you can download the full text of "Lightweight Compiler Techniques" here: http://www.bcl.hamilton.ie/~nmh/t3x.org/zzz/lightweight-comp...

Enjoy!

Re:T3X – a minimal procedural language by b1gtuna on Monday May 08, 2017 @03:34PM (#14294827)
Great thanks!
Re:T3X – a minimal procedural language by sigjuice on Friday May 05, 2017 @05:05PM (#14276852)
The author is unknown to me (and I am nobody!). FWIW, I just bought the book and quickly read through the chapter on bootstrapping. IMHO, it is really well written.
Re:T3X – a minimal procedural language by b1gtuna on Monday May 08, 2017 @05:43PM (#14295885)
Ty for your input. Getting a copy :)
Re:T3X – a minimal procedural language by sitkack on Friday May 05, 2017 @08:37PM (#14277942)
Is legit. Own books. Author is bad ass.
Re:T3X – a minimal procedural language by b1gtuna on Monday May 08, 2017 @03:34PM (#14294829)
Awesome. Getting a copy.
Re:T3X – a minimal procedural language by bmh100 on Friday May 05, 2017 @07:31PM (#14277608)
I mean this earnestly (no snark): why should I care about T3X? I know that I'm missing the obvious reasons.
Re:T3X – a minimal procedural language by nils-m-holm on Saturday May 06, 2017 @05:28AM (#14279481)
As bootload said, it's a learning tool.

You can also use it to bootstrap something more high-level than assembly language in very little time.

I have even written real-life programs in T3X for a while, but I wouldn't recommend it unless you are fascinated by the beauty of typeless languages!

Re:T3X – a minimal procedural language by bmh100 on Saturday May 06, 2017 @11:01AM (#14280524)
What could it teach? Compiler design? Imperative language design? By "bootstrapping", are you referring to building a higher-level language that compiles to T3X?
Re:T3X – a minimal procedural language by nils-m-holm on Saturday May 06, 2017 @12:21PM (#14280932)
It can teach the most fundamental basics of procedural language design and compiler construction: how to implement selection, loops, and functions/procedures as well as scanning, parsing, and code generation.

By bootstrapping, I'm referring to building a T3X9 compiler for a new target platform and than using that to create something more interesting. You can start the process by re-implementing the compiler or by re-targeting it.

Re:T3X – a minimal procedural language by bmh100 on Saturday May 06, 2017 @08:16PM (#14283074)
Would studying it be helpful if I wanted to create a static analysis application on top of an existing procedural language?
Re:T3X – a minimal procedural language by nils-m-holm on Sunday May 07, 2017 @03:30AM (#14284321)
Static analysis involves things like partial evaluation, dataflow analysis, and type inference. None of this is covered in the T3X book.
Re:T3X – a minimal procedural language by bmh100 on Monday May 08, 2017 @09:48AM (#14291387)
Thank you. I really appreciate the information.
Re:T3X – a minimal procedural language by bootload on Friday May 05, 2017 @08:30PM (#14277911)
"why should I care about T3X?"

If you look at the source code, you might learn something.

Re:T3X – a minimal procedural language by bmh100 on Saturday May 06, 2017 @11:02AM (#14280531)
What topics would the T3X source be well suited to teach?
Re:T3X – a minimal procedural language by megapatch on Saturday May 06, 2017 @01:53AM (#14278927)
That can be said about a lot of code bases.
Re:T3X – a minimal procedural language by bootload on Saturday May 06, 2017 @01:55AM (#14278933)
"can be said about a lot of code bases."

True, the poster asked specifically about T3X.

Re:T3X – a minimal procedural language by sigjuice on Friday May 05, 2017 @08:03PM (#14277775)
I mean this earnestly (no snark): what could it have been instead of T3X that would make you care?
Re:T3X – a minimal procedural language by bmh100 on Saturday May 06, 2017 @11:06AM (#14280546)
Something related to functional programming, databases, data analysis, dev methodology, or system architecture. I use a procedural language in my job, but this doesn't seem relevant to it. My degree isn't in CS, if that helps.
Re:T3X – a minimal procedural language by b1gtuna on Friday May 05, 2017 @04:19PM (#14276540)
Cool, looks like I have something to read this weekend. I am glad their e-book caters towards people with little comp-sci / compiler design background.
Re:T3X – a minimal procedural language by sigjuice on Friday May 05, 2017 @01:38PM (#14275254)
Looks cool, but what is FreeBSD-specific about it? Shouldn't a compiler just be reading and writing files?
Re:T3X – a minimal procedural language by oddity on Friday May 05, 2017 @01:57PM (#14275426)
It generates FreeBSD executables directly.

>The compiler translates from T3X9 directly to FreeBSD-386-ELF. It does not require any assembler, linker, or other additional programs. I suspect that it can be ported to other 32-bit ELF Unixes in about half an hour.

Re:T3X – a minimal procedural language by sitkack on Friday May 05, 2017 @08:40PM (#14277957)
WebAssembly port would be fun.
Re:T3X – a minimal procedural language by JdeBP on Friday May 05, 2017 @01:54PM (#14275406)
Compiled executables are, by their very natures, usually specific to operating systems. This minimal compiler outputs one specific executable file format, hardwiring a specific platform and instruction set architecture in that executable file format's header.
Re:T3X – a minimal procedural language by sigjuice on Friday May 05, 2017 @04:52PM (#14276758)
Yes, I know that about executables, but I guess compiler-related subtleties are lost on me. I will clearly benefit from reading the book I just bought.
Re:T3X – a minimal procedural language by megapatch on Saturday May 06, 2017 @01:50AM (#14278913)
The Mandelbrot example has implementation problems. The check for a point being outside the set is implemented totally wrong, even the comment (which is not even consistent with the code) is wrong.

Not judging the language itself, but that is not really convincing.

Re:T3X – a minimal procedural language by nils-m-holm on Saturday May 06, 2017 @02:37AM (#14279055)
For being "totally wrong" it draws a pretty nice Mandelbrot set!

That being said: yes there are problems with the comments. It's code I have written decades ago and just copy-pasted now. Will fix! Thanks!