23.11.2014 Views

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

2006 Scheme and Functional Programming Papers, University of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A(r{0, 0}):<br />

✓✏ɛ<br />

✓✏ ✎☞<br />

> p ✲ q<br />

✒✑push [ ] ✒✑ ✍✌<br />

ɛ<br />

✓✏<br />

> p ❅ ✓✏<br />

push [ ]<br />

✎☞<br />

❅❘ q<br />

✒✑❅ ɛ ✎☞ ✎☞ ɛ<br />

✲ p 1 A(r) q 1 ✒ ✒✑ ✍✌<br />

cons ✍✌ ✍✌ ✻<br />

push [ ]<br />

ɛ<br />

· · · ✛<br />

A(r{0, j}):<br />

cons<br />

(where j ≥ 1)<br />

✎☞ ✎☞ ɛ<br />

✲ p k A(r) q k ✲<br />

✍✌ ✍✌push [ ]<br />

ɛ<br />

· · · ✛<br />

cons<br />

✎☞ ✎☞ ɛ<br />

✲ p j A(r) q j<br />

✍✌ ✍✌push [ ]<br />

A(r{i, j}): (where i ≥ 1)<br />

✓✏ɛ<br />

✎☞ ✎☞ ɛ ✎☞ ✎☞ ɛ ✓✏ ✎☞<br />

> p ✲ p 1 A(r) q 1 ✲ · · · ✲ p i A(r) q i ✲ q<br />

✒✑cons<br />

✍✌ ✍✌ cons ✍✌ ✍✌push [ ] ✒✑ ✍✌<br />

ɛ<br />

· · · ✛<br />

✻<br />

cons<br />

✎☞ ✎☞ ɛ<br />

✲ p k A(r) q k ✲<br />

✍✌ ✍✌push [ ]<br />

ɛ<br />

· · · ✛<br />

cons<br />

✎☞ ✎☞ ɛ<br />

✲ p j A(r) q j<br />

✍✌ ✍✌push [ ]<br />

A(r 0 . . . r n−1): (where n ≥ 2):<br />

✓✏ɛ<br />

✎☞ ✎☞ ɛ ✎☞ ✎☞ ɛ ✓✏ ✎☞<br />

> p ✲ p 1 A(r<br />

✒✑cons<br />

✍✌ 0) q 1 ✲ · · · ✲ p n A(r<br />

✍✌ cons ✍✌<br />

n−1) q n ✲ q<br />

✍✌push [ ] ✒✑ ✍✌<br />

A(r 0 | . . . | r n−1):<br />

(where n ≥ 2)<br />

ɛ ✎☞ ✎☞<br />

✲<br />

✓✏<br />

sel 0 ✍✌<br />

p 1 A(r 0) ✍✌<br />

q ɛ<br />

1<br />

> p <br />

❅ ✓✏<br />

✎☞<br />

.<br />

❅❘ q<br />

✒✑❅ ɛ ✎☞ ✎☞ɛ<br />

❅ ✲ p n A(r<br />

sel n − 1 ✍✌<br />

n−1) q n ✒ ✒✑ ✍✌<br />

✍✌<br />

Figure 5. Construction rules for the automata with comm<strong>and</strong>s (Part II).<br />

non-deterministic states, each on behalf <strong>of</strong> its corresponding rule.<br />

In such a case, the deterministic state accepts on behalf <strong>of</strong> the<br />

rule that has highest priority. The non-deterministic path P N that<br />

corresponds to P D is recovered backwards portion by portion. The<br />

idea consists in determining non-deterministic states {q i} 0≤i≤n<br />

<strong>and</strong> portions <strong>of</strong> path {P i} 0≤i≤n such that: each q i is in s i; each P i<br />

starts at q i−1, ends at q i, <strong>and</strong> consumes c i−1, except for P 0, which<br />

starts at the non-deterministic start state, ends at q 0, <strong>and</strong> consumes<br />

ɛ; q n is a state that accepts on behalf <strong>of</strong> the same rule as s n.<br />

The recovery is initialized by determining q n directly from s n<br />

using the query Acc(s n). Next, the main part <strong>of</strong> the recovery consists<br />

in an iteration, with i going from n down to 1. At step i,<br />

given q i, one can determine portion <strong>of</strong> path P i <strong>and</strong> intermediate<br />

non-deterministic state q i−1. P i is obtained from the query<br />

f(s i−1, c i−1, q i). By doing so, q i−1 is also obtained as it is the<br />

source state <strong>of</strong> P i. As the final part <strong>of</strong> the recovery, P 0 is obtained<br />

using the query g(q 0). Then path P N is simply the linkage <strong>of</strong> all<br />

the portions together; i.e. P N = P 0 · . . . · P n.<br />

Note that the preceding explanation contains some minor inaccuracies.<br />

First, tables f <strong>and</strong> g do not exactly contain portions <strong>of</strong><br />

path but reversed ones. Indeed, recall that the NFA presented in<br />

this paper are such that comm<strong>and</strong>s must be executed in the order<br />

in which they are met when following paths backwards. Second,<br />

there is no need to recover path P N (or its reverse) explicitly. It<br />

is sufficient to keep references to the portions that form P N <strong>and</strong><br />

to later execute the comm<strong>and</strong>s by following the portions one after<br />

the other. Better yet, one may eagerly execute the comm<strong>and</strong>s<br />

contained in each portion as the latter gets determined. This way,<br />

it is unnecessary to remember P N nor its portions. Only the current<br />

state <strong>of</strong> the construction stack needs to be preserved. Last, one<br />

may observe that the sole purpose <strong>of</strong> the portions <strong>of</strong> path stored in<br />

tables f <strong>and</strong> g is to be followed in order to recover the parse tree<br />

<strong>Scheme</strong> <strong>and</strong> <strong>Functional</strong> <strong>Programming</strong>, <strong>2006</strong> 57

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!