CSC 432 Lecture 1
CSC 432 Lecture 1
CSC 432 Lecture 1
LECTURE NOTES 1
A programming language is an artificial language designed for expressing algorithms on
a computer.
APPLICATION DOMAINS
1. Scientific Applications
2. Data processing Applications
3. Text processing Applications
4. Artificial intelligence Applications
5. Systems Programming Applications
6. Web software
WEB SOFTWARE
This is a collection of languages which include:
- Markup (e.g. XHTML)
- Scripting for dynamic content under which we have the o Client side, using scripts
embedded in the XHTML documents e.g. Javascript, PHP o Server side, using the
common Gateway interface e.g. JSP, ASP, PHP
- General- purpose, executed on the web server through cGI e.g. Java, C++.
2. Functional
Here, the main means of making computations is by applying functions to parameters.
Examples are LISP, Scheme, ML, Haskell. It may also include OO (Object Oriented)
concepts.
3. Logic
This is Rule-based (rules are specified in no particular order). Computations here are
made through a logical inference process. Examples are PROLOG and CLIPS. This may
also include OO concepts.
IMPLEMENTATION METHODS
1. Compilation – Programs are translated into machine Language & System calls
2. Interpretation – Programs are interpreted by another program (an interpreter)
3. Hybrid – Programs translated into an intermediate language for easy interpretation
4. Just –in-time – Hybrid implementation, then compile sub programs code the first
time they are called.
5. Pure Interptretation
COMPILATION
- Translated 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 (e.g. identifiers, operators, keywords).
*Syntactic analysis: transforms lexical units into parse trees whichrepresent
*he syntactic structure of the program.
*Semantics analysis check for errors hard to detect during syntacticanalysis;
generate intermediate code.
*Code generation – Machine code is generated
- INTERPRETATION
- Easier implementation of programs (run-time errors can easily andimmediately be
displayed).
- Slower execution (10 to 100 times slower than compiled programs)
- Often requires more memory space and is now rare3 for traditional high level
languages.
- Significant comeback with some Web scripting languages like PHP and JavaScript.
- Interpreters usually implement as a read-eval-print loop:
*Read expression in the input language (usually translating it in some internal
form)
*Evaluates the internal forms of the expression
*Print the result of the evaluation
*Loops and reads the next input expression until exit
- Interpreters act as a virtual machine for the source language:
*Fetch execute cycle replaced by the read-eval-print loop
*Usually has a core component, called the interpreter “run-time”that is a compile
program running on the native machine.
HYBRID IMPLEMENTAITON
- This involves a compromise between compilers and pure interpreters. A high level
program is translated to an intermediate language that allows easy interpretation.
- Hybrid implementation is faster than pure interpretation. Examples of the
implementation occur in Perl and Java.
*Perl programs are partially compiled to detect errors before interpretation.
*Initial implementat6ions of Java were hybrid. The intermediate form, byte
code, provides portability to any machine that has a bytecode interpreter and a
run time system (together, these are called Java Virtual Machine).
JUST-IN-TIME IMPLEMENTATION
This implementation initially translates programs to an intermediate language then
compile the intermediate language of the subprograms into machine code when they are
called.
- Machine code version is kept for subsequent calls. Just-in-time systems are widely
used for Java programs. Also .NET languages are implemented with a JIT system.
Study Questions:
1. Why is it useful for a programmer to have some background in language design, even
though he or she may never actually design a programming language?
2. What does it mean for a program to be reliable?
3. What is: Aliasing?; What is exceptional handling?
4. Why is readability important in writability?
5. What are the three fundamental features of an object-oriented language?
6. What role does symbol table play in compiler?
7. What does a linker do?
8. What are the advantages in implementing a language with pure interpreter?
9. What are the three general methods of implementing a programming language?
10. Which produces faster program execution, a compiler or a pure interpreter and
how?
ALGOL
ALGOL 68 (short for ALGOrithmic Language 1968) is an imperative computer
programming language that was conceived as a successor to the ALGOL 60 programming
language, designed with the goal of a much wider scope of application and more
rigorously defined syntax and semantics. ALGOL 68 features include expression-based
syntax, user-declared types and structures/tagged-unions, a reference model of
variables and reference parameters, string and array and matrix slicing and also
concurrency.
ALGOL 68 was designed by IFIP Working Group 2.1. On December 20, 1968 the
language was formally adopted by Working Group 2.1 and subsequently approved for
publication by the General Assembly of IFIP.
ALGOL 68 was defined using a two-level grammar formalism invented by Adriaanvan
Wijngaarden. Van Wijngaarden grammars use a context-free grammar to generate an
infinite set of productions that will recognize a particular ALGOL 68 program; notably,
they are able to express the kind of requirements that in many other programming
language standards are labelled.
Special characters
Most of Algol's "special" characters (×, ÷, ≤, ≥, ≠, ¬, ∨, ∧, , →, ↓, ↑, □, ⌊, ⌈, ⎩, ⎧, ○,
⊥and ¢) can be found on the IBM 2741 keyboard with the APL "golf-ball" print head
inserted, these became available in the mid 1960s while ALGOL 68 was being drafted.
These characters are also part of the unicode standard and most of them are available
in several popular fonts.
C++
C++ (pronounced "see plus plus") is a statically typed, free-form, multi-paradigm,
compiled, general-purpose programming language. It is regarded as an intermediate
levellanguage, as it comprises a combination of both high-level and low-level language
features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an
enhancement to the C language and originally named C with Classes. It was renamed C++
in 1983.
C++ is one of the most popular programming languages and its application domains
include systems software (such as Microsoft Windows), application software, device
drivers, embedded software, high-performance server and client applications, and
entertainment software such as video games.
C++ is sometimes called a hybrid language; it is possible to write object oriented or
procedural code in the same program in C++. This has caused some concern that some
C++ programmers are still writing procedural code, but are under the impression that it
is object orientated, simply because they are using C++. Often it is an amalgamation of
the two. This usually causes most problems when the code is revisited or the task is
taken over by another coder.
C++ continues to be used and is one of the preferred programming languages to develop
professional applications.
Language features
C++ inherits most of C's syntax. The following is Bjarne Stroustrup's version of the
Hello world program that uses the C++ standard library stream facility to write a
message to standard output:
#include <iostream>
int main()
{
std::cout<< "Hello, world!\n";
}
Within functions that define a non-void return type, failure to return a value before
control reaches the end of the function results in undefined behaviour (compilers
typically provide the means to issue a diagnostic in such a case). The sole exception to
this rule is the main function, which implicitly returns a value of zero.
C#
During the development of the .NET Framework, the class libraries were originally
written using a managed code compiler system called Simple Managed C (SMC). In
January 1999, Anders Hejlsberg formed a team to build a new language at the time
called Cool, which stood for "C-like Object Oriented Language". Microsoft had
considered keeping the name "Cool" as the final name of the language, but chose not to
do so for trademark reasons. By the time the .NET project was publicly announced at
the July 2000 Professional Developers Conference, the language had been renamed
C#, and the class libraries and ASP.NET runtime had been ported to C#.
Some notable distinguishing features of C# are:
1. It has no global variables or functions. All methods and members must be declared
within classes. Static members of public classes can substitute for global variables and
functions.
2. Local variables cannot shadow variables of the enclosing block, unlike C and C++.
Variable shadowing is often considered confusing by C++ texts.
3. C# supports a strict Boolean data type, bool. Statements that take conditions, such
as while and if, require an expression of a type that implements the true operator, such
as the boolean type. While C++ also has a boolean type, it can be freely converted to
and from integers, and expressions such as if(a) require only that a is convertible to
bool, allowing a to be an int, or a pointer. C# disallows this "integer meaning true or
false" approach, on the grounds that forcing programmers to use expressions that
return exactly bool can prevent certain types of common programming mistakes in C or
C++ such as if (a = b) (use of assignment = instead of equality ==).
4. In addition to the try...catch construct to handle exceptions, C# has a try...finally
construct to guarantee execution of the code in the finally block.
5. C# currently (as of version 4.0) has 77 reserved words.
6. Multiple inheritances are not supported, although a class can implement any number
of interfaces. This was a design decision by the language's lead architect to avoid
complication and simplify architectural requirements throughout CLI.
2. Reference types: they have the notion of referential identity - each instance of a
reference type is inherently distinct from every other instance, even if the data within
both instances is the same. This is reflected in default equality and inequality
comparisons for reference types, which test for referential rather than structural
equality, unless the corresponding operators are overloaded (such as the case for
System. String). In general, it is not always possible to create an instance of a
reference type, nor to copy an existing instance, or perform a value comparison on two
existing instances, though specific reference types can provide such services by
exposing a public constructor or implementing a corresponding interface (such as
ICloneable or IComparable). Examples of reference types are object (the ultimate base
class for all other C# classes), System. String (a string of Unicode characters), and
System. Array (a base class for all C# arrays). Both type categories are extensible
with user-defined types.
Study Questions
1. Make an educated guess as to the most common syntax error in Lisp programs.
2. Describe in detail the three most important reasons, in your opinion, why ALGOL
60 did not become a very used language.
3. Do you think language design committee is a good idea? Support your opinion.
4. Give a brief general description of a markup/programming hybrid language
5. Why in your opinion, do new scripting languages appear more frequently than new
compiled languages?
6. Write a program to implement N factorial in; Machine Language, Assembly Language,
Scripting Language and any other five high level languages.