"semantic" in n1336.pdf

L

Larry Gates

How does the word "semantic" differ from "syntactic" in C? They seem to be
contrasted.

What does the standard mean when it speaks a a "semantic type?"

Thanks for your comment.
 
K

Keith Thompson

Larry said:
How does the word "semantic" differ from "syntactic" in C?  They seem to be
contrasted.

What does the standard mean when it speaks a a "semantic type?"

Thanks for your comment.


"Sem" is the Latin root meaning "to seem as though", where as
"syntactic" is the Latin root meaning "to signal as though". The
difference is that "syntactic" is explicit where as "semantic" is
implicit.

Glad I could help :) Any more C questions, just let me know.
 
T

Tomás Ó hÉilidhe

Eric said:
Keitho is a known troll on this newsgroup, please ignore him.


This is good advice. Mr Thompson has been spamming this newsgroup to
sell counterfeit Rolex watches of late, he is best ignored.
 
G

Guest

How does the word "semantic" differ from "syntactic" in C?  They seem to be
contrasted.

this is of those rare cases where looking up the words in a dictionary
might be beneficial. I think they were stolen from linguistics.

syntax is concerned with the form or grammar of the text.
semantics is concerned with the meaning.

"the policeman's beard is half constructed" is grammatically
fine but you have to get quite ingenious to give it meaning.

"time flies like an arrow" has multiple meanings,
whilst the grammatically identical "fruit flies like a banana"
has only a single sane meaning.

Constraint violations are semantic errors.
Undefined Behaviour are case where the semantics are
not defined.
What does the standard mean when it speaks [of] a "semantic type?"

dunno, where does it say it?
 
K

Keith Thompson

Keith Thompson said:
"Sem" is the Latin root meaning "to seem as though", where as
"syntactic" is the Latin root meaning "to signal as though". The
difference is that "syntactic" is explicit where as "semantic" is
implicit.

Glad I could help :) Any more C questions, just let me know.

The above quoted article, as should be fairly obvious, is a forgery.
I'm fairly sure that at least two other articles in this thread are
also forgeries. Several other articles purporting to be from Tom?s ?
h?ilidhe (sorry, I can't reproduce the accented characters in my
current environment) may also be forgeries.
 
K

Keith Thompson

Larry Gates said:
How does the word "semantic" differ from "syntactic" in C? They seem to be
contrasted.

Syntax generally refers to all the information about a source file
that can be obtained by parsing it in accordance with the language
grammar. Semantics is everything else.
What does the standard mean when it speaks a a "semantic type?"

It would have been helpful if the standard defined the term; probably
the authors felt that the English meanings of "semantic" and "type"
were sufficient to explain it. The general idea, I think, is that a
floating-point expression may be represented in greater precision than
required. For example, the semantic type of (1.0 / 3.0) is double,
but an implementation is allowed to represent it as, say, long double
or using some hidden extended representation. C99 6.3.1.8p2: "The
values of floating operands and of the results of floating expressions
may be represented in greater precision and range than that required
by the type; the types are not changed thereby."
 
B

Ben Bacarisse

Constraint violations are semantic errors.

Section 3.8 defines:

constraint

restriction, either syntactic or semantic, by which the exposition
of language elements is to be interpreted

so it would be valid to view syntax errors as constraint violations
though the more common usage is view them as something that is
checkable at compile time but goes slightly beyond the syntax. This
is why, I think, the standard says (earlier) that it lays out the
"syntax, constraints and semantics" of C.
 
L

Larry Gates

this is of those rare cases where looking up the words in a dictionary
might be beneficial. I think they were stolen from linguistics.

syntax is concerned with the form or grammar of the text.
semantics is concerned with the meaning.

"the policeman's beard is half constructed" is grammatically
fine but you have to get quite ingenious to give it meaning.

"time flies like an arrow" has multiple meanings,
whilst the grammatically identical "fruit flies like a banana"
has only a single sane meaning.

Constraint violations are semantic errors.
Undefined Behaviour are case where the semantics are
not defined.

Hmmm. I think I see your point, and natural languages might be the way to
think of this. So syntax is something like noun-verb agreement or placing
a comma before a subordinate clause. For semantic questions, you need to
pull back and look at the sentence or paragraph; it's how the syntactic
elements are arranged.

I think of a loop at something semantic.
--
larry gates

I'm sure that that could be indented more readably, but I'm scared of
the awk parser.
-- Larry Wall in <[email protected]>
 
L

Larry Gates

Section 3.8 defines:

constraint

restriction, either syntactic or semantic, by which the exposition
of language elements is to be interpreted

so it would be valid to view syntax errors as constraint violations
though the more common usage is view them as something that is
checkable at compile time but goes slightly beyond the syntax. This
is why, I think, the standard says (earlier) that it lays out the
"syntax, constraints and semantics" of C.

Almost everywhere that the word "semantic" appears in the standard, it is
in a sentence with "syntactic or semantic."
--
larry gates

Unix is like a toll road on which you have to stop every 50 feet to
pay another nickel. But hey! You only feel 5 cents poorer each time.
-- Larry Wall in <[email protected]>
 
