From: "Mauricio Fernández" Date: 2004-01-23T22:58:22+09:00 Subject: Re: BibTeX parser On Fri, Jan 23, 2004 at 06:27:45AM +0900, Daniel Carrera wrote: > On Fri, Jan 23, 2004 at 06:08:37AM +0900, Mauricio Fern�ndez wrote: > > > Looks like you're doing the parser by hand... > > Yes, because I am a parser-newbie and I don't know better. > > > wouldn't it be easier with, say, racc? As for the lexer [snip] > > What's racc? Do you have a link? http://i.loveruby.net/en/racc.html It's a parser generator similar to YACC (kind of de facto standard) for Ruby. > What's a lexer? Normally parsing is made in 2 steps. In the typical example of an arithmetic expression 1 + 2 the lexer would break the input into _tokens_ (syntactic atoms) type value (semantic info) NUMBER 1 OPPLUS NUMBER 2 which would be passed to the parser, that would recognize the expression according to a number of rules (productions). > Where can I learn how to make good parsers? I'd really like to do this > right. There's a billion books on this, essentially any on compiler construction. Reading such a thing would probably be overkill, and you can probably get by if you read the tutorial included in bison's .info documentation (bison is the GNU parser generator, compatible with yacc; if you understand how to use it you can make use of racc similarly). > > > mmm I guess Coco/Rb could be a good option too, since you also get a > > lexer, and LL(1) should be enough for this. > > Links for Coco/Rb? http://raa.ruby-lang.org/list.rhtml?name=coco-rb You could also try Seattle.rb's pure-Ruby port of Coco/R http://www.zenspider.com/ZSS/Products/CocoR/index.html > > Thanks for all the help! I just *knew* I was doing something wrong. > Thanks for pointing me the right direction. > > I will do a google search for "lexer", "grammar" and the other things you > mentioned and I didn't understand. But if you have good links for me I'd > love to get them. You can start here http://www.gnu.org/software/bison/manual/html_node/Language-and-Grammar.html#Language%20and%20Grammar and then proceed to the examples... Even though they're in C, they should be very helpful if you use racc later. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Beeping is cute, if you are in the office ;) -- Alan Cox