[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
3.1.1 Syntax and Sematics
JerryDate: Sunday, 25/09/2011, 10:23 PM | Message # 1
Ford Everest
Group: Administrators
Messages: 137
Reputation: 0
Status: Offline
•Syntax: the rules determining how the language, i.e. the program, is constructed.
    ■Example English language: A sentence must start with a capital letter.
    ■Example Java (programming language): a command must be ended with a semicolon.
    ◦In languages used to communicate by humans (ex. English), the meaning is often still understood if the syntax is wrong. However, in programs the syntax must be correct, otherwise the program
    won't work correctly or at all.
    ◦Note, however, that a statement can be syntactically correct but still does not do what was intended by the programmer.
    ■ex. a=b; is correct syntactically, however b=a; is too. Both statements contain the same variables and functions but the results are different.
    ■ex2. System.out.println("Hello World"); and System.out.println("bye"); are both syntactically correct but have different meanings. This leads over into semantics explained below.

•Semantics: the meaning of a collection of statements, so what you actually want the program to do.
    ◦Depending on the context, arguments can be created, that are syntactically correct but are meaningless.
    ■Example English language: "I watched into the street beside the moon because he felt so metallic". This phrase makes no sense but the syntax is correct.
    ■Example if you want to create a program that adds two numbers in Java: c=a*b;. The syntax of this statement is correct, however the semantics is not, since we want to add the numbers and not
    multiply them.
 
JerryDate: Monday, 26/09/2011, 11:11 AM | Message # 2
Ford Everest
Group: Administrators
Messages: 137
Reputation: 0
Status: Offline
High-level language features are only important to the programmer , the user doesn't care which language is used as long as the product is user-friendly.

Programmers usually write programs which are not commercially available, many users can get by with the common applications packages like word processors, databases, spreadsheets, etc.

We should be able to distinguish syntax (the rules which govern the construction of a language) from semantics (the meaning of a language - which is not always literal). Thus

"You are so right!"

could be a political message as well as an expression of agreement depending upon the context.

When we talk about the semantics of an HLL we refer to the meaning which we attach to program statements (ie what do they do ).

The syntax of a high level language program has to be correct, otherwise the program which is supposed to translate it into binary machine code (compiler or interpreter) will refuse to do so (you'll soon discover this for yourself).

Sometimes programmers get confused about what exactly they are trying to achieve and use a ( logically ) incorrect statement that is syntactically correct . This program can be executed by the computer but results in a logic or semantic error.

A programming language, eg Java , is used to construct programs or applications. Internally, as we shall see, the language is translated into binary machine code that the computer works with.

Languages like Java are designed for the convenience of programmers .

What are computer languages?

The hardware refers to the electronic circuitry and other physical components that carry out instructions . This process is automated by the CPU - a complex piece of hardware that is nevertheless just a machine.

Software refers to the programs and data that it operates on. These are supplied by humans. There are two main types of computer language for writing computer programs:

Low-level language
High-level language
The hardware runs only in machine code , usually represented (by us) as the 1's and 0's of binary code. The electrical circuits and magnetic storage devices which make up the computer can only recognise two states. Inside the hardware a computer program may look like this:

0001010011100110
0001001100001111
1010001110101100
1001010000111011

Binary machine code is tedious for humans to work with and they tend to make lots of mistakes when trying to do so.

The first step for computer engineers was to make codes (or mnemonics)which could stand for binary instructions thus ADD might correspond to the code for adding two numbers together, LDA might correspond to the for code fetching a number from memory (LoaDing the Accumulator). Thus a low level language might express the above as:

LDA 2309
ADD 2310
MLT #002
STO 2325

This language is also known as Assembly Language and there is a one-to-one correspondence with machine code. Of course, this is still not very easy to handle so the next step was the development of High Level Languages (HLL's).
 
  • Page 1 of 1
  • 1
Search:

Statistics
Map
Login form