Examples of disambiguation

In the new implementation, we decided to use the notation "x!".


The reasoning behind this is that all similar constructs in ixml are also 
postfix:


 x* zero or more
 x+ one or more
 x? zero or one
 x! zero


and prefix characters are use for marks on serialisation.


So here are some example disambiguation grammars.


IDENTIFIERS AND KEYWORDS
Each line is either an identifier or a keyword


   input: ((id; keyword), #a)*.
      id: keyword!, letter+, letter!.
-letter: [L].
keyword: ("if"; "then"; "else"), letter!.


Input
i
if
ifi
the
then
thene


Output
<input>
   <id>i</id>
   <keyword>if</keyword>
   <id>ifi</id>
   <id>the</id>
   <keyword>then</keyword>
   <id>thene</id>
</input>


MIXED CHARACTERS
Taken from the ixml tutorial, separating input characters into classes
{example input: ...abcd()1234!!!}
   input: line+.
    line: (number; word; punc)*, -#a.
  number: digit+, digit!.
    word: letter+, letter!.
    punc: p+, p!.
-letter: [L].
  -digit: ["0"-"9"].
      -p: [P].
Output
<input>
   <line>
     <punc>...</punc>
     <word>abcd</word>
     <punc>()</punc>
     <number>1234</number>
     <punc>!!!</punc>
   </line>
</input>
CODES
Each line is either a header that ends with a code, or an item that is a 
series of words.
catalogue: entry*.
     entry: header, item+.
    header: text, -" ", code, -#a.
      item: (text, " ")?, code!, word, -#a.
     -text: word**" ".
     -word: (l; d)+, (l;d)!.
     @code: l, l, l, d, d, d.
        -l: [L].
        -d: ["0"-"9"].
Input
Fiction fic001
Brave New World
1984
NonFiction non123
Translating Beaudelaire
The Sixth Extinction


Output
<catalogue>
   <entry>
     <header code="fic001">Fiction</header>
     <item>Brave New World</item>
     <item>1984</item>
   </entry>
   <entry>
     <header code="non123">NonFiction</header>
     <item>Translating Beaudelaire</item>
     <item>The Sixth Extinction</item>
   </entry>
</catalogue>
Steven

Received on Monday, 6 July 2026 15:21:46 UTC