CS441-Programming Languages: Design Implementation

Due: November 24, 2003

Project 3

                                                                                                                                                                      

Authors:

Email Addresses:

Desiree Shaw

Desiree Shaw

LaAisha Ettress

LaAisha Ettress

Amanda Oropeza

Amanda Oropeza

 

 

1.    Block Structured, Procedural vs. Object-Based

 

1. History

The most common Block Structured, Procedural language is Pascal.  Pascal was developed between 1968-1970 by Nicklaus Wirth. Pascal was designed to be an improvement over the programming language ALGOL.  Pascal is very flexible for programmers. Pascal was predominately used in an educational setting because it allowed compiler flexibility. Pascal is responsible for P-Code, a machine language that can be read by many computer systems.  Pascal is not as popular as it once was, many new languages borrow have borrowed key concepts from the language.  Object Based programming languages did not really becoming prominent until the development of the language SmallTalk that was developed between 1972 through 1980. Object based languages were developed to solve programming problems using object representation.

 

2. Overview

 

Object Based programming true achievement was the use of abstract data types, dynamic binding of data types and inheritance features.  The programming language Java uses single inheritance features with the language C++ uses multiple inheritance features.  Object based languages send messages to objects in the class. These messages carry instructions or methods for the way the objects will interact with each other. 

Block structured, procedural languages like Pascal are highly portable.  Most block structured languages have can create internal procedures with its own data types.  Pascal programs subprograms definitions are defined in the main program.

 

3. Handling of data objects.

Data objects for the Object-based such as C++ have built in data types, they do not allocate resources that do not allocate any memory.  The C++ program has constructors that are called when an object is created and destructors when an object must be destroyed.  Block structure languages such as Pascal do not have any data objects.  The way Pascal handles data is through real data types, integer data types, Boolean types, character variables, enumerated data types, sub ranges, arrays etc…  The object – base C++ and block structure Pascal do share the same type a data objects but are just defined and written differently.

4.     Handling of sequence control.

The block structure language Pascal is user friendly and really very simple.  It has three basic parts that must be in the program.  Program, which initiates the actual program, begin which shows where the program begins and, end shows where the program ends, both define the executable part of the program.  C++, which is an object-based language, is similar to how it is set up.  C++ has a void function that defines the program, the algorithm that defines what the program will be doing and an end to indicate that the code is finish.  Although these are two totally different languages they both have some similarities.

5.     Handling of subprograms and storage management.

Block Structured, Procedural languages handle subprograms as functions or procedures. Block structured, procedural functions have procedures to handle subprograms.  The functions must be defined and parameters set.  The parameters must also be type specified. Pascal uses three control structures to control the flow of subprograms: subroutine calls, iterative constructs, and selection constructs. Subroutine calls are code to complete actions and that actually complete the action as many times as the procedure is called by the program. Iterative constructs basically do the same thing as subroutine calls where an action is repeated any number of times. Selection constructs are the if-then, if-then-else, or case statements. Object Based programming handles subprograms handle subprograms very well. The best example is the language C++.  Functions in C++ pass parameters, which are declared and checked for actions. 

6. Handling of abstraction and encapsulation.

 Abstraction with Object-based structure has to be declared and can accessed any public entities in the class.  They can be either stacks dynamic or referred through pointers.  Abstraction for Block structure Pascal is something like Object-base C++.  Pascal handles abstraction through the use of subprograms.  So, in a way they are similar except C++ subprograms are called classes.  They both reduce redundancy in a program.  Pascal uses abstraction so the language can be more powerful.  C++ encapsulation is not generalized.  The use of a friend function gives access to private entities that have been declared.  Encapsulation for Pascal uses functions or procedures and the data structure and actions are protected by encapsulation.

 

2. Block Structured, Procedural vs. Functional Languages

 

1. History

Unlike Block Structured, Procedural languages, Functional languages were originally created in the 1950’s for its use in Artificial Intelligence.  LISP for example was developed in 1958 at IBM in order to handle algebraic expressions and mathematical functions.  Later Scheme was introduced in 1975 to fully support lexical scooping, first-class procedures, and continuations.  At first it was used primarily for research and teaching and it only supported a handful of pre-defined syntactic forms and procedures.  Now, however, it is a complete general-purpose language.  The general purpose of these languages was to produce code that closely resembled English.  One of the major differences in these to types of languages is the fact that they were created for two totally different programming types.  Block Structured, Procedural languages were used for creating actual applications unlike the Functional language group that was created for use in mostly evaluating functions.

 2. Overview 

