Descibing Syntax and Semantics ! (session 2)

Session 2: Describing Syntax and Semantics


A. Definition of Syntax

The word syntax comes from Ancient Greek: σύνταξις “coordination”, which consists of σύν syn, “together,” and τάξις táxis, “an ordering”.

In computer science, the syntax of a computer language is the set of grammatical rules that defines the combinations of words and symbols that are considered to be a correctly structured document or fragment in that language.

The syntax of a language defines its surface form. Text-based computer languages are based on sequences of characters, while visual programming languages are based on the spatial layout and connections between symbols (which may be textual or graphical). Documents that are syntactically invalid are said to have a syntax error.

B. Syntax in C++

The syntax of textual programming languages is usually defined using a combination of regular expressions (for lexical structure) and Backus-Naur Form (for grammatical structure) to inductively specify syntatic categories (nonterminals) and terminal symbols.

The following are the examples of basic C++ keywords syntax:

  1. #include, which is used to insert the library of functions we are going to use in our program. For example, #include <iostream>, which includes the standard input and output codes.
  2. int main(), which is called first by the program after the initialization. A statement return 0; should be written at the end of the codes inside int main(). Void main() is also a valid keyword syntax in C++ but without a return 0; at the end of the codes inside void main().
  3. cout, which is used to print output on the screen.
  4. cin, which is used to receive inputted data by user and store it as a variable.
  5. int, float, char, etc, which are used to declare a variable with a daya type.
  6. if, which is used in selection and will execute the codes if the condition is true.
  7. while, for, which are used in looping/repetition.

Important things to note:

  1. C++, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.
  2. A block is a set of logically connected statements that are surrounded by opening and closing braces
  3. C++ is a case-sensitive programming language, as such, “cout” and “Cout” are different.
  4. in C++, to make a comment we use double slash (//) to mark text or code in a line as a comment. Or we can also use /* */ to mark several lines of text or code as a comment inbetween the /* */.

example of a program with correct syntax in C++:

#include <iostream>               // Inserting library for input and output

using namespace std;
int main()                                 // Called first by the program after the initialization

{                                              // Opening brace

int a,y,z;                                  // Declaring variable “a” as an integer data type

cout<<“Masukkan nilai a : “;  // Printing “Masukkan nilai a : “ on the screen

cin>> a;                                   // Asking input from user and store it in variable a
return 0;                                   // Because we use “int main()” we write  a “return 0;”

}                                              // Closing brace

C. Definition of Semantic

Semantics (from Ancient Greek: σημαντικός sēmantikos, “significant”) is primarily the linguistic, and also philosophical study of meaning—in language, programming languages, formal logics, and semiotics. It focuses on the relationship between signifiers—like words, phrases, signs, and symbols—and what they stand for, their denotation.

In computer science, the term semantics refers to the meaning of languages, as opposed to their form (syntax). According to Euzenat, semantics “provides the rules for interpreting the syntax which do not provide the meaning directly but constrains the possible interpretations of what is declared.” In other words, semantics is about interpretation of an expression. Additionally, the term is applied to certain types of data structures specifically designed and used for representing information content.

D. Approaches of Semantics

There are many approaches to formal semantics; these belong to three major classes:

  • Denotational semantics, whereby each phrase in the language is interpreted as a denotation, i.e. a conceptual meaning that can be thought of abstractly. Such denotations are often mathematical objects inhabiting a mathematical space, but it is not a requirement that they should be so. As a practical necessity, denotations are described using some form of mathematical notation, which can in turn be formalized as a denotational metalanguage. For example, denotational semantics of functional languages often translate the language into domain theory.
  • Operational semantics, whereby the execution of the language is described directly (rather than by translation). Operational semantics loosely corresponds to interpretation, although again the “implementation language” of the interpreter is generally a mathematical formalism. Operational semantics may define an abstract machine (such as the SECD machine), and give meaning to phrases by describing the transitions they induce on states of the machine.
  • Axiomatic semantics, whereby one gives meaning to phrases by describing the logicalaxioms that apply to them. Axiomatic semantics makes no distinction between a phrase’s meaning and the logical formulas that describe it; its meaning is exactly what can be proven about it in some logic. The canonical example of axiomatic semantics is Hoare logic.

Once you’ve done your own research, you will have a better idea about what questions to ask and reddit write my essay 2021 what to avoid.

Source(s) :…/chapter%202.ppt

Slide Binus Maya

Comments are closed.