You are not logged in.

#1 2005-08-29 21:45:24

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

parsers/lexers

I've had absolutely no experience with yacc/lex/flex/bison/et al, and would like to do some things with them - does anyone know any good tutorials or books which would aid me?

This is probably the best reference so far:
http://dinosaur.compilertools.net/

However, there's alot of info there, and I don't really need all that much.

Offline

#2 2005-08-29 22:06:42

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: parsers/lexers

the dragon book is THE book when it comes to compiler theory, lexers, parsers.
http://catb.org/~esr/jargon/html/D/Dragon-Book.html

I had another book when i took compiler theory, and it was *ok*. I cant remember the name of it offhand. It delved into lalr parser generation quite a bit..as well as a considerable amount of automata theory. Automata is heavily used for state transition analysis.. basically you construct a nfa, perform nfa reduction/simplification, then produce a dfa. The dfa is used as an aid in determining the states your compiler can be in.
Add in BNF language notation for defining the tokens and language constructs too.
w00t! Good times.

mix in a little theory of computation, and you have a considerable nerd factor.
wink


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#3 2005-08-29 22:13:22

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: parsers/lexers

cactus wrote:

the dragon book is THE book when it comes to compiler theory, lexers, parsers.
http://catb.org/~esr/jargon/html/D/Dragon-Book.html

Nice book, however, I'm not looking for compiler theory - I require some complex logic to parse some config files properly, so I just wanted to run it through lex/yacc (I guess I could parse it by hand).  I'm pretty sure I have the grammer down, but I don't fully understand the workings of lex and yacc and *how* they do what they do.

So, to be a bit more specific: I'm looking for info on the actual tools themselves..

Offline

#4 2005-08-29 22:42:50

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: parsers/lexers

Hmmm for the record, http://spirit.sourceforge.net/ looks interesting - I've heard of it before (it's a spawn of the boost libraries), but never looked into it.

It seems like what I need - i.e. I don't need maximum performance, just simplification of the parsing.

Cool thing about it is that it's written in such a way so that the grammer and code are one and the same

Example: real_p is a predefined "real parser" - for real numbers (floating point)

bool
    parse_numbers(char const* str)
    {
        return parse(str, real_p >> *(',' >> real_p), space_p).full;
    }

The grammer is "real_p >> *(',' >> real_p)" (I'm guessing the "space_p" parser is when to stop, or possibly what to ignore...).

real_p >> *(',' >> real_p) translates to the following regex:
[0-9.](,[0-9.])*

Kinda neat... I hope is isn't as ungainly as boost is to work with, otherwise I may opt out of it....

Offline

#5 2005-08-29 22:43:29

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: parsers/lexers

lex & yacc from O'Reilly http://www.oreilly.com/catalog/lex/desc.html

I have other books from the same series and they are very good.

Offline

Board footer

Powered by FluxBB