Block structured procedural languages are imperative in nature, and were developed in response to the growing use of programming languages to solve a wider array of programming domains than the predominately numeric and scientific type applications of earlier years.  Functional languages are no imperative.  They are applicative and are based on mathematical functions, whereby members of a domain set are mapped to a range set.

 The objective of the design of a functional programming language is to mimic mathematical functions to the greatest extent possible.  A functional language provides a set of primitive functions, a set of functional forms to construct complex functions from those primitive functions, a function application operation, and some structure or structures for storing data.  A well-defined functional language requires only a small number of primitive functions.  Functional languages, such as LISP, are used primarily for artificial intelligence (AI), and list processing applications.

 

3. Handling of Data Objects 

Block structured procedural languages use constants and variables which can be structured to represent many real world entities.  The earliest version, ALGOL 60, used untyped or primitive basic data structures.  A later version, ALGOL 68, introduced user-defined data types.  This allowed users to combine primitive data types into a large number of different structures to model the problem domain.  The use of assignment statements on variables allows these variables to change value during execution. 

A purely functional language does not use variables or assignment statements in the imperative language sense, however, most do retain some notion of variable and assignment, and so are impure, but it is still possible to program effectively using the pure approach.  Functional languages, such as LISP, use atoms and lists.  A parameter for functional languages can represent any member of the domain set.  It is fixed to represent one specific element during the evaluation of the functional expression.  The result is a member of the range set, which can then be the domain of a larger or encompassing function.

 Although ML is strongly typed, most functional languages are type less.  Functional languages have more dynamic binding.  They do not bind a type to storage until a value is assigned, at which time the type bound is that of the assigned value.  A program written in a functional language consists of function definitions and application specifications, with execution consisting of evaluating the function applications.

 4. Handling of Sequence Control

 Functional programming paradigm, which is based on mathematical functions, is the design basis for one of the most important no imperative styles of languages. This style of programming is supported by functional, or applicative, programming languages. LISP began as a purely functional language, but it soon acquired some important imperative features that increased its execution efficiency.

 The control flow mechanisms of Scheme are modeled after those of mathematical functions. Control flow in mathematical function definitions is quite different from that in block structured, procedural programming languages. Whereas functions in block structured languages are defined as collections of statements that include several kinds of sequence control flow, mathematical functions do not have multiple statements and use only recursion and conditional expressions for evaluation flow. For example, the factorial function can be defined with two operations in functional language: F(n)= {1 if n=0  ; n*f(n-1) if n>0 . Functional language use recursion to do repetition, while block structured language use iteration. Functional languages can have a very simple syntactic structure. The lost structure of LISP is an example. The syntax of the block structured languages is much more complex.  

 5.     Handling of subprograms and storage management.

 Block Structured, Procedural languages handle subprograms as functions or procedures. Block structured, procedural functions have procedures to handle subprograms.  The functions must be defined and parameters set.  The parameters must also be type specified. Pascal uses three control structures to control the flow of subprograms: subroutine calls, iterative constructs, and selection constructs. Subroutine calls are code to complete actions and that actually complete the action as many times as the procedure is called by the program. Iterative constructs basically do the same thing as subroutine calls where an action is repeated any number of times. Selection constructs are the if-then, if-then-else, or case statements. The functional programming language LISP runs each code and has calls to subprograms, also know as functions. Subprogram parameters can be passed by value or reference. LISP is a functional language where a top-level function calls lower-level functions to compute its answers. Library functions are available for basic operations. These functions allow LISP to use recursion. Functions are defined and are used in the same way as functions that are built into the language. Loops are not necessary for LISP because recursive function calls name the function processes. Sub-programs in functional languages are not named if they are locally scoped and not reused.

 6. Handling of abstraction and encapsulation

 Abstraction for a functional language such as YACC that comes from the Backus-Naur is used to parse program languages and expresses all context-free (Type 2) grammars.  Functional languages in general are great because they have a heavy reliance on functions.  The encapsulation with a functional language such as YACC is meant to be used with in a C program that must interact with an external program.  Functional languages such as YACC have no encapsulation.  Abstraction for Block structure such as Pascal is handle through the use of sub-programs.  It reduce redundancy in the program and uses abstraction to make the language more powerful.  Encapsulation for Pascal uses functions or procedures and the data structure and actions are protected by encapsulation.

 

3.Block Structured, Procedural vs. Logic

1.     History

Prolog, which is a logic language, was also in the early 1970’s and received its fame in 1972.  This language was also developed in an education environment by Alain Colmerauer and Phillippe Roussel in an A.I. group at the University of Aix-Marseille. The purpose of the language was to enhance the previous work by J.A. Robinson who already had a proven therom of the language.  Prolog received it’s fame in 1981 when the Japanese decided to adopt the language for the purpose of developing intelligence machines which was called the “Fifth Generation Computing System”. 

A blocked structure procedural language called Algol was developed in the mid 1960’s.  In 1971 Nicklaus Wirth developed a language called Pascal.  Pascal was developed as a successor of Algol.  Pascal language was known for the ability to grow and shrink during runtime and the ability to define new data types.  Pascal was taught in classrooms because of its great portable compilers and was even used as the official language of the Advanced Placement test.  Pascal is no longer used.

2.     Overview

The logic language Prolog that means Programming Logic is different from the block structure language.  The language is designed to analyze the rules to see if they are true and what it needs to do to achieve the goal.  It has an inference engine that can determine if the problem at hand can be solved or not.  The rule base that is already encoded determines this.

The block structure was mainly designed to be a teaching tool.  The information is considered to be readable and typically easier for a person to understand.  The block structure language Pascal uses algorithms to express what the program is doing.  The compiler is designed to diagnose an incopability of any type to a variable of another type.

3. Handling of Data Objects

 Block structured procedural languages use set of predefined data types:  real, integer, character, Boolean, variables, constants and literals.  The earliest version, ALGOL 60, used untyped or primitive basic data structures, and a later version, ALGOL 68, introduced user-defined data types.  This allowed users to combine primitive data types into a large number of different structures to model the domain problem.  The use of assignment statements on variables allows them to change a value during execution.

Logic based languages represent objects by using terms, which are constructed from constants, variables, or structures.  All three are different, as constants are usually integers; variables are strings; and structures can be groups of both.  Each term has different rules as to how characters are put together to form its name.  PROLOG also supports simple arithmetic.

 4. Handling of Sequence Control

 Logic language is based on logic, so logic programs are likely to be more logically organized and written, which should lead to fewer errors and less maintenance compare to block structured language. The difference between block structured program and logic programs, logic programs should be nonprocedural, which means that the characteristics of the solution are given but the complete process of getting the solution is not. In Prolog, there are two opposite approaches to attempting to match a given goal to a fact in the database. The system can begin with the facts and rules of the database and attempt to find a sequence of matches that lead to the goal. This approach is called bottom-up resolution, or forward chaining. The alternative is to begin with the goal and attempt to find a sequence of matching propositions that lead to some set of original facts in the database. This approach is called top-down resolution, or backward chaining.

 5. Handling of Subprograms and Storage Management

 Block Structured, Procedural languages handle subprograms as functions or procedures. Block structured, procedural functions have procedures to handle subprograms.  The functions must be defined and parameters set.  The parameters must also be type specified. Pascal uses three control structures to control the flow of subprograms: subroutine calls, iterative constructs, and selection constructs. Subroutine calls are code to complete actions and that actually complete the action as many times as the program calls the procedure. Iterative constructs basically do the same thing as subroutine calls where an action is repeated any number of times. Selection constructs are the if-then, if-then-else, or case statements. Logic based languages deals with relations and list rather than functions.  Logic programming relies on the fact that list are more flexible and durable than regular functions like those present in block structured, procedural languages.

 6.  Handling of abstraction and encapsulation

 Abstraction and encapsulation is not a primary focus for most logic languages.  Since Prolog deals with relations instead of functions encapsulations so the concept of modularization is used to handle the abstraction and encapsulation.  Block structured, procedural languages handle abstraction and encapsulation by of its subprograms.  The procedures also allow for abstraction and encapsulation. The actions for the procedures are kept in the subprograms. 

 

 

References:

 

Block Structured, Procedural Languages - Pascal

http://www.kumc.edu/service/itc/people/nevans/Pascal.doc

 

Functional Languages – LISP, yacc

http://www.geocities.com/weishao2001/project1_h.htm

http://www.cstp.umkc.edu/~jsukardi/cs441/proj1_historyoverview.htm

http://www.cs.northwestern.edu/academics/courses/c25/readings/lisp-history.html

http://www8.informatik.uni-erlangen.de/html/lisp-enter.html
http://www.elwoodcorp.com/alu/table/history.htm

http://www.cs.ndsu.nodak.edu/~slator/html/CS372/sebesta-pdf/sebesta.html

http://www.csis.gvsu.edu/~adams/Notes/ProgLang/intro.pdf

 

Block Structured, Procedural Languages - Pascal

http://www.kumc.edu/service/itc/people/nevans/Pascal.doc

 

Logical Languages - Prolog

http://www.cstp.umkc.edu/personal/mwilson/cs441/proj1/cs441project1_prolog.htm

 

All languages that have been provided.

http://134.193.15.25/vu/course/cs441/exercises/f03p1.htm