[ale] [OT] Writing a parser

Fletch fletch at phydeaux.org
Thu Mar 18 07:14:09 EST 2004


>>>>> "Kevin" == Kevin Krumwiede <kjkrum at comcast.net> writes:


[...]

    Kevin> The gist of what I do understand is this (and somebody
    Kevin> please tell me if I'm wrong): parsers generally take a
    Kevin> string of text and return a numeric code signifying what
    Kevin> pattern (if any) the text matches.  A program can then use
    Kevin> that code to decide how to process the text.  I assume that
    Kevin> sophisticated parsers take into account the preceding
    Kevin> context of the text when evaluating its pattern.

Actually what turns the text into tokens is the lexical analyzer
(popular programs for creating one are lex or the GNU flex).  A parser
(generated with something like yacc, bison, or byacc) then takes
tokens from the lexer and produces a parse tree from them, possibly
taking some action when certain constructs are seen.

    Kevin> I am completely lost when it comes to the input languages
    Kevin> of parser generators.  Anyone know of a good tutorial?

ORA has a book titled strangely enough _lex and yacc_ that's pretty
good; has the standard RPN calculator example.  The original yacc
paper's pretty good if you've got a BSD box or sources handy, but that
presumes probably more familiarity with parsing than you think you've
got at this point (still might be worth glancing over).  If you're
into perl check out Damian Conway's Parse::RecDescent module, which
does both lexing and parsing.  P::RD pretty easy to get something
going once you wrap your head around it..


-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U



More information about the Ale mailing list