Home » Must know » Context Free and Context Sensitive

Context Free and Context Sensitive

Blog Stats

  • 14,863 hits
December 2013
M T W T F S S
« Oct   Jan »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Third post in Must to Know

In my Theory of computation class ,when i read about the context free grammar and context sensitive grammar i never took pain in understanding what it is actually just studied those concepts for mark .when i start to read about these thing now i am regretting that i must have concentrated before itself to learn these concepts in depth

Now let me explain what it is generally ,I dont want to confuse with the definition in the book ,it would confuse you further so let us have a practical example with the following code

For example, in Python the following is syntactically valid code:

x = 1
print x

The following code, however, is syntactically valid in terms of the context-free grammar, yielding a syntax tree with the same structure as the previous, but is syntactically invalid in terms of the context-sensitive grammar, which requires that variables be initialized before use:

x = 1
print y

Rather than being analyzed at the parsing stage, this is caught by checking the values in the syntax tree, hence as part of semantic analysis: context-sensitive syntax is in practice often more easily analyzed as semantics

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: