Chapter 6. Computer science Applied to Social Work 2004/05
Programming languages

Updated 2006/06/24License of Creative Commons
This work is under a license of Creative Commons
.
General concepts
Methodologies of programming
Types of languages

6.1 General concepts

A computer consists of two parts, one is the physical, well-known part like “Hardware” and another one, the logical part denominated “Software”. Both are essential to have a computer in operation. With respect to the physical part already a scheme of its components has studied, now will see the members of “Software”

As well as the physical part is totally visible, the logical part is intangible, although essential so that a computer is operative.

Software is divided in two great groups, one is the well-known as operating system or exploitation system and another part are the denominated programming languages. Aside they exist infinity of applications of “Software” but or for tactical missions, like for example the countable applications, the officce applications or the scientific programs.

Programming languages it has in great amount, some they have evolved throughout the time and they are used in the course of many years, whereas others have been operative during a more or less long period and at the moment they are not used. Given this great variety of languages, it is not tried here to give a vision of all, but a classification in diverse types and to make specific some of them. With respect to the most recommended for the learning, the Pascal, a section is dedicated to him for those who is interested in learning to program in a reasonable language and of ample diffusion.

In general a language is a method advisable and simple to describe to the structures of information and the sequences of actions necessary to execute a concrete task.

A very important classification of the languages is the one to make two groups on the basis of its operation, this is to consider them like interpreters and compilers, according to is described next.

Connection of extension (in Catalan) Compilers

There is a language spread in the scope of education, is the TurboPascal, whose advantage is that although it is a compiler has work surroundings as if outside an interpreter and any error can be corrected at the moment, starting again itself the execution of the program immediately.

An example in the real life that visualizes the difference between an interpreter and a compiler is the following one, we suppose that we have a book written in a language different from the Castilian, are two processes to accede to its content when its use is needed, one is to translate at the moment of its use the part of the book that is needed, but without transcribing it to paper, but simply by means of reading translating, this would be the process of interpreted, whereas the other option would be to translate the whole book to the Castilian and to leave this version on paper written, this would be equivalent to the compiled one.

The compiled process of is not as immediate as it seems, is described next of form very outlined:

1. The program (well-known as source program) by means of a text editor is written and it is stored in a file.

2. This source program is invoked by the first stage of the compiler, who carries out a lexical analysis, can be considered like an interpretation of the source program preparing it for a later treatment with detail. In this stage the three indicated processes are executed next:

For example, considering a fragment of code in BASIC (also BASIC compiler exists), it would be had,
200 FOR I=1 TO N STEP 1
210 LET A (I) =0: REM Initializes the matrix
220 NEXT I

it would pass a:

[L45] [T16] I=1 [T17] N [T18] 1 \
[L46] [T09] X (I) =0 \
[L47] [T19] I \

3. Syntactic analysis is the following step, the compiler determines the structure, and of some form the meaning of the source program. The set of the program is analyzed in blocks, that are disturbed in instructions and it is come to identify the individual elements. As the syntax is expressed by means of a set of rules, each one indicates as a structure of the program from other structures of smaller organization is constructed. The process by means of which the compiler applies these rules is known like “parsing”. Next an example is mentioned:

In notation BNF one regulates syntactic can be written like,

<Line program:: =<Number of line <Word key <Rest of the sentence

and applying it to line 100 of previous example BASIC, it would be had,

<Number of line 100
<Word key LET
<Rest of X=0 sentence

and therefore:

<Line of program 100 LET X=0

During the compilation great amount of information, that a well-known structure of data like dictionary or table of symbols is stored in, at some time of the process is generated will be needed the information kept previously. Most is information on variables, for example for X in the previous program, it would be had in the dictionary,

Name of the variable Direction Type
X N 3A2F

4. The following step is the generation of code, known as object For it crosses the generated intermediate code and one of “tokens” in the dictionary looks for each, which allows to insert the directions in the code machine that is being generated. In the example that is studying it would have:

