Input: 𝐺 𝑘 : The input graph
   𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 : The current node to be inspected
Output: 𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒 : The trailer node
1: 𝑥 = 𝐹 𝑖 𝑛 𝑑 𝑀 𝑖 𝑛 𝑖 𝑚 𝑎 𝑙 𝑅 𝑒 𝑔 𝑖 𝑜 𝑛 ( 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 )     // Takes
  care of nested regions
2:if 𝑥 = 𝑁 𝑈 𝐿 𝐿 then
3:  𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒 = 𝑅 𝑒 𝑑 𝑢 𝑐 𝑒 𝑅 𝑒 𝑔 𝑖 𝑜 𝑛 ( 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 )     // Do
   the composition following composition rules
4:  𝑈 𝑝 𝑑 𝑎 𝑡 𝑒 ( 𝐺 𝑘 )     // Update 𝐺 𝑘 with CCG at 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒
5:else // Indicates a nested region is found
6:  𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒 = 𝑅 𝑒 𝑑 𝑢 𝑐 𝑒 𝑅 𝑒 𝑔 𝑖 𝑜 𝑛 ( 𝑥 )     // 𝑥 is the entry node
7:  𝑈 𝑝 𝑑 𝑎 𝑡 𝑒 ( 𝐺 𝑘 )
8:  𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒    =    𝐶 𝑜 𝑚 𝑝 𝑜 𝑠 𝑒 𝑅 𝑒 𝑔 𝑖 𝑜 𝑛 ( 𝐺 𝑘 , 𝑐 𝑢 𝑟 𝑁 𝑜 𝑑 𝑒 )
        // recursively repeat the composition
9:end if
10:return 𝑒 𝑥 𝑖 𝑡 𝑁 𝑜 𝑑 𝑒
Function ComposeRegion(G, RegionFound)
Procedure 4: Function ComposeRegion.