CSC 432 - Comp Programming II
CSC 432 - Comp Programming II
…
(Did you know that APL means “A Programming language”)
lECTURE 1
😁
influenced by the power of the language you speak (tom scott made a video about this
), and for programming languages, the quality of the algorithm you implement is
influenced by the available constructs in the programming language.
2. Improved background for choosing appropriate Languages: Instead of using the most
appropriate language, many programmers use the language they are most familiar
with even though it is poorly suited for the project
3. Increased ability to learn new languages: Just like knowing the grammar will make
learning English easier, knowing the concepts of a language will make it easier to
learn. (like if you know OOP concepts you can very easily learn any OOP language)
4. Better Understanding of the Significance of implementation
5. Better use of languages that are already known
6. The overall advancement of computing
Text Processing Applications Involve manipulating natural language text as data (not
numbers). SNOBOL and C have strong text-processing capabilities.
😁
concepts (So basically, instead of having functions inside classes, the functions are the
root directory…And Kotlin is also a functional language but who’s asking ).
3. Logic - Here computations are made with logical inference and rules (with no
particular order). Examples are PROLOG and CLIPS. It may also include OOP
concepts.
Compilation
1. Translated high level program (source language) into machine code (machine
language
2. Slow translation, fast execution
3. Compilation process has several phases
a. Lexical analysis converts characters in the source program into lexical units
(e.g. identifiers, operators, keywords).
b. Syntactic analysis: Transforms lexical units into parse trees which represent
the syntactic structure of the program.
c. Semantics analysis check for errors hard to detect during syntactic analysis
d. Generate intermediate code.
e. Code generation – Machine code is generated
Interpretation
1. Easier implementation of programs (run-time errors can easily and immediately be
displayed).
2. Slower execution (10 to 100 times slower than compiled programs)
3. Often requires more memory space and is now rare for traditional high level
languages.
4. Significant comeback with some Web scripting languages like PHP and JavaScript.
5. Interpreters usually implement as a read-eval-print loop:
a. Read expression in the input language (usually translating it in some internal
form)
b. Evaluates the internal forms of the expression
c. Print the result of the evaluation
d. Loops and reads the next input expression until exit
6. Interpreters act as a virtual machine for the source language:
a. Fetch execute cycle replaced by the read-eval-print loop
b. Usually has a core component, called the interpreter “run-time” that is a
compile program running on the native machine.
Hybrid
1. This involves a compromise between compilers and pure interpreters. A high level
program is translated to an intermediate language that allows easy interpretation
2. Hybrid implementation is faster than pure interpretation. Examples of the
implementation occur in Perl and Java.
a. Perl programs are partially compiled to detect errors before interpretation.
b. Initial implementations of Java were hybrid. Java’s 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 and then
compiles the intermediate language of the subprograms into machine code when they are
called. The machine code version is kept for subsequent calls.
Just-in-time systems are widely used for Java and .NET languages.
Algol
ALGOL 68 (ALGOrithmic Language 1968) is a computer programming language that was
designed as a successor to ALGOL 60, with a wider scope of application and more rigorously
defined syntax and semantics. It features expression-based syntax, user-declared types,
structures, and tagged unions; a reference model of variables, and support for string and array
slicing, as well as concurrency. ALGOL 68 was designed by IFIP Working Group 2.1 and
was formally adopted by them on December 20, 1968. It was defined using a two-level
grammar formalism created by Adriaan van Wijngaarden, which allows for a more expressive
and flexible way of defining the language's syntax.
C++
is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming
language. It is regarded as an intermediate-level language, cuz it has both high-level and
low-level language features. developed by Bjarne Stroustrup starting in 1979 at Bell Labs as
an enhancement to the C language. It was originally named "C with Classes" and then
renamed "C++” in 1983.
It is one of the most popular languages cuz it’s used in; systems software (like Windows),
application software, device drivers, embedded software, high-performance server and client
applications, and video games.
C++ is sometimes called a "hybrid language" cuz it can be object-oriented or procedural.
Some C++ programmers are still writing procedural code, but think it is object orientated.
Most time it’s both OO and procedural.
Language Features
C++ inherits most of C's syntax, but also includes additional features like OOP.
The above code is a simple C++ program that uses the C++ standard library's stream facility
to write "Hello, world!" to the standard output. In C++, if a function is defined with a
non-void return type and no value is returned before the end of the function, it results in
undefined behavior. The only exception to this rule is the main function, which will return a
value of zero if no other value is explicitly returned.
C#
C# is a programming language developed by Microsoft as part of the .NET Framework. It
was originally developed under the name "Cool" (C-like Object Oriented Language) but was
later renamed to C#. C# is a modern, object-oriented language that is similar to C++ in terms
of syntax. Some of the notable features of C# include:
1. It does not have global variables or functions, all methods and members must be
declared within classes.
2. local variables cannot shadow variables of the enclosing block. //shadowing is when a
variable within a scope has the same name as a variable declared in the outer scope
3. It has a strict Boolean data type.
4. It has a try-finally construct to guarantee the execution of code in the finally block.
5. It has 77 reserved words
6. It does not support multiple inheritances but a class can implement any number of
interfaces.
Value types are plain aggregations of data, instances of value types do not have a referential
identity or referential comparison semantics. Equality and inequality comparisons for value
types compare the actual data values within the instances unless the corresponding operators
are overloaded. They are derived from System.ValueType always has a default value and can
always be created and copied. Examples of value types are all primitive types, such as int,
float, char and System.DateTime. Value types cannot derive from each other and cannot have
an explicit default constructor.
Reference types 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. In general, it's not always possible to create an instance of a reference type, copy an
existing instance, or perform a value comparison on two existing instances. Examples of
reference types are object, System.String and System.Array.
lECTURE 2
Programming languages are computer languages used by programmers to communicate with
computers. It is a set of instructions written in any specific language ( C, C++, Java, Python)
to perform a specific task. Like developing websites, desktop, and mobile app.
Low-Level Languages
This is a type of programming language that is machine-dependent and is directly
understood by the computer's processor without the need for a compiler or interpreter. It is
divided into two parts: Machine language and Assembly Language.
High-Level Language
High-level programming language (HLL) is designed for developing user-friendly
software programs and websites. These languages require a compiler or interpreter to
translate the program into machine language before it can be executed. The main advantage
of high-level languages is that they are easy to read, write, and maintain. Examples of
high-level programming languages include Python, Java, JavaScript, PHP, C#, C++,
Objective C, Cobol, Perl, Pascal, LISP, FORTRAN, and Swift. HLL is divided into three
parts.
1. Procedural Oriented Programming (POP) language: Is derived from structured
programming and is based on the procedure call concept. It divides a program into
small procedures called routines or functions. The advantage of POP language is that
it helps programmers easily track the program flow and the code can be reused in
different parts of the program. Examples of POP languages include C, FORTRAN,
Basic, Pascal, etc.
2. Object-Oriented Programming (OOP) language: Is based on objects. Here programs
are divided into small parts called objects. It is used to implement real-world entities
like inheritance, polymorphism, abstraction, etc to make the program reusable,
efficient, and easy to use. The main advantage of object-oriented programming is that
it is faster and easier to execute, maintain, modify, as well as debug. Examples of
OOP languages include C++, Java, Python, C#, etc.
3. Natural language: Is a part of human languages such as English, Russian, German,
and Japanese. It is used by machines to understand, manipulate, and interpret human
language. It is used by developers to perform tasks such as translation, automatic
summarization, Named Entity Recognition (NER), relationship extraction, and topic
segmentation. The main advantage of natural language is that it helps users to ask
questions in any subject and directly respond within seconds.
1. Bliss
2. ChucK
3. CLIST
4. HyperTalk
5. Modula-2
6. Oberon
7. Component Pascal
8. MATLAB
9. Occam
10. PL/C
11. PL/I
12. Rapia
13. RPG
Scripting Languages
Scripting languages are programming languages that control an application. Scripts can
execute independent of any other application. They are mostly embedded in the application
that they control. They are used for automation or communication with external programs.
1. Applescript (LOL)
2. AWK
3. BeanShell
4. ColdFusion
5. F-Script
6. JASS
7. Mondrian
8. PHP: Hypertext Preprocessor(How that makes sense? I don;t know too) is one of the
very popularly used general purpose scripting languages. It is developed for creating
dynamic web pages and supports a command line interface capability
9. Revolution
10. Tcl
11. VBScript
12. Windows Powershell
Markup Languages
A markup language is an artificial language that uses annotations to text that define how the
text is to be displayed.
1. Curl
2. SGML
3. HTML: Hypertext Markup Language is the most prominent markup language used for
web pages. It is written in the form of HTML tags that are surrounded by angular
brackets. HTML tags describe the appearance of the text in a document.
4. XML: Extensible Markup Language. It is extensible because it allows the users to
define their own XML elements. It supports the sharing of structured data over the
Internet and the encoding and serializing of data.
5. XHTML: It is a markup language that is similar to HTML and follows the XML
syntax. It is midway between HTML and XML.
Logic-Based Programming Languages
Logic programming is a type of programming paradigm which is largely based on formal
logic. It is used for expressing facts and rules about some problem domain.
1. ALF
2. Fril
3. Janus
4. Leda
5. Oz
6. Poplog
7. Prolog: It is a general-purpose programming language that supports logic
programming and is often linked with artificial intelligence and computational
linguistics. The language is declarative and the program logic is expressed in the form
of relations
8. ROOP
1. ABCL
2. Afnix
3. Clik
4. E
5. Joule
6. Limbo
7. Pick
8. Salsa
9. SR
1. Agora
2. BETA
3. Cecil
4. Bava
5. Lisaac
6. MOO
7. Moto
8. Object-Z
9. Obliq
10. Oxygen
11. Pliant
12. Prograph
13. REBOL
14. Scala
15. Self
16. Slate
17. IO
Python
It is a user-friendly language. It was developed in the 1990s. It is mostly used in Machine
learning, Artificial intelligence, Big Data, GUI based desktop applications, and Robotics.
Advantage
1. Easy to read, write and understand
2. Integrates nicely with other languages
3. Executes line by line, so easy to find bugs
4. It is platform independent, so write once - run everywhere
Disadvantage
1. Not suitable for developing games and mobile apps
2. Slower than C and C++ because it uses interpreter
Java
It is simple, secure, platform-independent, reliable, architecture-neutral high-level
programming language developed by Sun Microsystems in 1995. Now, Java is owned by
Oracle.
Advantage
1. Write, compile, learn, and debug
2. It provides an ability to run the same program on different platforms.
3. It is highly secured because there are no explicit pointers
4. It can perform multiple tasks at the same time
Disadvantage
1. Consumes more memory and slower than languages like C or C++ (Then again, what
is ever faster than C of C++)
2. It does not provide a backup facility
C
It is a popular, simple, and flexible general-purpose language.Developes in 1972 at AT&T. It
is a combination of both low-level and high-level language.
Advantages
1. It is easy to learn.
2. It fast, efficient, portable, easy to extend, powerful, and flexible.
3. It is used to perform complex calculations and operations such as MATLAB
4. It provides dynamic memory allocation to allocate memory at the run time
Disadvantages
1. It is very difficult to find the errors.
2. It does not support OOP concepts (constructors, destructors, abstraction,
polymorphism, encapsulation, and namespace)
C++
It was developed by BjarneStroustrup in 1980. It is similar to the C, but also includes some
additional features such as exception handling, object-oriented programming, type checking,
etc.
Advantages
1. It is a simple and portable structured programming language.
2. It supports OOPs features such as Abstraction, Inheritance, Encapsulation.
3. It provides high-level abstraction and is more efficient for general-purpose
programming
4. It is more compatible with the C language.
Disadvantages
1. It is not secured as compared languages like Java or Python.
2. It doesn’t have a garbage collection.
3. It is difficult to debug large as well as complex web applications.
C#
C# (pronounced as C sharp) is a modern, general-purpose, and object-oriented programming
language used with XML based Web services on the .NET platform. It is easier to learn for
users with knowledge of languages like C, C++, or Java.
Advantages
1. It is a modern, type-safe, easy, fast, and open-source language that is easily integrated
with Windows.
2. The maintenance is lower than the C++.
3. It is a pure object-oriented programming language.
4. It includes a strong memory backup facility. That's why it avoids the problem of
memory leakage.
Disadvantages
1. It is less flexible because it is completely based on Microsoft .Net framework.
2. It is difficult to write, understand, debug, and maintain multithreaded applications.
Javascript
It is a scripting language used on both client-side and server-side. It is developed in the 1990s
for the Netscape Navigator web browser. It allows programmers implement complex features
to make web pages alive.
Advantage
1. It adds behavior and interactivity on the web page.
2. It can be used to decrease the loading time from the server.
3. It has the ability to create attractive, dynamic websites, and rich interfaces.
4. It is simple, versatile, and lightweight
5. Its syntax are easy to understand.
Disadvantage
1. It is completely based on the browser.
2. It does not support multiple inheritance.
3. It is less secure compared to other programming languages.
PHP
GO
Ruby
A Categorical List of Prog Languages
Too much note there jare. I don’t think it’s necessary
For prefix, pray it doesn’t come out… or you can just guess I dont know
Example 1
A + B * C in Infix
+ A * B C in Prefix.
A B C * + in postfix
Example 2
Infix Expression : (A + B) * C
Prefix Expression : * + A B C
Postfix Expression: A B + C *
Example 3
Infix Expression : A + B * C + D
Prefix Expression: + + A * B C D
Postfix Expression: A B C * + D +
Example 4
Infix Expression : (A + B) * (C + D)
Prefix Expression : * + A B + C D
Postfix Expression : A B + C D + *
Example 5
Infix Expression : A * B + C * D
Prefix Expression : + * A B * C D
Postfix Expression : A B * C D * +
Example 6
Infix Expression : A + B + C + D
Prefix Expression : + + + A B C D
Postfix Expression : A B + C + D +
Lecture 3_3
Language Semantics
Semantics is the study of the relationship between words and how we draw meaning from
those words.
Semantic Theories
ACC-FOLD
● Conceptual Semantics: It deals with the most basic concept without adding context
with our thoughts and feelings.
● Denotation: Describes the meaning of a program as a mathematical function that maps
inputs to outputs.
Expressions
A series of variables, operators, and method calls that evaluates to (or return) a single value.
Like the ones in green below
● const y = 2 + 3.
● y = getAnswer().
● 12 + square ( 7 + 5 ) + square( square (2)).
Statements
A statement is code that forms a complete unit of execution and is usually terminated with a
semicolon (;).
Types of Statements
1. Expression statements: They sha perform an expression
E.g
● aValue = 8933.234; //assignment statement (In python, this can be a
declarative statement sha)
● aValue++; //increment
● System.out.println(aValue); //method call
● Int age = new Int(4); //object creation
Blocks
These are groups of zero or more statements usually grouped together with braces { }.
E.g
● If…Else blocks
The If…Else parts are statements, but the things it does after are blocks
● Function blocks
Example
X→ε
X → a | aY
Y→b
Type - 2 Grammar
Type-2 grammars generate context-free languages.
The productions must be in the form A → γ
where A ∈ N (Non terminal)
and γ ∈ (T ∪ N)* (String of terminals and non-terminals).
These languages generated by these grammars are be recognized by a non-deterministic
pushdown automaton.
Example
S→Xa
X→a
X → aX
X → abc
X→ε
Type - 1 Grammar
Type-1 grammars generate context-sensitive languages. The productions must be in the form
αAβ→αγβ
where A ∈ N (Non-terminal)
and α, β, γ ∈ (T ∪ N)* (Strings of terminals and non-terminals)
The strings α and β may be empty, but γ must be non-empty.
The rule S → ε is allowed if S does not appear on the right side of any rule. The languages
generated by these grammars are recognized by a linear bounded automaton.
Example
AB → AbBc
A → bcA
B→b
Type - 0 Grammar
Type-0 grammars generate recursively enumerable languages. The productions have no
restrictions. They are any phase structure grammar including all formal grammars.
They generate the languages that are recognized by a Turing machine.
The productions can be in the form of α → β where α is a string of terminals and
nonterminals with at least one non-terminal and α cannot be null. β is a string of terminals
and non-terminals.
Example
S → ACaB
Bc → acB
CB → DB
aD → Db
Regular Expressions
A Regular Expression can be recursively defined as follows −
● ε indicated empty string (L (ε) = {ε})
● Φ denoting an empty language. (L (φ) = { })
● x indicated L = {x}
● If X is a Regular Expression denoting the language L(X) and Y is a Regular
Expression denoting the language L(Y), then
○ X + Y is a Regular Expression corresponding to the language L(X) ∪ L(Y)
where L(X+Y) = L(X) ∪ L(Y).
○ X . Y is a Regular Expression corresponding to the language L(X) .
L(Y) where L(X.Y) = L(X) . L(Y)
○ R* is a Regular Expression corresponding to the language L(R*)where L(R*)
= (L(R))*
Declaration
A declaration is a statement describing an identifier, such as the name of a variable or a
function
Lecture 3_4
Stacks
If it comes out, skip it, you have tried na…ahn ahn
Lecture 3_5
Language Semantics
Lecture 3_6
Programming Language Series
Compiled
A compiled language is one where the program is first converted into machine code and then
executed directly on the target machine. E.g C, C++, Go, Rust…
Advantages:
1. Execution is faster
2. It is more efficient
3. It is converted to machine code, so it gives developers more control of memory and
hardware
Disadvantages:
Interpreted
An interpretive language is one in which the instructions are read and executed by some other
program called an interpreter (It is usually written in that language). E.g PHP, Python, Ruby,
Perl…
Advantages
The main disadvantage is that it is slower than compiled code, but newer technologies like
Just-In-Time compilation, where frequently executed sequences are compiled, have narrowed
the gap.
Bytecode Languages
These are both compiled and interpreted languages. Programs are first compiled from human
readable code to bytecode (bytecode is efficient to interpret and is in between machine
language and high-level language), and then a virtual machine interprets the code like an
interpreter would.
Advantages
1. There is a delay converting to bytecode, but the execution is faster than normal
interpreted
2. It is machine independent (as in the bytecode can be executed on any machine that
has the language's virtual machine without recompilation)
Type checking
Type checking is the process of verifying and enforcing the constraints of variable types,
either at compile time (statically) or at runtime (dynamically).
Like 1 + "2" will give an error in most languages (except rubbish languages like Javascript)
1. Static type checking: This is checking the data types at compile time instead of
runtime. This is faster, uses less memory, and makes it harder to have errors … E.g
C++, C, C#, Java, Fortran…
2. Dynamic type checking: This is verifying the type safety at runtime. This happens
when you cannot verify if a safecast can happen (Like you cannot tell if you can
safely downcast an object of 2 classes at compile time). Examples of languages that
use this are Python, PHP, Javascript Objective C.
Common Misconception
A common misconception is that all statically-typed languages are also strongly-typed
languages, and that dynamically-typed languages are also weakly-typed languages. This isn’t
true. Python is a good example for this.
Python is strongly typed (because variables are bound to specific data types from start), but
also uses dynamic type checking (because it checks at runtime).
Garbage Collection
Shalaye first:
When you allocate memory (like by creating a variable), that memory is allocated to
either the stack or the heap.
The stack is super fast at allocating and clearing memory all by itself, but the size and
state cannot change.
But memory alocated in heap will sit till the end of the prorgam except you manually
allocate and deallocate, but it’s state can change.
Why Do We Need GC
As you allocate more and more memory to the heap, memory size will begin to add up –
resulting in a heap overflow.
Reference Counting
In this algo, anytime you reference a memory location on the heap, a counter for that
particular memory location increments by 1. Every time a reference to that location is
deleted, the counter decrements by 1. When that counter gets to 0, then that particular
memory location is garbage collected.
Mark- Sweeping
Goan Read it if you want
Mark-Compact
Goan Read it if you want
Copying
Goan Read it if you want
Generational GC
Goan Read it if you want