Content model ambiguity in a schema

后端 未结 1 961
有刺的猬
有刺的猬 2021-01-23 02:32

Maybe I\'ve been staring at this problem for too long, maybe there isn\'t an answer; either way I\'m here now.

I\'m trying to permit a set of possible combinations in an

相关标签:
1条回答
  • 2021-01-23 02:55

    IIRC there is a theorem in computer science that says every ambiguous grammar can be rewritten as an unambiguous grammar, so start with the hypothesis that it's possible. However, the unambiguous grammar can sometimes be hideously complex.

    I think a good approach to handling this is to draw the "railroad diagram" of the grammar, that is, the finite state machine with its transitions. Then when you find a state in this machine that has two transitions labelled with the same symbol, you need to construct a new state that accepts both those transitions, and so on. In the CS literature this algorithm is called "determinization".

    Another approach which is perhaps easier to explain without a whiteboard is to start by factoring out what is common between the two branches of your choice. When you hit the first element in the content, it has to be either a bar or a baz. So write two choices, one starting with bar and one with baz.

    As far as I can see, your content model is euiqvalent to the unambiguous model

    (bar, (baz+, qux*)?) | (baz+, qux*)
    

    but I would check that carefully...

    0 讨论(0)
提交回复
热议问题