Compilers - Am I writing one?

Michael Torrie torriem at gmail.com
Mon Jun 30 09:58:57 MDT 2008


Hans Fugal wrote:
> In which way? They take ascii art as input? I had no trouble with the 
> syntax diagrams in 431, but I found them hard to work with. I couldn't 
> send one by email easily. I had to have a PDF viewer and scan through 
> dozens of pages of diagrams (we know how much fun that can be) or lug 
> the large book (which I printed out at Kinkos) around. I decided to 
> write my own parser generator, and so I had to enter all those diagrams 
> into BNF format (which seemed like a reasonable machine-readable 
> choice), and while tedious I don't remember it being difficult. In fact, 
> I seem to remember very quickly finding a few patterns, and converting 
> to BNF was primarily a rote exercise.

Good point.  I presume from a casual googling that ANTLR must have some
notation that allows one to easily define a syntax diagram using some
notation.  I would guess (and that's all it is) that the syntax would be
similar to how PyParsing defines a grammar.  Easy ways to say "one or
more" or "zero or more," for example.  Given that format it is just as
clear and easy to run through a parser generator as BNF.

I am curious about your easy rote exercise to create BNF from a syntax
diagram.  How do you do it?  How do you properly convert an iterative
diagram into the recursive productions that BNF requires?  It's not
always correct to convert an iterative production into right-recursive
format, yet left-recursive is problematic.  How do you deal with this?

Michael




More information about the PLUG mailing list