[Solved]: Why we use context-free grammar for parsing?

Problem Detail: Why we use context-free grammar for parsing? Why not regular expression and not context-sensitive grammar?

Asked By : Himanshu Saini

Answered By : David Richerby

Because regular expressions are too weak and context-sensitive languages are too difficult to parse. More specifically, regular expressions can’t specify that the brackets in your program match up; determining whether a string matches a context-sensitive language is PSPACE-complete (so probably takes exponential time).
Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/37167  Ask a Question  Download Related Notes/Documents