State Engines, part 3

Tags

, , , , , ,

In the first two parts of this series I’ve introduced state engines and taken apart a specific instance of an engine. Now it’s time to tie together the design idea with approaches to building a variety of such engines.

Because the programming logic is in the state table, the engine can be fairly generic. That means it’s possible to create a state engine framework you can reuse for a variety of applications.

Continue reading

State Engines, part 2

Tags

, , , , , ,

Last time I introduced state engines and state tables. I showed parts of a simple implementation of one in Python. It parsed the language introduced in Little Programming Languages. This post continues that, so be sure you’ve read that first article.

I got as far as the state table implementing the process, and that’s where this post picks up. I’ll also get into the SourceReader class that does the heavy lifting.

Continue reading

State Engines, part 1

Tags

, , , , ,

At one point in my career, the state engine (SE) was one of my favorite AWK hammers. At the time much of the work involved text processing or, in some cases, serial byte processing (which is not quite the same thing). That sort of thing is right in the wheelhouse for a state engine.

They are a very useful tool and an important part of any programmer’s toolkit.

Continue reading

An AWK Hammer

Tags

, , ,

In the Unix world you sometimes hear someone mention an “AWK hammer” or an “AWK nail” — usually in reference to an unexpected, possibly suspect, way of using some tool. In that history repeats itself, in the corporate world, one might have (but never did) hear reference to a “Lotus 1-2-3 hammer.”

The implication is that someone has fallen in love with a particular tool and is using it everywhere. In particular it applies to a situation where using that beloved tool may not have been the ideal choice.

Continue reading

LPL-1

Tags

, , , , ,

Here’s the last of the oddball Little Programming Languages (for now). This one is a little like LPL-2 in using a three-part syntax (which turns out to be non-ideal). Unlike LPL-3, neither of these are particularly usable languages — more along the lines of being something a language designer amused himself with on a rainy afternoon.

A key goal in LPL-1 was to minimize the use of punctuation characters. No brackets or parenthesis to create syntax blocks. (Square brackets for array indexing and parentheses for expressions, but that’s it.)

Continue reading

LPL-2

Tags

, , , , , ,

The language I showed you last time, in LPL-3, was a fairly reasonable one. This time I’m showing you a preposterous one no one would actually use. Worse, it turns out to be something of a failure due to weird holes left by the design goal of orthogonal single-syntax construction.

But that oddness helps us focus on what a programming language actually is, so it’s worth a peek. And maybe it’ll give you a laugh.

Continue reading

LPL-3

Tags

, , , , , ,

I’ll pick up with the language I began describing last time in a future post. Right now I want to pick up the thread of Little Programming Languages (LPLs) and use several examples to illustrate what underlies a programming language. (And as it turns out, these are “little” only in a certain sense.)

This first example, LPL-3, is Lisp-like and, because of that, is fairly orthogonal. Even better, it’s probably actually usable, although — like Lisp — it doesn’t have the cleanest syntax (languages like Python have really spoiled me).

Continue reading

Little Programming Languages

Tags

, , , , , , ,

One characteristic of the hard-core coder is a love of computer languages, programming languages in particular. Programmers of that ilk — of my ilk — collect new languages like merit badges. (I get a kick out of saying that I’ve programmed “from Ada to the Z-80!”)

The especially far gone of us also enjoy creating new languages (or in some cases, new dialects of XML). Lately I’ve been playing with a language design that follows a favorite theme: the single-syntax construction language.

Continue reading

Rule #4: Comment As You Go!

Tags

, , , , ,

There is a common tendency, as we crank out code, to think that we’ll come back later and write some really good comments — comments that future reviewers will view with admiration for their clarity, completeness, and humor. But if we’re honest we have to admit: Later never comes. We never go back and write those great comments. Often we don’t write any comments at all other than some placeholder we might dash off at the time.

Which is why Rule #4: Comment As You Go!

Continue reading