Skip to main content
gamedev.net
🔒 Locked

Writing a parser

Started by ricekrispyw 1 reply 1k views
Original Post
ricekrispyw
ricekrispyw
Hey, I was wondering if anyone can point me to some articles on the theory of parsers. I'm writing one in Java (though my "native language" is C++), and I know with the new Java 5.0, there's some helpful classes for doing this. I could write one that works, but I'd like to do it the right way. I'm sure there are some standard practices. Thanks in advance.
The best way to predict the future is to invent it.
risingdragon3
risingdragon3
any CS programming language class. You should look at parsers, NFA / DFAs, LL(1), LR, and stuff like that; this is all theory behind it. (LL(1) and LR are types of parsers that have different properties. LR can accept more languages then LL(1), because LL(1) has only one look ahead to resolve ambiguity.) For example, the dragon book (http://www.amazon.com/exec/obidos/tg/detail/-/0201100886/104-6054111-9367923?v=glance) is a good one. It's a little dated and you may want to consider something newer.
Or, if you don't want to buy a book, consider looking at lecture notes from a university. I like berkeley's 164 lecture notes, which are generally online (http://www-inst.eecs.berkeley.edu/~cs164/archives.html, many semesters of cs164). (Then again, that may be because I'm studying at berkeley.)

More practically, there are tools out there that help you generate parsers: lex, and it's variants: http://dinosaur.compilertools.net/. These take a language specification file (itself another language, which can be specified, of course, in the same language... compiler writers and programming language people love meta-compilers and self-compilation..) and generate code that creates an LL(1) or LR or whatever parser to accept the language. No work on your part.
MaulingMonkey
MaulingMonkey
Boost.Spirit is a great C++ library for parsing, from my vauge recollection of the docs they have some information on the theory as well. May be somewhat helpful :-).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.