Re: Genetics as a Language System
- From: "Kleuskes & Moos" <kleuske@xxxxxxxxx>
- Date: 1 Nov 2005 17:33:25 -0800
dhogaza schreef:
> Kleuskes & Moos wrote:
>
> > C, for instance, is not defined by the programs written in it, but by
> > it's grammar and it's semantics. Programs written in C either conform
> > to those, or they don't.
>
> You can define a legal C program using grammar only.
Not quite. There is a lot of semantics attached to it, and certain
grammatically correct sequences violate the semantic restrictions.
for instance
<code>
int i = 3;
i = i++; /* UNDEFINED BEHAVIOR, violates sequence point semantics */
</code>
or
<code>
int *a;
a=NULL;
*a=0xdeadbeef; /* null pointer dereferenced, if your lucky,
your OS will SIGSEGV, if you're unlucky your
ISR will be screwed */
</code>
or
<code>
int a = 1000, b = 1000;
long int c = a * b; /* a * b may be truncated and c may an invalid
value */
</code>
or
<code>
char *p = "hello, world!";
p[0] = 'H'; /* writes to a constant string */
</code>
are grammatically correct, but violate the semantics. Check the C-Faq,
if you do not take my word for it. Invoking undefined behavior may
result in a working program, but may also (by the C-definition) result
in Pink Bunnies jumping out of your computer.
The semantics violated are the sequence points. And by the way, the
syntax of
C is defined. If you apply another syntax, you'll end up with
(probably) a
nice programming language, but it's not C.
> It takes a context-sensitive grammar, which can't be parsed in linear time
> (and such a grammar would be complex to the point of being unreadable by the
> average programmer therefore useless as documentation).
>
> Or you can stack two context-free grammars (look up van Wijngarten
> grammars, or the Algol 68 Report).
Gee... Why haven't the compiler boys thought of that. Did you ever
think of notifying the gcc-team? I'm sure they'll slap their foreheads
in sheer amazement.
> > In the latter case you get a error-report in
> > the best case and a run-time exception (SIGSEGV or something simular)
> > in the worst case.
>
> Still a legal C program.
Nope. Invoking undefined behavior renders your program invalid. Again,
consult the C-Faq. Dereferencing a NULL pointer is not prohibited by
the syntax (and cannot be, since you have no way of knowing at compile
time which pointer will be NULL at what time by looking at the program
text.
If you have ideas of how to tell from the source code alone, withouth
knowing the actual input, i'm sure your input would be greatly
appreciated.
> If your goal is to trigger a run-time exception, your legal C program that
> does so is working ...
Working programs do not imply legal programs. Legal programs by
defintion, do not trigger run-time exceptions. In my career as a
programmer (mostly in C, C++ Java, with excursions into Assembly, SQL,
Postscript, Lex and Yacc and quite a few other languages) I have
encountered many programs that worked, but weren't legal C. They
invoked undefined behavior, violated name-space rules, etc. All
explicitly forbidden by the ISO standard, which has large sections
devoted to semantics.
> quite important to people who write programs to test C compilers and their
> libraries.
Any library that triggers a run-time exception is not worth having. C
compilers nor libraries are checked by invoking undefined behavior or
throwing runtime exceptions.
Mind you, these are NOT antything like C++/Java exceptions, they _are_
part of the language and quite a different kettle of fish alltogether.
Testing responses to (for instance) SIGSEGV is part of OS development
and at this
point we are discussing C.
If you want to throw one explicitly, for whatever reason, you would
have to do so in assembly, by inserting an appropriate instruction
(usualy something like 'INT N'), but that's entirely outside the scope
of the C-language. They cannot even be coded in C, you'd have to
nterface with assemby in some way or other.
> > Basically i'm on the practical side of it, being a programmer, so i'll
> > leave the theoretical aspects to the respective experts.
>
> Which is why I'm not trying to correct anyone's posts regarding
> molecular biology ...
I'm not trying to correct anyone either. I'm just trying to make a few
points here and there. This is, after all, not a 'molecular biology
forum', we are in the talk.* hierarchy. And by your rules, you would
also have to refrain from correcting me on matters of C, given the
contents of this post.
C FAQ can be found at http://www.eskimo.com/~scs/C-faq/top.html
.
- References:
- Re: Genetics as a Language System
- From: John Harshman
- Re: Genetics as a Language System
- From: Kleuskes & Moos
- Re: Genetics as a Language System
- From: John Harshman
- Re: Genetics as a Language System
- Prev by Date: Re: Genetics as a Language System
- Next by Date: Re: Dover asked: Why Thomas More?
- Previous by thread: Re: Genetics as a Language System
- Next by thread: Re: Genetics as a Language System
- Index(es):
Relevant Pages
|