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: Fri, 04 Nov 2011 16:03:28 +0100
Date: 2011-11-04T16:03:29+01:00	[thread overview]
Message-ID: <4eb3fec1$0$6558$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <82ty6kkrnc.fsf@stephe-leake.org>

On 04.11.11 13:18, Stephen Leake wrote:

> In current OpenToken, we have 'procedure Parse' instead of 'procedure
> Produce_Subprograms'; the rest is the same. I gather
> 'Produce_Subprograms' generates Ada code, that must then be compiled.

Yes.

> I'm not clear what the benefit of this is over the current OpenToken
> approach.

Meant only to be a possible alternative, its implementation is trivial,
and it automatically reuses mechanisms such as a stack that
a traditional computer features as a built-in. :-)

The given method is exhaustive, if that's needed, it's there.
If there are no loops in the grammar itself (such as left recursion),
then the length of input determines the number of recursive
calls for this method, too, so use of stack space has a known
maximum.

From a programmer's perspective, the method shown will pass tokens
to handlers. Writers of SAX style content handlers will recognize
the scheme and find it familiar, I think.

Following are some ideas that I would find fairly easy to add
to the resulting parsers, to make them more useful, more efficient,
or even more powerful.
Are they equally easy to add to, for example, bottom up parsers?

1. A simple extension, using functions as subprograms, allows more
control: Start another rule (call another subprogram) only if the
previous one (a function) has returned False. IOW, parsing does
not need to be exhaustive.  (A variation can use non-local
transfer of control, i.e. exception handlers added to subprograms
where desired.)
<hack>Let r be the return value, then f(r) is the next rule.
Assumption: this choice is not to be determined by the grammer
alone if modeling it accordingly would be awkward.</hack>

2. Or keep some state information along the way that can be
queried for (pseudo-)context, making the grammar less static,
and react to input:  Only if rule R (m) has hit token T (j)
before, assume that the parser should now choose rule R (k).
The conditionals would be added to the generated code,
thus specializing the parsing process. OK, a.k.a hacking.
But see "Fence", next.

3. Or introduce pseudo-symbols such as "Fence" that have no
meaning in the language but will have an effect on backtracking:
backwards motion stops at a "Fence".
  (Another possible pseudo-symbol is "User-Input".)

4. One can use (or misuse?) the mechanism to perform lexical
scanning. A first run produces tokens from a sub-grammar describing
the language in terms of lexemes only.

The basic mechanism never changes, and the number of topics
from which the parsers' logic can be understood is, I think,
pleasantly small.



  reply	other threads:[~2011-11-04 15:04 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
2011-11-04  8:48                   ` Dmitry A. Kazakov
2011-11-04 12:18                   ` Stephen Leake
2011-11-04 15:03                     ` Georg Bauhaus [this message]
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