[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Type-assignment in one pass
> 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|