Line 200
LOA X N+1 Use the registry índex like accountant
SIG CMP X N Compares with N
BGT AIM When finishing vetoes to AIM
Line 205
CLR To Puts to zero the storage cell
STD TO D and Copy the content of the storage cell in Y+índice
Line 210
INC. X Increases the index
BRN SIG Cont the curl
AIM

5. The following process is the optimization of generated object code, with which a more efficient program is obtained. Where they are obtained the best results are generally in the curls, whose objective is to reduce to the maximum the number of operations that are executed in him.

6. Normally there is a well-known later stage like “link” in which or the object modules generated previously are united to each other and/or with other modules available in librarys, to form a file that a feasible program directly contains from the operating system, with no need to have the corresponding compiler. Programs can even be united written in different languages if the created object modules have been structured of suitable form. In any phase of the process errors can be detected that will be able of manifesto, implying returning until the source program, carrying out the pertinent corrections and to repeat all the process, which usually is something laborious.

6.2 Methodologies of programming

At the moment long-range changes in the form are taking place in which “software” for the computer science equipment is developed. Between the causes of these changes the following ones are included:

These and other pressures are causing a reorganization of the methods used in the development of the programs for the computers. What it is needed are technical for elaboration the very long and complex software product, that satisfies very strict standards with quality and benefits, in agreement with a planning, control and estimated adapted.

The work methods that have been developed to respond to these necessities constitute what it has occurred in calling “Engineering of Software”. The Engineering of Software is an equipment task, when beginning a development project, constitute a series of equipment with a parallel structure to the one of the program in himself. A calendar for the project settles down and to costs to each one of the parts and stages of the project are assigned. Each equipment has a person in charge, whose task is the one to verify that the programming developed by the equipment is correct, is structured with property, has the interfaces to connect with the programs developed by other equipment and it is developed according to the forecasts of time and cost.

The Engineering of Software takes care of the complete service life of a software product, design, development, use and maintenance. The work is done looking for the greater possible degree of standardization and the smaller costs during the totality of the service life of the programs.

The Engineering of Software implies that a structured affluent program satisfies the following conditions:

With regards to the techniques of design of programs, the simplest method and one of most popular are the well-known like of “Progressive Refinement”. It is based on the use of algorithms that are written in an intermediate language between Castilian and a programming language like the Pascal, this language denominates pseudocode. The process can be described in terms of a language of this nature:

Other more polished methodologies like for example the well-known one like “Functional decomposition” exist. Unlike the previous one in each stage the essential properties of the structures of data are specified, and each algorithm is expressed like a mathematical function that transforms this structure of data.

Once developed a program as it is logical it has to verify his good operation. At the moment in most of the cases they are proven with any data type that can appear in the reality. Nevertheless this process never can establish if a program is or noncorrect, without concerning whichever data sets of use. If a program is of critical importance, as it happens in the present with many commercial applications, industrial or military, it is necessary to take all the precautions possible to assure that they are free of errors.

They are beginning to use technical to assure that the modules (and the algorithms) are correct, that consider them as mathematical and then theorems such are used methods that are used to demonstrate the theorems. This task is very complex and not always applicable.

6.3 Types of languages

The programming languages are classified of general way in two great groups, High-level languages and Low-level languages. The group of those of Low Level, as its name indicates includes the related ones intimately to the architecture of the machine, reason why is specific of a central processing unit (CPU) and is not generally valid for another different one.

Within those of these groups it is the language machine, that is to program in the scope of the CPU, therefore using zeros and only, language very difficult and prone to errors. The other more well-known within this category is the Assembler, who uses mnemonic on simple scale, and therefore it avoids the sequences of zeros and. Even so he is quite complicated and he is not recommendable for users without ample knowledge.

In conclusion, a low-level language is oriented towards the resolution of a certain machine or classes of machines.

Unlike those of the previous group, a high-level language is independent of the microprocessor of the computer that supports it, thus for example a program written in language C, it is possible to be compiled without modifying for any machine, and in principle it will work without no problem.

This implies two main advantages, one is that the person who develops the programs does not have to know nothing about the computer in which the program will be executed, the other is that the programs are portable, that is to say, he himself program (in theory) has to work on different types from computers.

