Content model ambiguity in a schema

拜拜、爱过 提交于 2019-12-02 02:10:33

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...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!