How C and C++ are context sensitive

C

chessc4c6

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

Howard

chessc4c6 said:
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
 
V

Victor Bazarov

chessc4c6 said:
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
 
M

Matthias Kaeppler

chessc4c6 said:
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.
 
K

Karl Heinz Buchegger

Matthias said:
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?
 
M

Matthias Kaeppler

Karl said:
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.
 
K

Karl Heinz Buchegger

Matthias said:
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 :)
 
L

Llewelly

Victor Bazarov said:
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.
 
G

gb

Llewelly said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,201
Messages
2,571,051
Members
47,656
Latest member
rickwatson

Latest Threads

Top