The development of the high-level languages began in the middle of the Fifties of the last century, at this time were created languages COBOL, FORTRAN and ALGOL60. Later they have been originated other many, in fact several thousands, although survive very few.

Between the high-level languages it is possible to emphasize the following ones:
JAVA
BASIC
FORTRAN
IT MODULATES 2
Pascal
ADA
C
C ++
LOGO
LISP
PROLOG


In conclusion a high-level language is oriented towards the resolution of a certain class of problems.

Another form to classify the languages is in two great groups, declaratory and imperative. The considerations establish how a task dividing it in procedures must be executed that specify each one of the tasks. On the contrary the declaratory ones establish structures of data and the relations among them who are significant to execute a determined task, to the time that they indicate as it is the objective of this task. A typical language of this group is the Prolog.

Annexed - Example of a language: Pascal

The Pascal receives his name in honor of the mathematician and French philosopher Blas Pascal (1623-1662). He was developed between years 1968 and 1971.

In contrast to FORTRAN, COBOL Or ALGOL 60, the Pascal is been from the work of a single person, Niklaus Wirth (1934-), university professor (at the moment rejoiced) of Zurich (Swiss). From the Algol60 he designed an suitable language to teach computation to the university students. According to its creator its development must to two main reasons. First he is the one to provide an suitable language to teach to program of systematic form, from a few fundamental concepts that they are reflected of clear and natural form in the language. The second is to develop implementations of this language that work at the moment of trustworthy and efficient form on the computers available.

Recommended connection:
Course of Pascal. Computer center, University of Zaragoza

Parts of a program in Pascal

A program is subdivided in several parts: - The head, usually is optional, in her indicates the name of the program
- Definitions and declarations, are optional and can be categorizar like:
- Definitions of types
- Definitions of constants
- Declarations of variables
- Declarations of labels
- Definitions of subprograms

The head

Independently of long or small it that is, all program must begin with a program head. This head is forward edge, begins with the key word Program followed of the name and finished by;.

Definitions and declarations

The normal thing is that a program needs data. A data is any information that is manipulated by a program and needs a space storage in the computer when executing itself the program. The data that they never change denominate constants, whereas those that they change know like variables. In order to reserve space in the memory they are had to declare by means of a declaration of variables. The identifiers must begin with an alphabetical character or the emphasized symbol of. The first character can be followed of up to 126 additional, alphabetical, numerical ones or of emphasized.

Types
In Pascal besides to give identifiers for the variables the type of the data is due to indicate that will be used for that variable. The type of a data has two intentions, one to assign how much memory is going away to assign to a data of particular type. The other is to badly prevent a emparejamiento with types.

In Pascal, the types can be categorizar in predefined and user defined.

The predefined types are:


Constants
They are used to associate a fixed value to an identifier. This it can be user defined or can be literal who describes a value. On the other hand the constants user defined, constant calls with name must be defined in the part of constant definition, like for example, const PUERTO = 98. Cons is the reserved word corresponding. The constant can as well be defined with type, like for example, Const PUERTO: Integer 98;


Variables
When a variable is declared, a place is assigned to him to memory, providing to him to put a data type. A declaration also provides a name for that place. The key word is Var, being able to appear next one or more identifiers of variables, separated by commas and the types separate with two points (:), next are examples,

Var tipo_interes
cant_nominal
main: Real;
year: Integer;
month: Byte;
inchr: Char;
exit: Boolean;
Var tipo_interes, cant_nomina, main: Real;

Constants with type
They can be used to save memory and like initialized variables. Next an example occurs:

Const TEXTO= " T ";
MAYUSCULA= " U ";
weight: Byte = 80;
tipo_entrada: CAPITAL Char =;

Operators
Great part of the data manipulation in a program is executed by means of operators. The operators classify themselves in three categories, arithmetic, logical and relational.

The term more constant expression talks about to a combination of one or literal or with name or identifiers of variables, one or more operators.

