Re: extract config file's tokens: need advice on algorithm
- From: "Rob Thorpe" <robert.thorpe@xxxxxxxxxxxx>
- Date: 20 Jan 2006 01:34:35 -0800
Roman Mashak wrote:
> Hello, All!
>
> I have to parse 'named' config file (DNS server). For those who don't know
> of it, its structure looks like this:
>
> # comment
> <statement> {
> <option>;
> <options>;
> ...
> };
>
> There are a number of statements, but I'm interested in one only:
>
> zone "name_of_zone" {
> <zone_options>;
> ...
> };
>
> So what I want is some pretty fast algorithm (right now size is small, but
> it's gonna grow up quickly) running through this file, and return TRUE if
> "name_of_zone" found, FALSE otherwise.
That doesn't look too hard. From what you say the language is
something like
file = {expression || comment}*
comment = # everything-until-end-of-line
expression = statement-part '{' option-list '}' ';'
statement-part = statement argument
option-list = {option ';'}*
There seem to be several types of token, say
LBRACE == {
RBRACE == }
SEMI == ;
STRING == "something"
IDENTIFIER == zone etc
I would firstly make a lexer to read the above tokens either by hand or
with something like flex. I'd kill comments in the lexer. I would
then write a recursive descent parser to read the above grammar, which
means fairly much writing a subroutine corresponding to each BNF line
above. Doing it this way should be very fast.
There are plenty of sources on the web for writing lexer and writing
recursive descent parsers. You may be tempted to do it in an ad-hoc
way, I would avoid that, ad-hoc parsing code is harder to debug than
parsing code written in the normal structured way.
Since 'named' is quite a common file to parse I expect you will be able
to find code to do it on the internet.
.
- Follow-Ups:
- Re: extract config file's tokens: need advice on algorithm
- From: Rob Thorpe
- Re: extract config file's tokens: need advice on algorithm
- References:
- extract config file's tokens: need advice on algorithm
- From: Roman Mashak
- extract config file's tokens: need advice on algorithm
- Prev by Date: Re: induction
- Next by Date: why doesn't work ?? [win32 C++]
- Previous by thread: extract config file's tokens: need advice on algorithm
- Next by thread: Re: extract config file's tokens: need advice on algorithm
- Index(es):
Relevant Pages
|