Implementing Thompson's construction

  • Follow


Hello,

I have read the red dragon book and I understand the algorithms and
how they work. But I am not real good at turning Thompson's
construction into Cor C++ code.  I think my mental block is happening
when I try to think about how to incorporate transition and epsilon
transitions into data structures. I understand how to recursive
descent parse a regular expression and have built parse trees for the
regular expressions.  Bu there is something I just don't get.  I want
to use a lookup table for the transition characters to keep the tables
a little smaller but I don't know what to do for the nfa.

I have dissected the source for flex quite thoroughly, and I find it a
real mess but very convenient to use.  Being able to use #define for
almost anything and it works for almost anything on any platform

I want to write a dfa table out and simulate a dfa on input and use it
in a iostream for tokenizing. I don't want or need a flex scanner. Too
much power.  Too much complexity.  But maybe, I just don't understand.
My goal is to write the dfa out into spaghetti code that does the
lexical analysis from a list of regular expressions.

Mike Warehime
[You might like re2c. -John]

0
Reply mwarehime (1) 12/9/2007 11:08:49 PM

On Dec 10, 1:08 am, "Mike Warehime" <mwareh...@comcast.net> wrote:
> I have read the red dragon book and I understand the algorithms and
> how they work. But I am not real good at turning Thompson's
> construction into C or C++ code. ...

I wrote an article for GameDev some years ago about a regex engine. It
features a section on Thompson's construction, with C++ code:

http://www.gamedev.net/reference/articles/article2131.asp

0
Reply eliben 12/10/2007 7:04:05 AM


Mike Warehime wrote:
> I have read the red dragon book and I understand the algorithms and
> how they work. But I am not real good at turning Thompson's
> construction into C or C++ code.  I think my mental block is happening
> when I try to think about how to incorporate transition and epsilon
> transitions into data structures.

Hello Mike,

I would advise you the book "Compiler Construction in C" by Allen I.
Holub [Prentice-Hall Software Series], ISBN 978-0131550452. It comes
with complete source code and explains them for Lex- and Yacc-like
tools. Also my own project JS/CC [http://jscc.jmksf.com] implements
Thompson's Algorithm using the way Holub implements it.

You can even download the sources of the book at
http://www.holub.com/software/compiler.design.in.c.html .

Best regards
Jan Max
[If you do get a copy of the book, be sure also to get a copy of the
errata.  The early printings had a stupendous number of errors, many
quite serious. -John]
0
Reply mailings 12/10/2007 6:18:33 PM

2 Replies
243 Views

(page loaded in 0.006 seconds)

Similiar Articles:













7/26/2012 11:13:51 PM


Reply: