Dec 16

Session 3: Names, Bindings, and Scopes

A. Variables

A variable is an abstraction of a memory cell. The lifetime of a variable is the time during which it is bound to a particular memory cell.

A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in programming languages.

Example : int angka               Variable name

 

Type

Variables can be characterized as a sextuple of attributes:

– Name                        – Address        – Value                        – Type              – Lifetime        – Scope

 

Categories of Variables by Lifetimes

  1. Static — bound to memory cells before execution begins and remains bound to the same memory cell throughout execution, e.g., C and C++ static variables in functions.

Advantages     : Efficiency (direct addressing), history-sensitive subprogram support

Disadvantage  : Lack of flexibility (no recursion)

  1. Stack-dynamic–Storage bindings are created for variables when their declaration statements are elaborated. If scalar, all attributes except address are statically bound, e.g. local variables in C subprograms (not declared static) and Java methods.

Advantage        : Allows recursion, conserves storage

Disadvantages  : Overhead of allocation and deallocation, subprograms cannot be

history sensitive, inefficient references (indirect addressing)

  1. Explicit heap-dynamic –– Allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution. Referenced only through pointers or references, e.g. dynamic objects in C++ (via new and delete), all objects in Java.

Advantage      : provides for dynamic storage management

Disadvantage  : inefficient and unreliable

  1. Implicit heap-dynamic--Allocation and deallocation caused by assignment statements, e.g. all variables in APL; all strings and arrays in Perl, JavaScript, and PHP

Advantage: flexibility (generic code)

Disadvantages: Inefficient, because all attributes are dynamic; loss of error detection

 

 

 

 

B. Names

Name is a string of characters used to identify some entity in a program.that is unique, means that there is only one existence of the name, and different each other. Variable names are the most common names in programs. Names are often referred as identifiers.

  1. Length
  • If too short, they cannot be connotative
  • In C++ no limit, but implementers often impose one
  1. Special Character
  • In C++, name can not start with any symbol or number, thus only able to use alphabet or “_” (underscore) symbol as the first word, and no “ “ (space) permitted, so instead of using space, underscore can be used as the exchange.
  1. Case Sensitivity

Disadvantage: readability (names that look alike are different), e.g. “A” is different with “a”, etc.

  • Names in the C-based languages are case sensitive

C. Special Words

Special words in programming languages are used to make programs more readable by naming actions to be performed.  They also are used to separate the syntactic entities of programs.

Keyword is a word of programming languages that is special only in certain context. This can still be used as an identifier or variable name, e.g. final, override, etc.

Reserved word is a special word of a programming language that cannot be used as a user-defined name, e.g. for, int, if, etc.

D. Bindings

A binding is an association between an entity and an attribute, such as between a variable and its type or value, or between an operation and a symbol. Binding time is the time at which a binding takes place.

Binding Time :

  • Language design time — bind operator symbols to operations
  • Language implementation time– bind floating point type to a representation
  • Compile time — bind a variable to a type in C or Java
  • Load time — bind a C or C++ static variable to a memory cell)
  • Runtime — bind a non static local variable to a memory cell

Storage Bindings

  • Allocation – getting a cell from some pool of available cells
  • Deallocation – putting a cell back into the pool

 

 

 

E. Scopes

The scope of a variable is the range of statements over which it is visible. The local variables of a program unit are those that are declared in that unit. Local variables are only known in the unit and can not be used in different unit. The nonlocal variables of a program unit are those that are visible in the unit but not declared there. Global variables are a special category of nonlocal variables, where it is universally known by any unit and usually declared first before any scope or unit. The scope rules of a language determine how references to names are associated with variables.

Example :

#include <stdio.h>

int JumlahSiswa;                                       Global Variable; known by the NamaSiswa and main unit. It is not visible in those 2 units, but this global variable is usable in those 2 units

void NamaSiswa()

Scope

{

char Nama[30];                                 Local Variable; only known and usable in this unit

getchar();

}

 

int main()

Scope

