PLC Session 3

In this session we talked about Names,Binding and Scopes. Our friend’s group was the one who did the presentation. It was an easy material because it’s what we , newbie coder already did and it was really easy to understand. Okay without further ado let’s talk about lesson on that day. This presentation divided into five topics as we can see it below

  • Introduction
  • Names
  • Variables
  • The Concept of Binding
  • Scope

The first topic is about introduction our friend’s group explained to us that imperative language are abstraction of von Neumann’s architecture that contains memory and processor. The abstractions in a language for the memory cells of the machine are variables. 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. Designing the data types of a language requires that a variety of issues be considered.Among the most important of these issues are the scope and lifetime of variables. Now we go to the next topic that talked about Names, name is a string of characters used to identify some entity in a program. Basically names are the one that construct a variable, without a name variable can’t be built. In this topic our friend’s group explain the length of variable names that are allowed in languages like PHP, C++, C#, etc. We also learned that in PHP variable name must begin with dollar sign, variable in C-based languages are case sensitive, etc. Next topic is about variable, a program variable is an abstraction of a computer memory cell. A variable consist of Name, Address, Type, and value. Name is what we have discussed before, most variable needs name to be distinguished between variable. The address of a variable is the machine memory address with which it is associated. It is possible to have multiple variables that have the same address. When more than one variable name can be used to access the same memory location, the variables are called aliases.

The other component is Type, type of a variable determines the range of values the variable can store. When the value of a variable is the contents of the memory cell or cells associated with the variable. In the next topic we talked the concept of binding. A binding is an association between an attribute and an entity, such as between a variable and its type or value, or between an operation and a symbol. In this topic we learned that there are static type binding and dynamic type binding. A binding is static if it first occurs before run time begins and remains unchanged throughout program execution. Where which in Dynamic type binding, the type of a variable is not specified by a declaration statement, nor can it be determined by the spelling of its name. Instead, the variable is bound to a type when it is assigned a value in an assignment statement. When the type of a variable is statically bound, the name of the variable can be thought of being bound to a type, in the sense that the type and name of a variable are simultaneously bound. However, when a variable’s type is dynamically bound, its name can be thought of as being only temporarily bound to a type. In this topic we also learned about storage bindings and lifetime.The memory cell to which a variable is bound somehow must be taken from a pool of available memory. This process is what we as programmer called allocation. Whereas deallocation is the process of placing a memory cell that has been unbound from a variable back into the pool of available memory. We also learned that The lifetime of a variable is the time during which the variable is bound to a specific memory location. There are Static variables which are those that are bound to memory cells before program execution begins and remain bound to those same memory cells until program execution terminates. Whereas Stack-dynamic variables are those whose storage bindings are created when their declaration statements are elaborated, but whose types are statically bound. There are also Explicit Heap-Dynamic Variables and Implicit heap-dynamic variables.

The next topic is about scope, the scope of a variable is the range of statements in which the variable is visible. A variable is visible in a statement if it can be referenced in that statement. There are scope that are called static Scope, static scope was first introduced in ALGOL 60. Static scope is called static because the scope of a variable can be statically determined. Not to forget we also learned about blocks. There is also what we called global scope, Some languages, including C, C++, PHP, JavaScript, and Python, allow a program structure that is a sequence of function definitions, in which variable definitions can appear outside the functions. Definitions outside functions in a file create global variables, which potentially can be visible to those functions. Example of scope is shown below

function big() {
function sub1() {
var x = 7;
}
function sub2() {
var y = x;
var z = 3;
}
var x = 3;
}

The reference of x in sub2 in a static scope case will have the value of big’s x. Whereas in dynamic scope case,the x reference of x in sub2 will have the value of sub1’s x.

Posted in Uncategorized | Leave a comment

PLC Session 2

In this second meeting we started to do our presentation that we presented with our groups, in this session 2 we talked about Describing Syntax and semantics that were presented by our friend’s group. This Session divided into 5 topics

  • Introduction
  • The General Problem of Describing Syntax
  • Formal Methods of Describing Syntax
  • Attribute Grammars
  • Semantics

First, we got introduction that covers a little of the whole subject. In this topic we learn about syntax and semantics, The syntax of a programming language is the form of its expressions, statements, and program units. Whereas the semantics of a programming language is the meaning of those expressions, statements, and program units. Next topic is about The General Problem of Describing Syntax .A language, whether natural (such as English) or artificial (such as Java), is a set of strings of characters from some alphabet. The strings of a language are called sentences or statements , that also means language is a set of sentences. There are also lexemes, lexemes is the lowest level syntactic unit of a language. Lexemes can be categorized and form a token. Move to the other topic, it is formal method  of describing syntax. In this topic we learn about context free grammar and Backus Naur Form that abbreviated into BNF . BNF is a natural notation for describing syntax, also BNF is nearly identical to Chomsky’s generative devices for context-free languages, called context-free grammars. We also learned that the fundamental of BNF consists of abstractions are used to represent classes of syntactic structures for example abstraction <assign>

<assign> →  <var> = <expression>

Where <assign> are called Left Hand Side(LHS) means that abstraction being defined

The next right of the arrow are called Right Hand Side(RHS) consists
of some mixture of tokens, lexemes, and references to other abstractions.