L

Larry Gates

Syntax generally refers to all the information about a source file
that can be obtained by parsing it in accordance with the language
grammar. Semantics is everything else.

I'd like to come up with a grab bag of examples to contrast the two.
It would have been helpful if the standard defined the term; probably
the authors felt that the English meanings of "semantic" and "type"
were sufficient to explain it. The general idea, I think, is that a
floating-point expression may be represented in greater precision than
required. For example, the semantic type of (1.0 / 3.0) is double,
but an implementation is allowed to represent it as, say, long double
or using some hidden extended representation. C99 6.3.1.8p2: "The
values of floating operands and of the results of floating expressions
may be represented in greater precision and range than that required
by the type; the types are not changed thereby."

I would like to see a much more pimped-out dictionary of terms in the
standard.

"Semantic type" does seem to have to do with floats. This footnote on pg
217 seems revealing:

209) For the isnan macro, the type for determination does not matter unless
the implementation supports NaNs in the evaluation type but not in the
semantic type.

--
larry gates

: I've tried (in vi) "g/[a-z]\n[a-z]/s//_/"...but that doesn't
: cut it. Any ideas? (I take it that it may be a two-pass sort of
solution).
In the first pass, install perl. :)
-- Larry Wall <[email protected]>
 
L

Larry Gates

The above quoted article, as should be fairly obvious, is a forgery.
I'm fairly sure that at least two other articles in this thread are
also forgeries. Several other articles purporting to be from Tom?s ?
h?ilidhe (sorry, I can't reproduce the accented characters in my
current environment) may also be forgeries.

I saw those last night. I have to wonder what age that person is. I'm all
for broadening The Topic to reflect how huge C is, but this type of crap is
a waste of everyone's time.

BTW, I could have done a *much better* Keith impression.
--
larry gates

I was trying not to mention backtracking. Which, of course, means that
yours is "righter" than mine, in a theoretical sense.
-- Larry Wall in <[email protected]>
 
K

Keith Thompson

Larry Gates said:
Hmmm. I think I see your point, and natural languages might be the way to
think of this. So syntax is something like noun-verb agreement or placing
a comma before a subordinate clause. For semantic questions, you need to
pull back and look at the sentence or paragraph; it's how the syntactic
elements are arranged.

Syntax is about grammar (in fact the words are nearly synonymous).

Semantics is about meaning.
I think of a loop at something semantic.

A loop, like any other C construct, has both syntactic and semantic
aspects. For example, this:

while ( expression ) statement

tells you everything there is to know about the *syntax* of a while
statement (once you understand that "while" is a keyword, "(" and ")"
are delimiters, and "expression" and "statement" are constructs with
their own grammar).

The fact that the statement is executed 0 or more times, as long as
the expression evaluates to a non-zero value, is a matter of
*semantics*. So is the fact that the expression must be of scalar
type.
 
B

Ben Bacarisse

Larry Gates said:
Almost everywhere that the word "semantic" appears in the standard, it is
in a sentence with "syntactic or semantic."

I don't know what your point is. One key part of my confusion comes
from the fact that your statement is factually wrong as a simple
search shows. It remains wrong even if you remove the huge number of
places where the word is used on its own as a heading.
 
K

Kaz Kylheku

How does the word "semantic" differ from "syntactic" in C? They seem to be
contrasted.

Syntax is how the symbols are put together, according to the phrase
structure rules (or incorrectly, in violation of them).

Semantics is what they mean; their interpretation.

E.g. ``Colorless green ideas sleep furiously.'' is a syntactically valid
sentence with nonsense semantics.

These terms are so general in programming languages that the C standard has
next to zero latitude to assign these terms a different meaning.

Sometimes certain semantic feature have an obvious counterpart in the syntax,
so that a semantic distinction or invalidity can be analyzed through syntax.

For instance the semantic constraint that a declaration can specify only one
type can be expressed as a (clumsy) set of syntactic rules which generate
only valid type specifier lists. No such list contains "int char" and so
"int char" is considered syntactically invalid.

Or you can let the syntax generate any lists of type specifiers, and catch the
invalid combinations as a semantic constraint. I.e. "int char" is valid syntax,
but the meaning is recognized as nonsense.

So what makes "int char" invalid, syntax or semantics? For that we have to look
at the particulars of the language. The syntax for declarations in C clearly
over-generates (allows specifier lists that are meaningless), and the
restriction that bans "int char" is a semantic constraint rule, not expressed
in the phrase structure.

In general, anything that cannot be answered using grammar rules is an aspect
of semantics.

