简体   繁体   中英

Parse balanced parentheses CNF

I have a grammar S -> (S)S | empty S -> (S)S | empty

I converted it to a Chomsky Normal Form like this

S -> AS | empty
A -> LB
B -> SR
L -> (
R -> )

I'm not sure if I converted it correctly, but how do I parse this input ()() using the CNF

Do the following derivation in reverse:


          S → AS   
→ S       A → LB
→ BS      L → (
→ (S      B → SR
→ (RS     S → ε
→ (S      R → )
→ ()      S → AS   
→ ()S     A → LB
→ ()BS    L → (
→ ()(S    B → SR
→ ()(RS   S → ε
→ ()(S    R → )
→ ()()    S → ε
→ ()()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM