SLIDE 11 Input: DOM Tree for T, a tree grammar G = (N, , S, P), NT is a stack of strings of sets of non-terminals R is a stack of sets of production rules NS is a stack of sets of non-terminals, init with S Traverse T in a depth-first, left-2-to-right manner When an element E is visited on way down, set RS to the set of production rules N a e in P with a = E’s tag name and (N occurs in topmost set of NS) if RS is non-empty then push RS onto R, push onto NT, push set of all non-terminals occurring in RHS of a rule in RS to NS else report “not accepted” and stop
When an element E is visited on way up, pop a rule set RS = {Ni a ei | i = 1..k} out of R pop a string of sets of non-terminals W1...Wk out of NT set W to the set of those Ni such that there is a w1...wk with each wj from Wj that matches ei if W is non-empty then pop a string V1...Vm of non-terminals out of NT push V1...VmW onto NT, pop NS else report “not accepted” and stop report “accepted” and stop
41
ValAlgo XML doc/Tree any tree Grammar G “yes”, if T “no”,
store non-terminals from RHS
- f possibly applicable rules
- Let’s see how algorithm works:
– G = ({A,B,C},{a},{A,B,C},P) with P = { A a B|, B a (C,C), C a (A,A,A)|}
42
a a R NT ValAlgo XML doc/Tree any tree Grammar G “yes”, if T “no”,
When an element E is visited on way down, set RS to the set of production rules N a e in P with a = E’s tag name and (N occurs in topmost set of NS) if RS is non-empty then push RS onto R, push onto NT, push set of all non-terminals occurring in RHS of a rule in RS to NS else report “not accepted” and stop When an element E is visited on way up, pop a rule set RS = {Ni a ei | i = 1..k} out of R pop a string of sets of non-terminals W1...Wk out of NT set W to the set of those Ni such that there is a w1...wk with each wj from Wj that matches ei if W is non-empty then pop a string V1...Vm of non-terminals out of NT push V1...VmW onto NT, pop NS else report “not accepted” and stop report “accepted” and stop
NS {A,B,C} a a a a a
- Let’s see how algorithm works:
– G = ({A,B,C},{a},{A,B,C},P) with P = { A a B|, B a (C,C), C a (A,A,A)|}
43
a a R NT ValAlgo XML doc/Tree any tree Grammar G “yes”, if T “no”,
When an element E is visited on way down, set RS to the set of production rules N a e in P with a = E’s tag name and (N occurs in topmost set of NS) if RS is non-empty then push RS onto R, push onto NT, push set of all non-terminals occurring in RHS of a rule in RS to NS else report “not accepted” and stop When an element E is visited on way up, pop a rule set RS = {Ni a ei | i = 1..k} out of R pop a string of sets of non-terminals W1...Wk out of NT set W to the set of those Ni such that there is a w1...wk with each wj from Wj that matches ei if W is non-empty then pop a string V1...Vm of non-terminals out of NT push V1...VmW onto NT, pop NS else report “not accepted” and stop report “accepted” and stop
NS {A,B,C} {A,B,C} a a a a a
RS = {, , } NS {A,B,C} {A,B,C}
- Let’s see how algorithm works:
– G = ({A,B,C},{a},{A,B,C},P) with P = { A a B|, B a (C,C), C a (A,A,A)|}
44
a a R NT ValAlgo XML doc/Tree any tree Grammar G “yes”, if T “no”,
When an element E is visited on way down, set RS to the set of production rules N a e in P with a = E’s tag name and (N occurs in topmost set of NS) if RS is non-empty then push RS onto R, push onto NT, push set of all non-terminals occurring in RHS of a rule in RS to NS else report “not accepted” and stop When an element E is visited on way up, pop a rule set RS = {Ni a ei | i = 1..k} out of R pop a string of sets of non-terminals W1...Wk out of NT set W to the set of those Ni such that there is a w1...wk with each wj from Wj that matches ei if W is non-empty then pop a string V1...Vm of non-terminals out of NT push V1...VmW onto NT, pop NS else report “not accepted” and stop report “accepted” and stop
NS {A,B,C} {A,B,C} a a a a a
RS = {, , } NS {A,B,C} {A,B,C} {, , }