comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Ada 'hello world' for Android; success!
Date: Thu, 03 Nov 2011 23:14:24 +0100
Date: 2011-11-03T23:14:24+01:00	[thread overview]
Message-ID: <4eb31240$0$6549$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <8239e5mo9q.fsf@stephe-leake.org>

On 03.11.11 12:36, Stephen Leake wrote:

> In my opinion, this recursive descent style is much harder to
> understand. In particular, it is very difficult to see that the program
> structure matches the grammar structure.

Yes, recursion does take getting used to.  I am sketching a generator
that will remove the burden of writing the recursive subprograms.
Its input will be compatible with OpenToken's operator based notation.
Currently, the interesting part looks like the following. This is
just exploring ideas, there is no real business going on.
(The usual suspects like proper lexical scanning, generating tokens,
etc., might be compatible.)

with Tokens,  -- tokens, and lists of tokens
       Rules;   -- productions, and lists of productions
with Templates;   -- what should a recursive subprogram look like

procedure Generate_Recursive_Descent is

    ------------------------------------------------------------------------
    --  "Define the Grammar productions.
    --
    --  "The text in the example in the book looks something like:
    --
    --  S' -> S
    --  S  -> L = R | R
    --  L  -> * R | id
    --  R  -> L"
    --

    type Token_ID is (S_Prime_Nonterminal,
                      S_Nonterminal,
                      L_Nonterminal,
                      R_Nonterminal);

    package Example_Tokens is new Tokens (Token_ID);
    package Example_Rules is new Rules (Example_Tokens);
    package Writers is new Templates (Example_Tokens);

    S_Prime : Example_Tokens.Nonterminal(S_Prime_Nonterminal);
    S : Example_Tokens.Nonterminal(S_Nonterminal);
    L : Example_Tokens.Nonterminal(L_Nonterminal);
    R : Example_Tokens.Nonterminal(R_Nonterminal);

    Asterisk : Example_Tokens.Terminal
        (Name => new String'("Asterisk"),
         Match => '*');

    ID : Example_Tokens.Terminal
        (Name => new String'("id"),
         Match => 'I');

    Equals :  Example_Tokens.Terminal
        (Name => new String'("EQ"),
         Match => '=');

    use Example_Rules;  -- operators

    Example : constant Example_Rules.Grammar := Example_Rules.Null_Grammar and
        S_Prime <= S and
        S       <= L & Equals & R and
        S       <= R and
        L       <= Asterisk & R and
        L       <= ID and
        R       <= L;

    procedure Produce_Subprograms (Position: Lists_of_Rules.Cursor);

That is it, if one of the parsing models and Templates is acceptable
for the hypothetical programmer.


> Perhaps we should
> put both on the Ada Programming Wikibook somewhere?

It might be a starting point, although I'd prefer more generally relevant,
stripped down topics. For example the design pattern of delegation and its
consequences, or the meaning of distributed overhead of design choices:
show classical opposites, such as passive vs active, call vs callback,
Iterate vs for-loop, assignment-then-loop vs new-parameter-then-recursion,
heap allocation vs automatic objects etc.

If parsers can be stripped to the minimum matching one such subject,
they should serve as good examples? (Surely my example would need
overhaul, and polishing.)





  parent reply	other threads:[~2011-11-03 22:14 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-27  1:18 Ada 'hello world' for Android; success! Stephen Leake
2011-10-27  7:12 ` Alex R.  Mosteo
2011-10-28 12:51   ` Stephen Leake
2011-10-27 10:50 ` Jeffrey Creem
2011-10-28 13:01   ` Stephen Leake
2011-10-27 10:58 ` Brian Drummond
2011-10-28  1:37 ` Shark8
2011-10-28 12:22 ` Anatoly Chernyshev
2011-10-29 13:37   ` Stephen Leake
2011-10-29 14:46     ` Anatoly Chernyshev
2011-10-29 20:47       ` Brad Moore
2011-10-29 21:59         ` Anatoly Chernyshev
2011-10-30  3:51           ` Brad Moore
2011-10-30  7:20             ` Anatoly Chernyshev
2011-10-30 10:56       ` Stephen Leake
2011-10-30 17:32         ` Brad Moore
2011-10-29 15:32     ` Georg Bauhaus
2011-10-29 16:09       ` Simon Wright
2011-10-29 17:32         ` tmoran
2011-10-30 11:38           ` Stephen Leake
2011-10-29 20:51         ` Brad Moore
2011-10-30 11:32       ` Stephen Leake
2011-10-31 22:34         ` Randy Brukardt
2011-11-01  8:41           ` Stephen Leake
2011-11-01  9:30         ` Georg Bauhaus
2011-11-02 15:55           ` Stephen Leake
2011-11-02 17:37             ` Robert A Duff
2011-11-08  3:56               ` Randy Brukardt
2011-11-03  0:37             ` Georg Bauhaus
2011-11-03 11:36               ` Stephen Leake
2011-11-03 15:24                 ` Robert A Duff
2011-11-03 18:43                   ` Pascal Obry
2011-11-03 22:14                 ` Georg Bauhaus [this message]
2011-11-04  8:48                   ` Dmitry A. Kazakov
2011-11-04 12:18                   ` Stephen Leake
2011-11-04 15:03                     ` Georg Bauhaus
2011-11-05 16:56                       ` Stephen Leake
2011-11-01  9:52         ` Dmitry A. Kazakov
2011-11-02 15:59           ` Stephen Leake
2011-11-02 16:27             ` Dmitry A. Kazakov
2011-11-02 17:38               ` Simon Wright
2011-11-10 17:25 ` Stephen Leake
2011-11-27 15:18 ` mockturtle
2011-11-28 22:35   ` Ada 'hello world' for Android; success! (but music player failure) Stephen Leake
2011-11-29 11:23     ` Georg Bauhaus
2011-11-30  3:33       ` Stephen Leake
2011-11-30 18:57         ` Georg Bauhaus
replies disabled

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