In C, syntax and semantics are tangled because parsing the grammar sometimes
requires semantic input, but this doesn't cause the two concepts to be mixed
up. It just means that a C program cannot be analyzed as pure syntax prior to
semantics being applied. Some semantic analysis must be applied during the
processing of the grammar rules, but that's still understood as semantic
analysis. In some constructs, a token is lexically an identifier, but the
grammar for the construct is predicated on deeper information: the phrase
structure rule requires the identifier to be semantically identified as, say,
the name of a type, and not just any kind of identifier. What the meaning of
the syntax A(B); for instance? It could be a declaration of B to be of type A,
(declarators can be parenthesized!). Or it could be a call to function A of
type B. To be able to translate the construct, the syntax has to be known, but
which syntax that is depends on looking up semantic information about A. That
being known, the parse can be completed, and later subject to more semantic
analysis.
What does the standard mean when it speaks a a "semantic type?"

I found one occurence here:

6.3.1.5 Real floating types

2 When a double is demoted to float, a long double is demoted to double or
float, or a value being represented in greater precision and range than
required by its semantic type (see 6.3.1.8) is explicitly converted
(including to its own type), if the value being converted can be
represented exactly in the new type, it is unchanged.

I don't think there is anything tricky going on here. When we look at 6.3.1.8,
it's talking about the type that ``common-real-type'' that arises from
promotions and combinations of operands in an expression.

This is probably what is understood by semantic type. I.e. it's not
syntactically apparent type; it's a type determined by semantics.

In general, type isn't syntactic. For instance if we declare ``int x;'', then
there can later be an expression ``x'' in the program. This has type int, but
that type is semantic information, not syntactic.

Some people might regard the expression 'a' as having as syntactic type,
because it's a literal constant in the syntax. I.e. that it's syntactically a
character constant, and as such could be regarded as having character type.
Regardless of that, be it right or wrong, the expression really has type int,
and this is from a semantic rule which requires expressions of type char to
undergo promotion to int. (Or, rarely, unsigned int, if an int cannot hold all
of the values of type char).
 
L

Larry Gates

I don't know what your point is. One key part of my confusion comes
from the fact that your statement is factually wrong as a simple
search shows. It remains wrong even if you remove the huge number of
places where the word is used on its own as a heading.

My simple search shows hits for "semantic type" and then a handful of hits
where they lie really close together, as in the opening paragraph:

1 This International Standard specifies the form and establishes the
interpretation of
programs written in the C programming language.1) It specifies
¡X the representation of C programs;
¡X the syntax and constraints of the C language;
¡X the semantic rules for interpreting C programs;

At least three times they have s and s, but counting is starting to bore
me.
--
larry gates

In any event, the real geeks will probably just have the screen
tattooed on their chest. Or their stomachs. Teletubbies "R" us.
-- Larry Wall, 8th State of the Onion
 
L

Larry Gates

In C, syntax and semantics are tangled because parsing the grammar sometimes
requires semantic input, but this doesn't cause the two concepts to be mixed
up. It just means that a C program cannot be analyzed as pure syntax prior to
semantics being applied. Some semantic analysis must be applied during the
processing of the grammar rules, but that's still understood as semantic
analysis. In some constructs, a token is lexically an identifier, but the
grammar for the construct is predicated on deeper information: the phrase
structure rule requires the identifier to be semantically identified as, say,
the name of a type, and not just any kind of identifier. What the meaning of
the syntax A(B); for instance? It could be a declaration of B to be of type A,
(declarators can be parenthesized!). Or it could be a call to function A of
type B. To be able to translate the construct, the syntax has to be known, but
which syntax that is depends on looking up semantic information about A. That
being known, the parse can be completed, and later subject to more semantic
analysis.

Thanks, Kaz, I think this is the answer I was looking for, where you talk
of the interplay that also happens in natural language. The perl people
talk of the difference, and they don't have a standard. The word
"semantic" doesn't appear in the fortran standard.

--
larry gates

And you can still put in all that cruft if you want to. You can even
force yourself to have to do it. But to me, it feels a bit like slavery,
so I'm still looking for a land flowing with milk and honey, even if
there are a few giants in it. -- Larry Wall
 
B

Ben Bacarisse

Larry Gates said:
My simple search shows hits for "semantic type" and then a handful of hits
where they lie really close together, as in the opening paragraph:

1 This International Standard specifies the form and establishes the
interpretation of
programs written in the C programming language.1) It specifies
— the representation of C programs;
— the syntax and constraints of the C language;
— the semantic rules for interpreting C programs;

At least three times they have s and s, but counting is starting to bore
me.

This text does not seem to match the pattern you said was common, so
what is this text an example of? What does it illustrate?

I'd rather you explain what point you are making rather than relying
on data you admit you don't have the boredom threshold to collect.
Are you saying the standard does not make much distinction between the
two, or what?

I think it does and that is backed up by the way the word is used (if
you look at all the uses).
 
B

Ben Bacarisse

Larry Gates said:
The word "semantic" doesn't appear in the fortran standard.

No, but the word semantics does -- with what seems to be the same
meaning as in the C standard.
 
L

Larry Gates

No, but the word semantics does -- with what seems to be the same
meaning as in the C standard.

Right you are. I unchecked "match whole word only." I try to get
perspective by contrasting the standards I know best.
--
larry gates

In general, if you think something isn't in Perl, try it out, because it
usually is. :)
-- Larry Wall in <[email protected]>
 

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

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top