[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Type-assignment in one pass

  • From: "K.Kawaguchi" <k-kawa@b...>
  • To: Norman Walsh <ndw@n...>
  • Date: Thu, 01 Feb 2001 15:21:27 -0800

width first search

> I'm a little confused by this example. I would have thought that the
> validator had to look ahead anyway in this case.

No, without any lookahead, validator can know the document is valid.

> to see if you've got the last y, how can you pick the matching
> definition?

Let me show you. To simplify the pattern, I'll use pseudo-TREX pattern.


<element name="x" label="x">
  <zeroOrMore>
    <element name="y" label="y1">
      <attribute name="z" type="xsd:string" />
    </element>
  </zeroOrMore>
  <element name="y" label="y2">
    <attribute name="z" type="xsd:integer" />
  </element>
</element>

Consider validating the following fragment with this pattern:

<x> <y z="1" /><y z="2" /><y z="3" /> </x>


1. When the validator see startElement(<y z="1">), it can see the two
possibilities, as "y1" and "y2". So it remembers both.

"y1"
"y2"

2. When it sees endElement(</y>). Both of the choice work. So again keep
both of them.

"y1" -- "<endtag>"
   (no child)

"y2" -- "<endtag>"
   (no child)

3. When it sees startElement(<y z="2">), it knows that the second
interpretation doesn't work any more. but the first thread has two
choices. So remember the both choice.

"y1" -- "<endtag>" -+- "y1"
   (no child)       |
                    +- "y2"

"y2" -- "<endtag>" --- X
   (no child)

If you link these interpretations by backward references and you have
garbage collection, simply remember the last set of choice. Dead
interpretation will be automatically collected by GC. Of course
reference counting works, too.


4. ...

5. When it sees startElement(<y z="3">), again it abandons one
interpretation, and find two options.


"y1" -- "<endtag>" -+- "y1" -- "<endtag>" -+- "y1"
   (no child)       |                      |
                    |                      +- "y2"
                    |
                    +- "y2" -- "<endtag>" --- X

"y2" -- "<endtag>" --- X
   (no child)

6. ...

7. When it sees endElement(</x>), now it sees the first thread is dead.


"y1" -- "</>" -+- "y1" -- "</>" -+- "y1" -- </> -- X
    (nc)       |      (nc)       |      (nc)
               |                 +- "y2" -- </> -- </>
               |                        (nc)
               +- "y2" -- "</>" --- X
                      (nc)
"y2" -- "</>" --- X
    (no child)


So, after GC the only interpretation left is

"y1" -- "</>" -+- "y1" -- "</>" -+- "y2" -- </> -- </>

and hey, it's the interpretation that works.


All of this process has done without any lookaheads. In other words, if
you want depth-first search, you need lookaheads. If you choose
width-first search, you don't.


regards,
----------------------
K.Kawaguchi
E-Mail: k-kawa@b...


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.