Jump to content
  • Advertisement
Sign in to follow this  
CodeMachine

Compiler Design - Lexical & syntactical analysis

This topic is 4187 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all I have a compiler construction question for you. I wonder if anyone can recommend good tutorials/webpages/books that explain how to create a lexical & syntactical analyser (scanner)? I know there are several free tools for this such as Lex, Flex, Bison etc, but I want to develop one myself. Otherwise I do not learn how to implement this. ;) Thank you folks

Share this post


Link to post
Share on other sites
Advertisement
lex, yacc, flex, bison, ocamlyacc, ocamllex and menhir (to cite only a few) are open source and well-documented. Taking a peek at the source code and documentation would be an excellent learning experience.

Share this post


Link to post
Share on other sites
Hi Fred

Do you mean this book:
http://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811/ref=pd_lpo_k2_dp_k2a_1_img/002-3598064-9116857

Share this post


Link to post
Share on other sites
I would pick up the first edition of the Dragon Book instead. Most of the changes for the second edition were to do with optimizations and more in depth topics. The chapters on lexing and parsing were mostly the same. Seeing as Amazon has that one for $6, it'd be good deal.

Share this post


Link to post
Share on other sites
Ok, so the first or second edition of the dragon book makes no difference.

It's the most recommended book then if you want to learn how to build a compiler?

Share this post


Link to post
Share on other sites
Quote:
Original post by CodeMachine
Hi all
I have a compiler construction question for you.

I wonder if anyone can recommend good tutorials/webpages/books that explain how to create a lexical & syntactical analyser (scanner)?

I know there are several free tools for this such as Lex, Flex, Bison etc, but I want to develop one myself. Otherwise I do not learn how to implement this. ;)

Thank you folks


Ok I've done this for 2 years and this is my personal recommendation. The best *overall* book (and yes I know... Blasphemy!) is *not* the Dragon book. The Dragon book is very unfriendly to someone implementing a compiler and is very VERY theory driven. The best book IMHO is "Compiler Design in C" by Allen Holub. The source can be downloaded for free from here : http://www.holub.com/software/compiler.design.in.c.html

It very effectively mixes the theory *with* the application and is thus drastically more usable than the paperweight Dragon book. Also, believe it or not, I wrote a compiler and interpreter (very elementry one but it is a compiler nonetheless) from the Deitel and Deitel book "C: How To Program". They have a series of exercises in the end of the chapters that give enough information to get you started without removing the fun of figuring out the implemetation yourself and provides a good starting point to go deeper into this topic.

I actually did exactly this and then read the Dragon book for about 2 years until it got into compiler compilers where I wanted to gouge my eyes out with pickaxes! Not a recommended path to glory...

Share this post


Link to post
Share on other sites
i'll recommend the dragon book as well, 2nd edition. however, if you get that one, i'd also recommend getting another book on automata and grammars, as the coverage of them in the dragon book, such as subset construction and DFA state minimization, is blah. another thing i was pissed off about this book is that there is a lot of errors (especially in the code listings and algorithm descriptions... i remember pg. 224 Algorithm 4.31 really pissed me off) he he he. make sure you download the errata for this book!

i also liked this book too. it doesn't talk about lex and yacc as much as the aho book does, and it covers automata much better (like how to code them).

Share this post


Link to post
Share on other sites
Ok, so the recommended books (if you want to learn how to build a parser), are "Engineering a Compiler" and "Compiler Design in C" then.

Is an AST to recommend if you want to implement editor-intellisense?

Share this post


Link to post
Share on other sites
an ast is mainly for translating your code into psuedo-assembly... err... three-byte code or three-address code something like that he he he which i think goes into your OBJ file (if my memory serves me correct it's been a while). it can also be used for type-checking/conversion and stuff. it's really cool stuff. i think the symbol table is what you're thinking is good for intellisense... it keeps track of the variables and function identifiers, what parent scope they're in and such...

[Edited by - yadango on June 25, 2007 3:51:00 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!