When it appears more of an operator is a precedence order, and if it is at he himself level the evaluation takes place of left to right. The precedences are:

1 - (less unary)
2 not
3 *,/, div, mod, and, shl, shr
4 *, -, or, xor
5 =, <, <, <=, =, in

Sentences
The part of sentences is in where the logic of a program is defined, it is where the data are manipulated to obtain the result wished by the user of the program. The sentences can be classified in the types:


An assigment statement consists of an identifier of variable (or function) followed of the operator of the allocation (: =) followed of an expression. Next examples are indicated,

exit: =FALSE -->
interest: =10
payment: =principal/periodo

A compound sentence is had to identify in the end in the principle with Begin and with end;. A sentence of this type can be formed by all the types of sentences including other compound sentences.

Sentences of logic control

- Curl while. It executes a sentence repeatedly until the condition of the curl gives FALSE. The form is, While Do condition sentences

While Do condition
Begin
if sentences 1
if sentences 2
  ......
End;

- Repeat-Until Curl. If is used when it is necessary that the curl is executed at least once. In this case verificaction of the condition offers that possibility. The form of the curl is,

Repeat
if sentences 1
if sentences 2
  ......
Until condition

- For-Do Curl. He is ideal for the cases in that the Number of times is predetermined that will execute a sentence. The form is, For accountant: = exp1 To exp2 Do sentences

For accountant: =exp1 To exp2 do
Begin
sentencia1
sentencia2
   .......
End;

- If-Then-Else. This sentence executes one, many or no sentence depending on the evaluation of the established condition. The general form is,

If Then condition sentencia1 [Else sentencia2]

- CASE Sentences. The form of this sentence is,

CASE Of selector
Constante1: sentencia1;
Constante2: sentencia2;
Constanten: they sentence;
Else
he sentences;

When a sentence CASE is executed, the value of the selector, that is a variable and can be any type to climb except Real, is used to determine which, if there were it of, sentences of the CASE ejcuta. The constants associated with the sentence must of being of he himself type that the variable selector

Subprograms in Pascal

The subprograms are like small programs within a program, are even looked like the programs to begin with a head, to go followed of the declarations and a part of sentences. The subprograms are in the part of declaration of the program, nevertheless operate in their own surroundings, separated but not always isolated of the main program. A subprogram can declare variables that are only accessible from the subprogram, can use variables of the main program and can use a mixture of both.

The subprograms are of two types: procedures and functions.

Procedures
The procedures begin semicolon by the reserved Word followed Procedure of an identifier and. After the head the part comes from declaration. When executing a procedure the constants and variables of the part of declaration are created in memory, but after the procedure has been finished disappear, which supposes a memory saving.

After the declaration they are the sentences, between the key Words Begin and End and semicolon. The procedures activate in the main program giving their name as a simple sentence.

Frequently the procedures need that one occurs them or more values, than are known like parameters. These are included in the head, within the parentheses that follow the identifier. The declarations of parameters are as the declarations of variables in the form and intention. Each identifier separates by semicolon, each one is had to define as a type with name. Next is a procedure that repeats a character in screen, the Number of times that is wanted,

Procedure Repite (character; Car, conta: Integer);
Var i: Integer;
Begin
For i: =1 to conta Do
Write (character);
End;

and thus to invoke that it appears the letter To 80 times followed in screen,

It repeats (“To”, 80)

where two parameters have gone. These parameters can be of another type, like variables, expressions, like for example,

character: = " A "; conta: =80;

It repeats (LowerCase (character), conta);

where LowerCase is a function that removes the very small letter from the indicated one.

The parameters can as well be passed through value or reference. If one goes through value, a copy of the value of the present parameter to the procedure is transferred, the procedure does not accede to the real variable and therefore it cannot modify it. A procedure can change the value of a parameter by value, but to the return to the program it is without modifying the present value of the original parameter

If it is desired to pass a parameter through reference, the present parameter must be a variable or a constant with type. In front of the declaration of the formal parameter it is necessary to put the Word key Var.

Next an example for each one of the two forms of passage of parameters occurs,

a) By value

