Most people are taught something about the parts of speech, which include nouns, verbs, adjectives, adverbs, subjects, predicates, objects, conjunctions, propositions, propositional phrases, etc., so that they can more precise and effective readers and writers. Indeed, educated people, who get the highly paid jobs involving reading, listening, writing and speaking, have internalized the explicit rules for combining parts of speech. These explicit rules are called grammar. The meaning of some speech or writing and how it is determined by its grammatical construction and the meanings of its individual words is called semantics. Linguists and cognitive scientists discover, develop and use rules for semantics as part of their scientific research.
[Maybe give example of bad syntax and syntactic ambiguity.]
The same is true about professional level users of programming languages. Like natural languages, programming languages have rules of grammar and they have semantics. The semantics are quite a bit simpler than semantics of natural languages, so explicitly stated rules of semantics are practical. Those rules indeed apply with much fewer complications and exceptions than any rules formulated for natural language. A person who has not internalized some of the explicitly stated rules of syntax and semantics of some programming languages and systems cannot go very far in programming or computer science. Beginning programmers are usually introduced to a programming language with just examples. However, among the of the subjects that professionals use to be highly precise and effective is the subject of how syntactic and semantic rules in programming can be written, understood and applied.
Example:
Suppose you got an assignment to give you practice with the Java while loop. The task is to write a Java fragment that prints a count from 0 to 4 and then prints the value of the counting variable when the count is finished. What's wrong with this solution?
int i;
i = 0;
while( i < 5 )
System.out.println("My count is " + i);
i++;
System.out.println("The variable value is " + i + " at loop finish.");
What is printed?
Choice A:
My count is 0
My count is 0
My count is 0
....
(Infinite loop!) |
Choice B:
My count is 0
My count is 1
My count is 2
My count is 3
My count is 4
The variable value is 5 at loop finish.
|
Now what are you going to say about THAT??????
Link to the Java syntax chapter of the Java Programming Language Specification.
[Work up an example with NESTING..]
There has been error in communication with booki server. Not sure right now where is the problem.
You should refresh this page.