Happy is the man that findeth wisdom, and the man that getteth understanding.

Proverbs 3:13

Semantics

Semantics (ancient Greek: σημαντικός [semantikós] – meaning, σημαίνω [semaino] – to mean, point out, σήμα [sema] – sign) studies the meaning (meaning) in language. In this sense, semantics is usually understood as linguistic semantics (as opposed to computer semantics, for example), that is, the science that studies the meaning of words, phrases, and other linguistic objects. Linguistic semantics considers not only the grammar and meaning of words, but also the use and achievements of language.

In computer science, semantics explores the meaning of a computer program. When the program does not return correct results when the correct input data is submitted, it is assumed that there is a semantic error. Unlike syntax, the machine cannot check the accuracy of program semantics (see: Turing Machine).

Unsolvable tasks

In the 1930s, an important semantic question was resolved: Are there problems that can be formulated as computational problems, but there is no algorithm that solves them?

It turns out that there are many such tasks. Some examples:

Is there an algorithm to determine whether a computer program submitted to its input solves the problem of doubling a number represented as a series of units?

Is there a Turing machine that decides whether the sequence of characters described on its ribbon is a definition of an algorithm equivalent to the Double machine?

Is there an algorithm to check if a program always ends?

As early as 1936, Alan Turing proved that there was no algorithm for determining whether a program would complete its calculation or not.

Syntax

Syntax (Greek: σύνταξις, building) is a science that studies the units of related speech, as well as the laws and rules for constructing sentences and phrases. Syntax is a major part of Grammar, along with Morphology. As a science of the structure of connected speech, syntax studies the laws by which words are connected in word combinations and sentences, as well as the functioning of the combined parts of speech. Syntax treats words not as lexical units but as parts of speech.

In computer science, syntax means the set of rules for writing a programming language.

Elements of programming languages

  • Identifiers – sequences of letters and numbers or certain characters and letters. Names in programming languages are sequences of letters and numbers beginning with a letter. Examples of identifiers: “age, HighestPrice, _column, @string, smallSquare, PI, DAYS_OF_WEEEK”. Examples of non identifiers:  “6years, 7th_month, !size, ?table”.
  • Keywords (reserved words) – predefined, stored words in the language. They execute basic commands and express syntactic constructions. They cannot be used as identifiers of variables, constants, etc. For example: “var, int, echo, if, then, while”.
  • Some programming languages, such as C#, contain contextual keywords that are not essentially keywords. They serve to convey a certain meaning of the code. For example: “add, get, notnull, set”.
  • Keywords in CKeywords in C++Keywords in C#Keywords in PHPKeywords in JavaScriptHTML Tags.
  • Signs – numbers (10, 54, -22, 24674…) and quantities (x, y…), (x, y, z…).
  • Epressions – containing arithmetic (a * x ^ 2 + b * x + c, thisYear, age, ((A + B / C) * (B-A / C))) or comparative (age <18, currentPage == 180 ) or logical (age <18 && currentPage == 180) or a set of different operations involving constants, variables, literals and sets of operations between them. The elements contained in the expressions are divided into operators (+, -, *, /, ^, <, ==,! =,>, ||, &&) and operands (a, x, 2, age, A, B, C, currentPage). The operators work with operands. In programming, very often the result of an expression is passed to a variable. The value token used is “=”, and the operation is called value assignment.

Arithmetic operators

       Operator                         Name                            Description                            Example

            +                              Addition                     Adds two values                           a + b

            –                            Subtraction      Subtracts one value from another             x – 4

            *                          Multiplication              Multiplies two values                       x * y

            /                               Division               Divides one value by another             8 / 2

            %                            Modulus              Returns the division remainder           x % y

           ++                           Increment       Increases the value of a variable by 1      x++

            —                          Decrement      Decreases the value of a variable by 1      x–

Comparison operators

       Operator                         Name                            Description                            Example

            ==                             Equal to        Compare for equality two operands           x == 6

            !=                             Not equal  Compare for non equality two operands        5 != 7

            >                            Greater than                                                                        9 > 10

            <                              Less than                                                                           11 < y

            >=                Greater than or equal to                                                               x >= 22

            <=                   Less than or equal to                                                                 x <= y

Logical operators

       Operator                         Name                            Description                            Example

            &&                               and    Returns true if both statements are true   5 < 10 &&  10 < 15

            ||                                    or       Returns true if one of the statements is true   1 < 5 || 10 < 4

            !                                   not  Reverse the result, returns false if the result is true !(0 < 15 && 5 < 9)

Program structure

Part for data description (declarative part)

             If the program solves a complex task or a series of tasks, it is good practice to divide the
algorithm into modules (subroutines), which are described in the declarative part.

Part for data processing (algorithm)

             The task is done by running a main program (called Main function in some languages),
which in turn calls the subroutines.

Notes to Remember

  • Semantics explores the meaning of a computer program.
  • Syntax means the set of rules for writing a program by a programming language.
  • Elements of a programming language – Identifiers, Keywords, Literals, Statements, Expressions.
  • Operators of a programming language – Arithmetic, Comparison, Logical.
  • Every program language use own syntax and structure. Most of the languages supports declarative and executive syntactic structure.

Recommended References for this Lecture

    Semantics                                  Syntax
    Programming language            Statement and Expression

Last modified: July 8, 2022

Author

Comments

Write a Reply or Comment

Your email address will not be published.