{

int NilaiSiswa;                                  Local Variable; only known and usable in this unit

getchar();

}

  1. Static Scope
  • Based on program text
  • To connect a name reference to a variable, you (or the compiler) must find the declaration
  • Search process: search declarations, first locally, then in increasingly larger enclosing scopes, until one is found for the given name
  • Enclosing static scopes (to a specific scope) are called its static ancestors; the nearest static ancestor is called a static parent
  • Some languages allow nested subprogram definitions, which create nested static scopes (e.g., Ada, JavaScript, Common LISP, Scheme, Fortran 2003+, F#, and Python)
  • Works well in many situations
  • Problems : In most cases, too much access is possible; as a program evolves, the initial structure is destroyed and local variables often become global, subprograms also gravitate toward become global, rather than nested

 

  1. Dynamic Scope
  • Based on calling sequences of program units, not their textual layout (temporal versus spatial)
  • References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point

Example :

                

function big()                                                     Static scoping

{                                                                          Reference to x in sub2 is to big’s x

function sub1()

var x = 7;

function sub2()                                            Dynamic Scoping

{                                                                    Reference to x in sub2 is to sub1‘s x

var y = x;

}

var x = 3;

}

               

  1. Global Scopes

C, C++, PHP, and Python support a program structure that consists of a sequence of function definitions in a file. These languages allow variable declarations to appear outside function definitions.

C and C++ have both declarations (just attributes) and definitions (attributes and storage). A declaration outside a function definition specifies that it is defined in another file.

Source(s) :

http://groups.engin.umd.umich.edu/CIS/course.des/cis400/maxim/lectures/chp4.htm

Slide Binus Maya

Dec 16

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 logical axioms 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.

Source(s) :

https://en.wikipedia.org/wiki/Syntax_(programming_languages)#Example:_Lisp

https://www.tutorialspoint.com/cplusplus/cpp_basic_syntax.htm

https://en.wikipedia.org/wiki/Semantics_(computer_science)

www.letu.edu/people/stevearmstrong/…/chapter%202.ppt

Slide Binus Maya

Dec 16

Session 1: Introduction

 

A. Reasons for studying Concepts of Programming Languages

Increased ability to express ideas, Improved background for choosing appropriate languages, Increased ability to learn new languages, Better understanding of significance of implementation, Better use of languages that are already known, Overall advancement of computing.

 

B. Programming Domains

  • Scientific Computing

– mathematical modeling and engineering design applications

– the first application domain for computers and programming languages

– characterized by: floating point computations, array, matrix manipulations, need for efficiency (number crunching)

– languages: Fortran, ALGOL 60, parallel machine architectures and programming languages

 

  • Business Applications

– information processing and reporting applications

– characterized by: report generation facilities, decimal number manipulations ($), database interoperability, accessibility to nonprogrammers

– languages: COBOL, also affected design of Visual Basic and 4GLs (Delphi, PL/SQL)

 

  • Artificial Intelligence

– manipulating symbols instead of numbers

– characterized by: list (not array) processing, dynamic typing, self-modifying code, flexibility

– example applications: natural language processing, theorem proving, automated integration & differentiation

– languages: LISP (and other functional languages), Prolog

 

  • Systems Programming

– developing operating systems, compilers, database systems, …

– characterized by: emphasis on efficiency, ability to interface with hardware (low-level), few safety checks/restrictions

– languages: C (for implementing Unix), other specialized languages

 

 

  • Web Software

– write applications

– languages: C, C++, Java

 

 

C. Language Evaluation Criteria

  • Readability: the ease with which programs can be read and understood.
  • Writability: the ease with which a language can be used to create programs.
  • Reliability: conformance to specifications (i.e., performs to its specifications).
  • Cost: the ultimate total cost.

 

D. Influences on Language Design

  • Computer architecture: Von Neumann.
  • We use imperative languages, at least in part, because we use von Neumann machines.
    • Data and programs stored in same memory.
    • Memory is separate from CPU.
    • Instructions and data are piped from memory to CPU.
    • Basis for imperative languages
    •  Variables model memory cells.
    •  Assignment statements model piping.
    •  Iteration is efficient.
  • Fetch-execute-cycle (on a von Neumann architecture computer)

initialize the program counter

repeat forever 

fetch the instruction pointed by the counter  increment the counter  decode the instruction  execute the instruction

end repeat.

  • “von Neumann Bottleneck”

 

E. Language Categories

  • Imperative (e.g., C and Pascal)
  • A language which operates by a sequence of commands that change the value of data elements.
  • Central features are variables, assignments statements, and iteration.
  • Includes visual languages( Visual Basic.NET) and scripting languages (JavaScript, Perl and Ruby).
  • Functional (e.g., LISP and Scheme
  • A functional language is one that operates by use of higher-order functions, building operators that manipulate functions directly without even appearing to manipulate data.
  • Main means of making computations is by applying functions to given parameters.
  • Logic (e.g., Prolog)
  • Rule-based where rules are specified in no special order.
  • Language implementation decides the execution order that produces the desired result.
  • Object-oriented (e.g., SmallTalk, C++ and C#)
  • A language in which data and the functions which access it are treated as a unit.
  • Encapsulate data objects with processing.
  • Inheritance and dynamic type binding.
  • Grew out of imperative languages.

 

F. Implementation Methods

  • Compilation
  • Programs are translated into machine language; includes JIT systems.
  • Use: Large commercial applications.
  • Translate high-level program (source language) into machine code (machine language).
  • Slow translation, fast execution.
  • Compilation process has several phases:
  • lexical analysis: converts characters in the source program into lexical units.
  • syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program.
  • Semantics analysis: generate intermediate code.
  • code generation: machine code is generated.

 

The Compilation Process

  • Pure Interpretation
  • Programs are interpreted by another program known as an interpreter.
  • Use: Small programs or when efficiency is not an issue.
  • No translation.
  • Easier implementation of programs (run-time errors can easily and immediately be displayed).
  • Slower execution (10 to 100 times slower than compiled programs).
  • Often requires more space.
  • Now rare for traditional high-level languages.
  • Significant comeback with some Web scripting languages (e.g., JavaScript, PHP).

Pure Interpretation Process

 

  • Hybrid Implementation Systems
  • A compromise between compilers and pure interpreters.
  • Use: Small and medium systems when efficiency is not the first concern.
  • A compromise between compilers and pure interpreters
  • A high-level language program is translated to an intermediate language that allows easy interpretation
  • Faster than pure interpretation
  • Examples:
  • Perl programs are partially compiled to detect errors before interpretation
  • Initial implementations of Java were hybrid; the intermediate form, byte code, provides portability to any machine that has a byte code interpreter and a run-time system (together, these are called Java Virtual Machine)

 

Source(s) :

users.dickinson.edu/~wahlst/356/ch1.pdf

https://prezi.com/nvowp–hkiu4/programming-domains/

http://zakarum.tistory.com/entry/Language-Design

http://zakarum.tistory.com/entry/Language-Categories

https://www8.cs.umu.se/kurser/5DV086/HT09/utdelat/PLC1.pdf

Slide Binus Maya

 

Dec 10

logo tfi merahdownload

Hi, Kalian semua !!! Selamat datang di Blog saya ! Kenalin, Nama saya Kevin Fausta (nim : 2001559141). Saya dari Binus University sebagai jurusan IT (Information Technology) dan untuk saat ini, saya akan menceritakan pengalaman saya saat acara DV RUN.

Sebelum saya menceritakan pengalaman saya tentang DV RUN, apa sih DV RUN itu ? DV RUN itu adalah DV Run adalah acara 5k charity run yang diselenggarakan oleh salah satu UKM kehrohanian di Binus, yaitu KMBD. Acara DV RUN ini diselenggarakan di Taman Ancol, tanggal 4 Desember 2016.

Alasan saya mengikuti DV RUN ini untuk bersenang – senang dengan teman – teman saya saat waktu luang dan juga sambil mendapatkan jam sosial :V.

Sebelum acara DV RUN dimulai, kami diberikan race pack sebagai persiapan dan syarat untuk mengikuti acara DV RUN ini. Dan pada saat di hari – H, kami bersiap – siap untuk pergi ke taman Ancol pada jam 5 dari Binus. Perjalanan kami untuk sampai ke Taman Ancol pintu barat sekitar 30 menit. Setelah itu kami sampai di lokasi acara, kami pun melakukan pemanasan sebelum berlari.

IMG20161204071614

Persiapan saat memulai acara DV RUN

IMG20161204071823

Saat DV RUN berlangsung

Berlari sejauh 5 km bukanlah yang mudah, namun hal tersebut bukanlah menjadi hambatan saya dalam bersemangat mengikuti acara ini. Setelah sesampainya saya di garis finish, saya melihat ada anak – anak kecil yang sedang menunggu kami sambil membawa medali. Medali itu ternyata diberikan untuk para partisipan DV RUN. Setelah selesai berlari, kami pun mengunjungi stand yang telah disediakan di sana dengan beberapa performa panggung yang unik.

IMG20161204065103

Acara panggung setelah berlari

Dari acara DV RUN ini, saya mendapat pelajaran bahwa kita dapat membantu orang – orang dari hal yang sangat kecil apapun. Sekecil apapun usaha kita, merupakan hal terbesar yang didapatkan orang tersebut. Motivasi yang dapat diberikan untuk teman – teman anak jalanan dan para aktivis acara ini adalah kita dapat menjadi seseorang yang membawa kebahagian untuk orang lain demi menciptakan sesuatu kebersamaan hangat tiada tara.

Jumlah anak – anak jalanan di Indonesia masih sangat banyak. Mereka tidak bersekolah. Setiap harinya, mereka bekerja demi mencukupi kebutuhan mereka sendiri. Namun dengan sarana – sarana yang ada, kita dapat meminimalisir tingkat kemiskinan anak – anak jalanan di Indonesia, seperti acara DV RUN dan acara – acara sukarela lainnya.

1480864497822

Foto bersama teman – teman

1481155259973

That’s me :))

Next Entries »