Writing a compiler
I basically need to make a compiler for bibtex files, such that a given bibtex database can be queried. Now I'm familiar with certain aspects of theory, like automata, grammars, SLR,LR(1) and LALR parsing. However, I still find all of that theoretical and 开发者_Python百科abstract, since I've never applied it. It would help a lot if someone could outline the solid steps required to build a compiler. I'll be using flex and bison/yacc probably, so if you could let me know how exactly the design process goes, what files are generated at what stage, what is the output at each stage, and in general how things tie together, I can probably get a more practical view of how things are done...
Thanks!
Are you sure you want to compile a bibtex database into something executable? If querying is the only thing you want, than it will make more sense to translate a bibtex database into a relational one, and query it with SQL. Of course you still have to parse bibtex first, and generate a SQL code out of it, and some will call it "compiling", but it is far less complicated than the stuff in the already mentioned Dragon Book.
Bibtex syntax is extremely trivial, so you can choose any parsing approach. I would not even bother using parser generators for such a trivial grammar, and will jot a recursive descent parser instead. Depending on the language of your choice, it can be really easy (e.g., if you're using Haskell with Parsec, or even a C#).
If your additional goal is to learn the outdated tools like bison and flex, then, of course, they'll do the job too, but it is an overkill.
Edit: the best practical reading on the classic lex/yacc approach is http://en.wikipedia.org/wiki/The_Unix_Programming_Environment
I am not a compiler expert but I do know that this book is actually regarded as necessary reading for anyone that wants to write a compiler. Yes the cover is antiquated but from what I have read it still has many good patterns relevant to code compilation:
http://www.amazon.com/Compilers-Principles-Techniques-Alfred-Aho/dp/0201100886
精彩评论