Exercise 9      Name       ____________________   Points __/25

Document last modified: 
 

<!ELEMENT exp ( (exp, plus, exp) | (exp, times, exp) | (lparen, exp, rparen) | a | b | c )>

  1. (9) For the above EBNF DTD give the parse trees for the following XML.

    i. a + b

    <exp>
        <exp><a/></exp>
        <plus/>
        <exp><b/></exp>
    </exp>

    ii. a * b + c

    <exp>
        <exp>
            <exp><a/></exp>
            <times/>
            <exp><b/></exp>
        </exp>
        <plus/>
        <exp><c/></exp>
    </exp>

    iii. (a + b) * c

<exp>
    <exp>
        <lparen/>
        <exp>
            <exp><a/></exp>
            <plus/>
            <exp><b/></exp>
        </exp>
        <rparen/>
     </exp>
    <times/>
    <exp><c/></exp>
</exp>

  1. (6) Give the XML for the following using the definition of exp above:
    1. a * (b + c)
    2. (a + b) * (b + c)

     

     

    <!ELEMENT digit (zero | one | two | three)>
    <!ELEMENT unsigned (digit+)>                                            Iterative
    <!ELEMENT unsigned (digit | (unsigned, digit))>                    Recursive
    <!ELEMENT signed ((plus, unsigned) | (minus, unsigned))>
    <!ELEMENT plus EMPTY>
    <!ELEMENT minus EMPTY>
    <!ELEMENT zero EMPTY>
    <!ELEMENT one EMPTY>
    <!ELEMENT two EMPTY>
    <!ELEMENT three EMPTY>

     

  2. (6) Complete the above DTD of a grammar with the following rules:
    1. <integer> as the set of all strings of <signed> or <unsigned>.
    2. <decimal> as the set of all strings of <integer> followed by a ‘.’ and optionally followed by an <unsigned>.
    3. <twoorthreedigits> as the set of all strings of two or three <digit>.

     

  3. (4) The following is XML for an <unsigned> 123:

    <!DOCTYPE unsigned SYSTEM "ex9.dtd">                 Using iterative
        <unsigned>
            <digit>
                <one/>
            </digit>
            <digit>
                <two/>
            </digit>
            <digit>
                <three/>
            </digit>
        </unsigned>

    <!DOCTYPE unsigned SYSTEM "ex9.dtd">                 Using Recursive
    <unsigned>
        <unsigned>
            <unsigned>
                <digit><one/></digit>
            </unsigned>
            <digit><two/></digit>
         </unsigned>
         <digit><three/></digit>
    </unsigned>

    1. Give the XML for a <signed> +123.
    2. Give the XML for a <decimal> -12.4.