By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

How C and C++ are context sensitive

P: n/a
Can someone explain to me hoe both C and C++ are context sensitive??

Jul 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
chessc4c6 wrote:
Can someone explain to me hoe both C and C++ are context sensitive??


Could it be you're confusing that with "case-sensitive"?
Jul 23 '05 #2

P: n/a
Yes it could be, but I'm trying to explain how they are different in
that sense and do not know myself.

Jul 23 '05 #3

P: n/a

"chessc4c6" <pr***********@aol.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Can someone explain to me hoe both C and C++ are context sensitive??


Are you referring to the grammar(s)? I suspect there are several parts of
the grammar(s) that make it context sensitive, but I'd say off-hand that the
fact that one needs to know if a given token is a typename or not, while
parsing, is the main reason. Both languages have the typdef keyword which
introduces context sensitivity by defining a new typname. And C++ has a lot
of other constructs that I'd guess make it so, such as templates.

Search on groups.google.com, and you're sure to get a lot of hits.

-Howard
Jul 23 '05 #4

P: n/a
chessc4c6 wrote:
Yes it could be, but I'm trying to explain how they are different in
that sense and do not know myself.


In the sense of case sensitivity they are not different. Context
sensitivity WRT C or C++ is something I've never heard of. Sorry.

V
Jul 23 '05 #5

P: n/a
chessc4c6 wrote:
Can someone explain to me hoe both C and C++ are context sensitive??


As far as I know, no programming language available has a context
sensitive grammar. Context sensitivity is extremely hard to handle, and
more appropriate to spoken languages anyway.

--
Matthias Kaeppler
Jul 23 '05 #6

P: n/a
Matthias Kaeppler wrote:

chessc4c6 wrote:
Can someone explain to me hoe both C and C++ are context sensitive??


As far as I know, no programming language available has a context
sensitive grammar.


Just to clearify.
What is your understanding of 'context sensitive grammer'?

C++ has lots of things in the grammer, which are interpreted differently
depending on the context they appear in. The keyword 'static' comes to my
mind.

Or are you talking about something differently and I am barking up the
wrong tree?

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #7

P: n/a
Karl Heinz Buchegger wrote:
Matthias Kaeppler wrote:
chessc4c6 wrote:
Can someone explain to me hoe both C and C++ are context sensitive??


As far as I know, no programming language available has a context
sensitive grammar.

Just to clearify.
What is your understanding of 'context sensitive grammer'?

C++ has lots of things in the grammer, which are interpreted differently
depending on the context they appear in. The keyword 'static' comes to my
mind.

Or are you talking about something differently and I am barking up the
wrong tree?


Context sensitive grammar would allow productions like:

a N c ::= a b c

whereas the non-terminal N would be reduced to token b if and only if it
appears in the context of a and c.
At least from what I know, this is not what a compiler does when parsing
a programming language. Productions of common programming languages
never appear in a context, that means, they form context-free grammars.

--
Matthias Kaeppler
Jul 23 '05 #8

P: n/a
Matthias Kaeppler wrote:

Karl Heinz Buchegger wrote:
Matthias Kaeppler wrote:
chessc4c6 wrote:

Can someone explain to me hoe both C and C++ are context sensitive??
As far as I know, no programming language available has a context
sensitive grammar.

Just to clearify.
What is your understanding of 'context sensitive grammer'?

C++ has lots of things in the grammer, which are interpreted differently
depending on the context they appear in. The keyword 'static' comes to my
mind.

Or are you talking about something differently and I am barking up the
wrong tree?


Context sensitive grammar would allow productions like:

a N c ::= a b c

whereas the non-terminal N would be reduced to token b if and only if it
appears in the context of a and c.
At least from what I know, this is not what a compiler does when parsing
a programming language. Productions of common programming languages
never appear in a context, that means, they form context-free grammars.


Thanks for the clearification.
A long time has gone since my compiler construction lessons :-)

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #9

P: n/a
Victor Bazarov <v.********@comAcast.net> writes:
chessc4c6 wrote:
Yes it could be, but I'm trying to explain how they are different in
that sense and do not know myself.


In the sense of case sensitivity they are not different. Context
sensitivity WRT C or C++ is something I've never heard of. Sorry.


huh?

int count= 0;

void foo()
{
++count; //in this context, the global count is incremented.
}

void bar()
{
static int count= 0;
++count; //in this context, the static count local to the function
//bar is incremented.
}

namespace baz
{
int count= 0;
void qux()
{
++count; //in this context, the count inside of namespace baz is incremented.
}
}

Above, the expression '++count' appears 3 times, each time in a
different context. Each time, because of differing context, an
otherwise textually identical expression has different
behavior. (And in other contexts, 'count' could refer to a
template ...)

C++ is filled with context sensitivity. In fact, it has few features
which are not in someway context sensitive.

The real problem with the OP's question is the enourmous number of
ways in which both C and C++ are context sensitive.

Jul 23 '05 #10

P: n/a
gb
Llewelly wrote:
Victor Bazarov <v.********@comAcast.net> writes:

Above, the expression '++count' appears 3 times, each time in a
different context. Each time, because of differing context, an
otherwise textually identical expression has different
behavior. (And in other contexts, 'count' could refer to a
template ...)

C++ is filled with context sensitivity. In fact, it has few features
which are not in someway context sensitive.

The real problem with the OP's question is the enourmous number of
ways in which both C and C++ are context sensitive.


Context-sensitivity is a linguistic term that has to do with the rules
of
the grammar (i.e., what is syntactically correct), not the semantics of
the
program (i.e., what the program does). Your examples don't demonstrate
context-sensitivity in the grammatical sense.

Gregg

Jul 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.