Abstraction in BNF are often called non terminal and the lexemes and token are  often called terminal .Non terminal itself are often enclosed in angle brackets. These non terminal and terminals are formed into what we call rules and a finite number of non empty rules are called grammar.In BNF an abstraction or non terminal can have more than one Right Hand Side. BNF can have recursive  if its LHS appears in its RHS for example

<ident_list> → identifier                                                                                                                                                    |identifier ,<ident_list>

A derivation is a repeated application of rules, starting with the start symbol and ending with a sentence (all terminal symbols).We also learn that a grammar is a generative device for defining languages. The sentences of the language are generated through a sequence of applications of the rules, beginning with a special nonterminal of the grammar called the start symbol. This sequence of rule applications is called a derivation. An example of derivation is

<program> => <stmts> => <stmt>

=> <var> = <expr>

=> a = <expr>

=> a = <term> + <term>

=> a = <var> + <term>

=> a = b + <term>

=> a = b + const

where the example of above’s grammar is

<program>  → <stmts>

<stmts>  → <stmt> | <stmt> ; <stmts>

<stmt>  → <var> = <expr>

<var>  → a | b | c | d

<expr>  → <term> + <term> | <term> – <term>

<term>  → <var> | const

The other topics is about attribute grammar, attribut grammar is a context free grammar. The attributes are divided into two groups: synthesized attributes and inherited attributes. The synthesized attributes are the result of the attribute evaluation rules, and may also use the values of the inherited attributes. The inherited attributes are passed down from parent nodes.In this session we also talked about semantics topic, semantics are the meaning of various elements in the program. A program can syntactically right but semantically wrong for example

int velocity, width;

Both of these variables are integers. From the compiler’s point of view, they are exactly the same. However, judging by the names, one is the width of something, while the other is velocity of something.

velocity = width;

Syntactically, this is okay, since you can assign integers to each other. However, semantically, this is totally wrong, since the width and the velocity didn’t have any relation whatsoever.  Semantics can be approach in three major classes Operational Semantics, Denotational Semantics, and Axiomatic Semantics .

Posted in Uncategorized | Leave a comment

PLC Session 1

This is the first meeting of programming language concept class in semester 1 and in my first year in college. We started the lesson with introduction from our lecturer and not to  forget about the class rules,for instances like point system, presentation, etc. We start the class with the introduction to Programming language concept.There are a lot of topics like

  • Reasons for Studying Concepts of Programming Languages
  • Programming Domains
  • Language Evaluation Criteria
  • Influences on Language Design
  • Language Categories
  • Implementation Methods

That was broke down by our lecturer into a set of mind map.The first topic is about Reason for Studying Concepts of Programming Languages.There are several benefits that we can get while studying concept of programming languages for example like, we can Increase our ability to express ideas,Improve our background for choosing appropriate languages, Increasing our ability to learn new computer languages,etc. And not to forget we also talked about the domain of programming or IT role in the real world like making scientific applications, business application, artificial intelligence, system programming, and a lot more. Next topic is about Language Evaluation Criteria, in this topic we talked about the requirement of a programming language to be a good language or not. There are 4 criteria, readability,writability, reliability, and cost.

Readability means the ease with which programs can be read and understood so that programmer can have a better understanding. Another criteria is writability, it means the ease with which a language can be used to create programs. There is also reliability, that means language should run as expected to its specification. Lastly there is cost, means that a language should have the most optimization and minimum cost. Another topic is about influences on language design. The subtopic talks about computer architecture and programming design methodologies. Computer architecture itself talks about how Von Neumann’s architecture influence the design of a programming language. Those languages that uses Von’s architecture were called imperative language because data and programs stored in memory, memory is separate from CPU, instructions and data are transmitted from memory to CPU.Nearly all digital computers built since the 1940s have been based on the von Neumann architecture. The overall structure of a von Neumann computer is shown below

 

Because of the Von Neumann architecture, the central of imperative language are variables, assignment statements, and the iterative form of repetition.The other subtopic is Programming Design Methodologies, this subtopic talk about the wave of changes on programming language from early 1950 to middle 1980.In 1950’s through early 1960’s people concern about machine efficiency but it was hard to understand, so languages become more structured and more easy to understand, for example like languages are read from top to down. Then later languages became data oriented instead of process oriented in late 1970’s until the emerging of object oriented programming. Another topic in this session is language categories which includes  imperative, functional, logic, and object oriented that categorize programming languages. Last topic is about Implementation Methods,

Implementation Methods includes Compilation, Pure Interpretation ,and Hybrid Implementation System. Compilation process is done by compiler, compiler is the one which translate program into machine language.We learn that the language that a compiler translates is called the source language,and then the lexical analyzer gathers the characters of the source program into lexical units.So that the syntax analyzer takes the lexical units from the lexical analyzer and uses them to construct hierarchical structures called parse trees. We will discuss these things later in another session.There is also pure interpretation, it is opposite to the compilation process because in pure  interpretation programs are not translated only interpreted by the interpreter.We also learn that  The interpreter program acts as a software simulation of a machine.We also talked about Hybrid Implementation System, it is a language implementation system that compromise between compilation and pure interpretation.

 

Posted in Uncategorized | Leave a comment