Re: Example interpreter C

Laurence Finston <>
7 Sep 2005 13:13:09 -0400

          From comp.compilers

Related articles
[3 earlier articles]
Re: Example interpreter C (2005-08-21)
Re: Example interpreter C (Laurence Finston) (2005-08-21)
Re: Example interpreter C (George Neuner) (2005-08-24)
Re: Example interpreter C (2005-08-24)
Re: Example interpreter C (Julian Stecklina) (2005-08-31)
Re: Example interpreter C (Joerg Simon) (2005-09-02)
Re: Example interpreter C (Laurence Finston) (2005-09-07)
Re: Example interpreter C (Ivan Boldyrev) (2005-09-10)
Re: Example interpreter C (George Neuner) (2005-09-10)
Re: Example interpreter C (Laurence Finston) (2005-09-14)
Re: Example interpreter C (Ivan Boldyrev) (2005-09-17)
Re: Lisp variables, was Example interpreter C (Laurence Finston) (2005-09-22)
Re: Lisp variables, was Example interpreter C (Julian Stecklina) (2005-09-25)
| List of all articles for this month |

From: Laurence Finston <>
Newsgroups: comp.compilers
Date: 7 Sep 2005 13:13:09 -0400
Organization: GWDG, Goettingen
References: 05-08-055 05-08-062 05-08-073 05-08-084
Keywords: C, interpreter
Posted-Date: 07 Sep 2005 13:13:09 EDT

Somehow I missed this posting before. Thank you for your

On Thu, 24 Aug 2005, George Neuner wrote:

> On 21 Aug 2005 00:21:14 -0400, Laurence Finston <>
> wrote:

> But more important, I think, is the practical experience of compiler
> implementation. [...]

I couldn't agree more. For my language, I had the luxury of being
able to base it on an existing one, Knuth's METAFONT language, the
grammar of which he conveniently supplied in Backus-Naur form.
Clearly, if I were to implement a language from scratch, I would have
to learn some compiler theory. My current preoccupation, however, is
finding the intersections of geometric figures. I've been told on
good authority that some mathematicians spend their whole lives
working on this.

I learned a great deal by implementing a METAFONT-like language using
GNU Bison and C++. Among other things, I learned what I would do
differently. For example, I would not require variable declarations
and I would allow variables to change their type by means of
assignment. In other words, I would implement LISP-like behavior.

In addition, I would use `{' and `}' rather than `begingroup' and
`endgroup' and I wouldn't use `fi' and `endfor' to close conditional
constructions and loops, respectively.

I believe Knuth implemented things this way in order to support a
Pascal-like "structured" style of programming. In my opinion, this
idea hasn't stood the test of time. Anyone who wants to can program
in a structured manner with LISP, C, C++, or any other language that
permits comments. I don't like "nannying" languages that force a
particular style on the programmer.

> >however I didn't need it to implement loops and conditionals. If they
> >require an Abstract Syntax Tree, then I must have implemented one without
> >knowing it.
> It depends. [...]

I apologize for my flippancy. To my way of thinking, conditionals
require way of executing the "true" clause and ignoring the "false"
ones, while loops require a way of executing code repeatedly. When I
decided to implement these features, I didn't think the problems were
that difficult, and in fact, I didn't have much trouble doing it, and
they seem to work fine. I do remember having to go back and debug the
code for the conditionals, but that's par for the course. The way
I've implemented nested loops is not particularly efficient, but I
have an idea for improving it, if I ever get the chance. I didn't
think I was doing anything special or even worthy of comment. I
figured everybody did these things in more-or-less the same way.

When I get the opportunity, I will certainly look up Abstract Syntax
Trees. I do sincerely believe that basic programming skills and
common sense are the most important ingredients in solving any
programming problem; qualities that seem to have gone out of fashion
in these days of "extreme this" and "object oriented that".
Nevertheless, I don't take pride in being ignorant. If Abstract
Syntax Trees are a useful tool, I want to know about them.

Thanks again.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.