Procedure increases (mas_uno: Integer)

Begin
mas_uno: =mas_uno+1;
WriteLn (mas_uno);
End;

and when executing the following instructions,

advance: =1;
it increases (advance);
WriteLn (advance)

the exit would be of 2 and 1.

b) By reference

Procedure increases (Var mas_uno: Integer)

Begin
mas_uno: =mas_uno+1;
WriteLn (mas_uno);
End; and when executing the following instructions,

advance: =1;
it increases (advance);
WriteLn (advance)

the exit would be of 2 and 2.

Functions
The difference between a procedure and a function is that the identifier of a function assumes a value when the function has finished and gives back east value to the routine that called it in substitution of the name of the function. In an ample sense the name of the function is also a variable. All the indicated one previously with respect to the definition of the procedures is applied to the functions. The key Word is Function. Next a function example is indicated that turns a parameter of Char type to very small letter, if this parameter is in the rank from a to z.,

Function miniscula (character: Char); Char

Begin
If character in “A”. “Z” Then
small letter: To =Char (Ord (character) +32)
Else
small letter: to =caracter;
End;

Other possibilities

The Pascal offers many more possibilities, like for example the definition of types by the user, or the Seth type (joint), of great interest since they do not appear in most of the languages. Another type to emphasize is the sharpshooting denominated one. The recursividad is a characteristic of much utility, that is to say, that certain instruction can be called to itself. Here these possibilities do not treat although they are widely used in the scale programming outpost in Pascal.


Bibliography (Available in the University Library):

- Appleby, Doris, Lenguajes de programación : paradigma y práctica / Doris Appleby, Julius J. Vandekopple 1998
- Berger, Marc. Graficación por computador con Pascal / Marc Berger. -- Argentina, etc. : Addison-Wesley Iberoamericana, cop. 1991
- Biondi, Joëlle, Algorítmica y lenguajes / Joëlle Biondi, Gilles Clavel 1985
- Burns, Alan Sistemas de tiempo real y lenguajes de programación -- Madrid : Addison-Wesley, cop. 2003
- Cueva Lovelle, Juan Manuel...[et al.]. Introducción a la programación estructurada y orientada a objetos con Pascal -- Oviedo : Departamento de Matemáticas
- Cuevas Agustín, Gonzalo. Teoría de la información, codificación y lenguajes Córdoba, Argentina : SEPA, Sociedad para Estudios Pedagogicos Argentinos , cop. 1985
- Lenguajes HTML, JAVA Y CGI : el diseño de páginas web para internet a su alcance. -- Madrid : Abeto, 1996
- Findlay, W. Pascal : programación metódica W. Findlay, D. A. Watt. -- [2ª ed.]. -- Madrid : Rueda, 1984
- Grogono, Peter, Programación en PASCAL. -- Ed. revisada. -- Argentina, etc. : Addison-Wesley, cop. 1986
- Sánchez Dueñas, G. Compiladores e intérpretes.Un enfoque pragmático 2ª ed. Díaz de Santos, Madrid 1989
- Algunos programas de uso común en Pascal. -- Madrid : McGraw-Hill, D.L. 1982
- Lenguajes HTML, JAVA Y CGI : el diseño de páginas web para internet a su alcance. -- Madrid : Abeto, 1996
- TRUCS et astuces pour turbo Pascal. -- Paris : Micro-Application, 1986


Enlaces de interés en internet:

Artículos y tutoriales. Lenguaje Pascal
Bjarne Stroustrup's homepage!
El Máquinas
Hello World. ACM
Metodología y Tecnología de la Programación. Fac. Informática. Univ. Murcia
Raúl Monge Anwandter. Univ. F. Sanat María. Chile
Metodologías de Desarrollo de Software. Fac. Informática. Univ. Murcia
The Languaje Guide
Vilecha.com. Tú albergue en la red


Capítulo previo Inicio Capítulo siguiente
Difunde Firefox

Apuntes Introducción Informática. Rafael Barzanallana

courses:.fr.de.pt.jp
.
courses:.fr.de.pt.jp