From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4cb1f8d1c17d39a8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.42.246.3 with SMTP id lw3mr12773987icb.0.1320358466058; Thu, 03 Nov 2011 15:14:26 -0700 (PDT) Path: p6ni67880pbn.0!nntp.google.com!news2.google.com!news3.google.com!feeder.news-service.com!news2.euro.net!82.197.223.103.MISMATCH!feeder3.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 03 Nov 2011 23:14:24 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada 'hello world' for Android; success! References: <8239efcjuw.fsf@stephe-leake.org> <98ca5430-aa52-4e39-b789-70d0dd6adb46@d33g2000prb.googlegroups.com> <824nyrq5p6.fsf@stephe-leake.org> <4eac1ca1$0$7625$9b4e6d93@newsspool1.arcor-online.net> <82mxciogt0.fsf@stephe-leake.org> <4eafbc25$0$6575$9b4e6d93@newsspool3.arcor-online.net> <82mxcemscg.fsf@stephe-leake.org> <4eb1e241$0$7627$9b4e6d93@newsspool1.arcor-online.net> <8239e5mo9q.fsf@stephe-leake.org> In-Reply-To: <8239e5mo9q.fsf@stephe-leake.org> Message-ID: <4eb31240$0$6549$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 03 Nov 2011 23:14:24 CET NNTP-Posting-Host: 09ebebb7.newsspool4.arcor-online.net X-Trace: DXC=[IYW\12Wng5LNKYb?b>0764IUKejV8VOY`hm<_F92Qh]cBFIQSo> X-Complaints-To: usenet-abuse@arcor.de Xref: news2.google.com comp.lang.ada:14299 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2011-11-03T23:14:24+01:00 List-Id: 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.)