comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Writing a scanner and parser in Ada
Date: Mon, 25 Dec 2017 20:19:27 +0100
Date: 2017-12-25T20:19:27+01:00	[thread overview]
Message-ID: <p1rivu$1d03$1@gioia.aioe.org> (raw)
In-Reply-To: 2c3f6378-1ec4-4128-ad61-a3bcdde49614@googlegroups.com

On 2017-12-25 19:57, Yves Cloutier wrote:
> On Monday, December 25, 2017 at 12:08:38 PM UTC-5, Dmitry A. Kazakov wrote:
>> On 2017-12-25 17:35, Yves Cloutier wrote:
>>
>>> Yes my Perl version does all that in 1 pass, but one of the things I
>>> want to do is have it generate for different targets. Groff was my
>>> initial one. I wan't creating any kind of AST but I think I'll want to
>>> do that in my rewrite to make things simpler and allow for generating
>>> for other targets like maybe Latex, or epub etc...
>>
>> You don't need AST for that. Simply define code generator interface
>> (tagged) with abstract operations generating pieces of code. For each
>> target have a derived type implementing these operations. Pass a
>> class-wide Target object as a parameter to the parser. If the actual is
>> of Groff_Target the result is groff etc.
>>
> haha I'm quite new to Ada so most of what you just explained I don't
> quite understand. But will get there. Baby steps.

It is not that complicated when you get into Ada's OO model. The idea is 
that you abstract away code generator (as well as the code source) fro 
the parser. Then you can use the same parser with all back-ends and all 
types of sources (file, string, stream, text-buffer etc)

> I see that you created a SNOBOL-like pattern matcher. This looks
> really useful for processing text.

Not really. Pattern matching is rarely useful. There are few cases like 
searching and skipping parts of text, partial and error-tolerant parsing 
(like in text coloring). But even then simple wildcard patterns (like * 
and %) often work better because they are easier to understand.

The rationale is this. More powerful the formal language of patterns is, 
more difficult it becomes for the user to foresee and understand what 
the pattern will match and what not. Regular expressions are already too 
complex. SNOBOL patterns are even more powerful, so that anything beyond 
trivial quickly becomes not understandable.

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


  reply	other threads:[~2017-12-25 19:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-24  1:15 Writing a scanner and parser in Ada Yves Cloutier
2017-12-24  4:07 ` Robert Eachus
2017-12-25 16:32   ` Yves Cloutier
2017-12-24  9:08 ` Dmitry A. Kazakov
2017-12-24 15:09   ` Niklas Holsti
2017-12-25 16:37     ` Yves Cloutier
2017-12-25 16:35   ` Yves Cloutier
2017-12-25 17:08     ` Dmitry A. Kazakov
2017-12-25 18:57       ` Yves Cloutier
2017-12-25 19:19         ` Dmitry A. Kazakov [this message]
2017-12-26 18:06           ` Shark8
2017-12-26 21:45             ` Dmitry A. Kazakov
2017-12-26 22:20             ` Dmitry A. Kazakov
2017-12-24 14:40 ` Tero Koskinen
2017-12-25 16:36   ` Yves Cloutier
2017-12-24 15:33 ` Lucretia
replies disabled

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