comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Text parsing package
Date: Wed, 23 Mar 2011 09:32:10 +0100
Date: 2011-03-23T09:32:10+01:00	[thread overview]
Message-ID: <v6w93r8pxrcx$.b590s9zimz0o$.dlg@40tude.net> (raw)
In-Reply-To: 4fa6c081-910a-4e62-928a-0f6cdd1da951@l18g2000yqm.googlegroups.com

On Tue, 22 Mar 2011 16:34:48 -0700 (PDT), Syntax Issues wrote:

> I have just finished a simple text parsing package.

Congratulations. What are you parsing? CSV?

> If anyone is interested I can post the code (only about 160~ lines).

Some notes to parsing techniques:

1. Don't use unbounded strings. That is an unnecessary overhead.

2. When parsing something you should have a kind of syntax error handling.
Exceptions with error location information is IMO the best choice.

3. As others have mentioned, it is a good idea to abstract the source
formats in order to be able to parse files, strings, streams etc.

4. Encoding issues is a related issue to the above. If you have that source
abstraction layer, you can deal everything Unicode, transcoding things
there and keeping the parser agnostic to encoding.

5. The state of the parser should be encapsulated in an object. Otherwise
you won't be able to reenter the parser or to make a recursively descent
one.

6. You should decide what drives the parser. In your case it is the caller.
That is not a good idea in most cases, because the caller rarely knows what
to expect next. A better choice is semantic call-backs from the parser to
the caller. Abstract primitive operations is IMO the best implementation of
such callbacks.

7. Usually parser is a middleman. It means that you should consider how to
shape the intermediate results of parsing, e.g. the AST. Ada pools are very
nice to keep that stuff in an arena.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2011-03-23  8:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-22 23:34 Text parsing package Syntax Issues
2011-03-23  3:01 ` Shark8
2011-03-23  6:29 ` Alex Mentis
2011-03-23  6:36 ` J-P. Rosen
2011-03-23  8:32 ` Dmitry A. Kazakov [this message]
2011-03-23 11:19   ` Syntax Issues
2011-03-28  0:15   ` Yannick Duchêne (Hibou57)
2011-03-28  8:15     ` Dmitry A. Kazakov
2011-03-28 10:18       ` Yannick Duchêne (Hibou57)
2011-03-28 12:08         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox