This document discusses imperative and object-oriented programming languages. It covers basic concepts like state, variables, expressions, assignments, and control flow in imperative languages. It also discusses procedures and functions, including passing parameters, stack frames, and recursion. Finally, it briefly mentions the differences between call by value and call by reference.
Compiler Construction | Lecture 6 | Introduction to Static AnalysisEelco Visser
Lecture introducing the need for static analysis in addition to parsing, the complications caused by names, and an introduction to name resolution with scope graphs
Compiler Construction | Lecture 6 | Introduction to Static AnalysisEelco Visser
Lecture introducing the need for static analysis in addition to parsing, the complications caused by names, and an introduction to name resolution with scope graphs
C programming_MSBTE_Diploma_Pranoti DokePranoti Doke
"1.1 Structure of ‘C’program, Assembler, Linker, Compiler, Interpreter.
1.2 ‘C’character set-keywords, identifiers, types of constants (Integer, single character, string, and real) variables, scope of variables, concept of ASCII.
1.3 Data types: integer- unsigned, signed, long, float- float, double, character char, string, octal, hexadecimal
1.4 Algorithm and flow chart.
1.5 Formatted input and output statements. Input and output function.
1.6 Operators and expressions:
a. Operators in ‘C’- arithmetic, logical, assignment, relational, increment and decrement, conditional, bit wise, special operators
b. Expressions
c. Precedence and associatively."
"2.1 Decision making if statement (if, if-else, nested if-else), switch –case statement.
2.2 Repetition in ‘C’ (loop control
statement) while, do-while and for loop, break and continue statement, nested loops
"
"3.1 Introduction to Array and its types
3.2 Declaration, initialization of array,
accessing elements of an array, adding,
deleting, sorting & searching.
3.3 Introduction to string Initializing,
declaring and display of string
3.4 String handling functions from standard library (strlen (), strcpy (), strcat (), strcmp(), strlwr(),strupr()):
"
"4.1 Concept and need of functions
4.2 Library functions: Math functions,
String handling functions, other
miscellaneous functions.
4.3 Writing User defined functions, scope of variables.
4.4 Parameter passing: call by value, call by reference.
4.5 Recursive functions
"
"5.1 Concept of pointer and pointer variables, initialization of pointer, call-by reference.
5.2 Pointer arithmetic.
5.3 Handling arrays using pointers
5.4 Handling functions using pointers
"
"6.1 Introduction and Features and Syntax of structure
6.2 Declaration and Initialization of
Structures
6.3 Initializing, assessing structure members using pointers
6.4 Type def, Enumerated Data Type,
using structures in C Program
6.5 Operations on structure."
C programming_MSBTE_Diploma_Pranoti DokePranoti Doke
"1.1 Structure of ‘C’program, Assembler, Linker, Compiler, Interpreter.
1.2 ‘C’character set-keywords, identifiers, types of constants (Integer, single character, string, and real) variables, scope of variables, concept of ASCII.
1.3 Data types: integer- unsigned, signed, long, float- float, double, character char, string, octal, hexadecimal
1.4 Algorithm and flow chart.
1.5 Formatted input and output statements. Input and output function.
1.6 Operators and expressions:
a. Operators in ‘C’- arithmetic, logical, assignment, relational, increment and decrement, conditional, bit wise, special operators
b. Expressions
c. Precedence and associatively."
"2.1 Decision making if statement (if, if-else, nested if-else), switch –case statement.
2.2 Repetition in ‘C’ (loop control
statement) while, do-while and for loop, break and continue statement, nested loops
"
"3.1 Introduction to Array and its types
3.2 Declaration, initialization of array,
accessing elements of an array, adding,
deleting, sorting & searching.
3.3 Introduction to string Initializing,
declaring and display of string
3.4 String handling functions from standard library (strlen (), strcpy (), strcat (), strcmp(), strlwr(),strupr()):
"
"4.1 Concept and need of functions
4.2 Library functions: Math functions,
String handling functions, other
miscellaneous functions.
4.3 Writing User defined functions, scope of variables.
4.4 Parameter passing: call by value, call by reference.
4.5 Recursive functions
"
"5.1 Concept of pointer and pointer variables, initialization of pointer, call-by reference.
5.2 Pointer arithmetic.
5.3 Handling arrays using pointers
5.4 Handling functions using pointers
"
"6.1 Introduction and Features and Syntax of structure
6.2 Declaration and Initialization of
Structures
6.3 Initializing, assessing structure members using pointers
6.4 Type def, Enumerated Data Type,
using structures in C Program
6.5 Operations on structure."
We start with a linguistic discussion of language, its properties, and the study of language in philosophy and linguistics. We then investigate natural languages, controlled languages, and artificial languages to emphasise the human ability to control and construct languages. At the end, we arrive at the notion of software languages as means to communicate software between people.
Declarative Type System Specification with StatixEelco Visser
In this talk I present the design of Statix, a new constraint-based language for the executable specification of type systems. Statix specifications consist of predicates that define the well-formedness of language constructs in terms of built-in and user-defined constraints. Statix has a declarative semantics that defines whether a model satisfies a constraint. The operational semantics of Statix is defined as a sound constraint solving algorithm that searches for a solution for a constraint. The aim of the design is that Statix users can ignore the execution order of constraint solving and think in terms of the declarative semantics.
A distinctive feature of Statix is its use of scope graphs, a language parametric framework for the representation and querying of the name binding facts in programs. Since types depend on name resolution and name resolution may depend on types, it is typically not possible to construct the entire scope graph of a program before type constraint resolution. In (algorithmic) type system specifications this leads to explicit staging of the construction and querying of the type environment (class table, symbol table). Statix automatically stages the construction of the scope graph of a program such that queries are never executed when their answers may be affected by future scope graph extension. In the talk, I will explain the design of Statix by means of examples.
https://eelcovisser.org/post/309/declarative-type-system-specification-with-statix
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfJay Das
With the advent of artificial intelligence or AI tools, project management processes are undergoing a transformative shift. By using tools like ChatGPT, and Bard organizations can empower their leaders and managers to plan, execute, and monitor projects more effectively.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
4. Imperative and Object-Oriented Languages
natural
language
natural
language
translator
4
compiler
software
language
machine
language
5. Imperative and Object-Oriented Languages 5
Traditional compilers
architecture
source
code
errors
parse generate
check
machine
code
6. Imperative and Object-Oriented Languages 6
Modern compilers in IDEs
architecture
source
code
parse generate
machine
code
check
7. Imperative and Object-Oriented Languages 7
Compilers are inverted abstractions
architecture
source
code
machine
code
abstract
8. Imperative and Object-Oriented Languages
Compilers Invert Abstractions
Computers speak machine language
• basic instructions to move around and combine small things
Humans do not speak machine language very well
• “mov; loadi; jump” anyone?
Programming languages abstract from machine language
• capture common programming patterns in language constructs
• abstract from uninteresting variation in machines
Compilers invert the abstractions of programming languages
8
9. Imperative and Object-Oriented Languages 9
Portability: Platform Independence
architecture
source
code
parse
generate
GPU
code
check
generate
x86
code
10. Imperative and Object-Oriented Languages
Understanding Compilers Requires …
Understanding machine languages
• machine architecture, instruction sets
Understanding programming language (abstraction)s
• memory, control-flow, procedures, modules, …
• safety mechanisms: type systems & other static analyses
Understanding how to define mapping from PL to ML
• semantics of such mappings
• techniques to implement such mappings
10
11. Imperative and Object-Oriented Languages 11
Imperative Languages
state & statements
procedures
types
Object-Oriented Languages
objects & messages
types
14. basic concepts
Imperative and Object-Oriented Languages
State
Machine state
• a pile of data stored in memory
• memory hierarchy: registers, RAM, disk, network, …
Imperative program
• computation is series of changes to memory
• basic operations on memory (increment register)
• controlling such operations (jump, return address, …)
• control represented by state (program counter, stack, …)
14
15. registers
Imperative and Object-Oriented Languages
x86 family
general purpose registers
• accumulator AX - arithmetic operations
• counter CX - shift/rotate instructions, loops
• data DX - arithmetic operations, I/O
• base BX - pointer to data
• stack pointer SP, base pointer BP - top and base of stack
• source SI, destination DI - stream operations
15
16. registers
Imperative and Object-Oriented Languages
x86 family
general purpose registers
• accumulator AX - arithmetic operations
• counter CX - shift/rotate instructions, loops
• data DX - arithmetic operations, I/O
• base BX - pointer to data
• stack pointer SP, base pointer BP - top and base of stack
• source SI, destination DI - stream operations
special purpose registers
• segments SS, CS, DS, ES, FS, GS
• flags EFLAGS
15
17. mov AX [1]
mov CX AX
L: dec CX
mul CX
cmp CX 1
ja L
mov [2] AX
basic concepts
Imperative and Object-Oriented Languages
Example: x86 Assembler
16
18. read memorymov AX [1]
mov CX AX
L: dec CX
mul CX
cmp CX 1
ja L
mov [2] AX
basic concepts
Imperative and Object-Oriented Languages
Example: x86 Assembler
16
19. read memorymov AX [1]
mov CX AX
L: dec CX
mul CX
cmp CX 1
ja L
mov [2] AX
basic concepts
Imperative and Object-Oriented Languages
Example: x86 Assembler
16
write memory
20. read memorymov AX [1]
mov CX AX
L: dec CX
mul CX
cmp CX 1
ja L
mov [2] AX
basic concepts
Imperative and Object-Oriented Languages
Example: x86 Assembler
16
write memory
calculation
21. read memorymov AX [1]
mov CX AX
L: dec CX
mul CX
cmp CX 1
ja L
mov [2] AX
basic concepts
Imperative and Object-Oriented Languages
Example: x86 Assembler
16
write memory
calculation
jump
26. basic concepts
Imperative and Object-Oriented Languages
Memory & Control Abstractions
Memory abstractions
• variables: abstract over data storage
• expressions: combine data into new data
• assignment: abstract over storage operations
Control-flow abstractions
• structured control-flow: abstract over unstructured jumps
• ‘go to statement considered harmful’ Edgser Dijkstra, 1968
18
27. states & statements
Imperative and Object-Oriented Languages
Example: C
int f = 1
int x = 5
int s = f + x
while (x > 1) {
f = x * f ;
x = x - 1
}
19
28. states & statements
Imperative and Object-Oriented Languages
Example: C
int f = 1
int x = 5
int s = f + x
while (x > 1) {
f = x * f ;
x = x - 1
}
19
variable
29. states & statements
Imperative and Object-Oriented Languages
Example: C
int f = 1
int x = 5
int s = f + x
while (x > 1) {
f = x * f ;
x = x - 1
}
19
variable
expression
30. states & statements
Imperative and Object-Oriented Languages
Example: C
int f = 1
int x = 5
int s = f + x
while (x > 1) {
f = x * f ;
x = x - 1
}
19
variable
expression
assignment
31. states & statements
Imperative and Object-Oriented Languages
Example: C
int f = 1
int x = 5
int s = f + x
while (x > 1) {
f = x * f ;
x = x - 1
}
19
variable
expression
assignment
control flow
32. states & statements
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
var f := 1
var x := 5
var s := f + x
in
while x > 1 do (
f := x * f ;
x := x - 1
)
end
20
33. states & statements
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
var f := 1
var x := 5
var s := f + x
in
while x > 1 do (
f := x * f ;
x := x - 1
)
end
20
variable
34. states & statements
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
var f := 1
var x := 5
var s := f + x
in
while x > 1 do (
f := x * f ;
x := x - 1
)
end
20
variable
expression
35. states & statements
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
var f := 1
var x := 5
var s := f + x
in
while x > 1 do (
f := x * f ;
x := x - 1
)
end
20
variable
expression
assignment
36. states & statements
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
var f := 1
var x := 5
var s := f + x
in
while x > 1 do (
f := x * f ;
x := x - 1
)
end
20
variable
expression
assignment
control flow
38. push 21
push 42
call _f
add SP 8
push BP
mov BP SP
mov AX [BP + 8]
mov DX [BP + 12]
add AX DX
pop BP
ret
Imperative and Object-Oriented Languages
Example: x86 Assembler
22
modularity
39. push 21
push 42
call _f
add SP 8
push BP
mov BP SP
mov AX [BP + 8]
mov DX [BP + 12]
add AX DX
pop BP
ret
pass parameter
Imperative and Object-Oriented Languages
Example: x86 Assembler
22
modularity
40. push 21
push 42
call _f
add SP 8
push BP
mov BP SP
mov AX [BP + 8]
mov DX [BP + 12]
add AX DX
pop BP
ret
pass parameter
Imperative and Object-Oriented Languages
Example: x86 Assembler
22
new stack frame
modularity
41. push 21
push 42
call _f
add SP 8
push BP
mov BP SP
mov AX [BP + 8]
mov DX [BP + 12]
add AX DX
pop BP
ret
pass parameter
Imperative and Object-Oriented Languages
Example: x86 Assembler
22
access parameter
new stack frame
modularity
42. push 21
push 42
call _f
add SP 8
push BP
mov BP SP
mov AX [BP + 8]
mov DX [BP + 12]
add AX DX
pop BP
ret
pass parameter
Imperative and Object-Oriented Languages
Example: x86 Assembler
22
access parameter
new stack frame
modularity
old stack frame
43. push 21
push 42
call _f
add SP 8
push BP
mov BP SP
mov AX [BP + 8]
mov DX [BP + 12]
add AX DX
pop BP
ret
pass parameter
Imperative and Object-Oriented Languages
Example: x86 Assembler
22
access parameter
new stack frame
modularity
old stack frame
free parameters
44. procedures
Imperative and Object-Oriented Languages
Example: C
#include <stio.h>
/* factorial function */
int fac( int num ) {
if (num < 1)
return 1;
else
return num * fac(num - 1) ;
}
int main() {
int x = 10 ;
int f = fac( x ) ;
int x printf(“%d! = %dn”, x, f);
return 0;
}
23
45. procedures
Imperative and Object-Oriented Languages
Example: C
#include <stio.h>
/* factorial function */
int fac( int num ) {
if (num < 1)
return 1;
else
return num * fac(num - 1) ;
}
int main() {
int x = 10 ;
int f = fac( x ) ;
int x printf(“%d! = %dn”, x, f);
return 0;
}
23
formal parameter
46. procedures
Imperative and Object-Oriented Languages
Example: C
#include <stio.h>
/* factorial function */
int fac( int num ) {
if (num < 1)
return 1;
else
return num * fac(num - 1) ;
}
int main() {
int x = 10 ;
int f = fac( x ) ;
int x printf(“%d! = %dn”, x, f);
return 0;
}
23
formal parameter
actual parameter
47. procedures
Imperative and Object-Oriented Languages
Example: C
#include <stio.h>
/* factorial function */
int fac( int num ) {
if (num < 1)
return 1;
else
return num * fac(num - 1) ;
}
int main() {
int x = 10 ;
int f = fac( x ) ;
int x printf(“%d! = %dn”, x, f);
return 0;
}
23
formal parameter
actual parameter
local variable
48. procedures
Imperative and Object-Oriented Languages
Example: C
#include <stio.h>
/* factorial function */
int fac( int num ) {
if (num < 1)
return 1;
else
return num * fac(num - 1) ;
}
int main() {
int x = 10 ;
int f = fac( x ) ;
int x printf(“%d! = %dn”, x, f);
return 0;
}
23
formal parameter
actual parameter
local variable
recursive call
49. procedures
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
function fac( n: int ) : int =
let
var f := 1
in
if n < 1 then
f := 1
else
f := (n * fac(n - 1) );
f
end
var f := 0
var x := 5
in
f := fac( x )
end
24
50. procedures
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
function fac( n: int ) : int =
let
var f := 1
in
if n < 1 then
f := 1
else
f := (n * fac(n - 1) );
f
end
var f := 0
var x := 5
in
f := fac( x )
end
24
formal parameter
51. procedures
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
function fac( n: int ) : int =
let
var f := 1
in
if n < 1 then
f := 1
else
f := (n * fac(n - 1) );
f
end
var f := 0
var x := 5
in
f := fac( x )
end
24
formal parameter
actual parameter
52. procedures
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
function fac( n: int ) : int =
let
var f := 1
in
if n < 1 then
f := 1
else
f := (n * fac(n - 1) );
f
end
var f := 0
var x := 5
in
f := fac( x )
end
24
formal parameter
actual parameter
local variable
53. procedures
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
function fac( n: int ) : int =
let
var f := 1
in
if n < 1 then
f := 1
else
f := (n * fac(n - 1) );
f
end
var f := 0
var x := 5
in
f := fac( x )
end
24
formal parameter
actual parameter
local variable
recursive call
54. call by value vs. call by reference
Imperative and Object-Oriented Languages
Example: Tiger
let
type vector = array of int
function init(v: vector) =
v := vector[5] of 0
function upto(v: vector, l: int) =
for i := 0 to l do
v[i] := i
var v : vector := vector[5] of 1
in
init(v) ;
upto(v, 5)
end
25
56. Subtitle Text
Imperative and Object-Oriented Languages
Types & Type Checking
Type
• type is category of values
• operation can be applied to all values in some category
Type checking
• safety: ensure that operation is applied to right input values
• static: check during compile time
• dynamic: check during execution
27
57. dynamic & static typing
Imperative and Object-Oriented Languages
Type Systems
Machine code
• memory: no type information
• instructions: assume values of certain types
28
58. dynamic & static typing
Imperative and Object-Oriented Languages
Type Systems
Machine code
• memory: no type information
• instructions: assume values of certain types
Dynamically typed languages
• typed values
• run-time checking & run-time errors
28
59. dynamic & static typing
Imperative and Object-Oriented Languages
Type Systems
Machine code
• memory: no type information
• instructions: assume values of certain types
Dynamically typed languages
• typed values
• run-time checking & run-time errors
Statically typed languages
• typed expressions
• compile-time checking & compile-time errors
28
61. compatibility
Imperative and Object-Oriented Languages
Type Systems
Type compatibility
• value/expression: actual type
• context: expected type
Type equivalence
• structural type systems
• nominal type systems
29
62. compatibility
Imperative and Object-Oriented Languages
Type Systems
Type compatibility
• value/expression: actual type
• context: expected type
Type equivalence
• structural type systems
• nominal type systems
Subtyping
• relation between types
• value/expression: multiple types
29
63. type compatibility
Imperative and Object-Oriented Languages
Example: Tiger
let
type A = int
type B = int
type V = array of A
type W = V
type X = array of A
type Y = array of B
var a: A := 42
var b: B := a
var v: V := V[42] of b
var w: W := v
var x: X := w
var y: Y := x
in
y
end
30
64. record types
Imperative and Object-Oriented Languages
Type Systems
Record
• consecutively stored values
• fields accessible via different offsets
Record type
• fields by name, type, position in record
• structural subtyping: width vs. depth
31
type R1 = {f1 : int, f2 : int}
type R2 = {f1 : int, f2 : int, f3 : int}
type R3 = {f1 : byte, f2 : byte}
77. polymorphism
Imperative and Object-Oriented Languages
Type Systems
Ad-hoc polymorphism
overloading
• same name, different types, same operation
• same name, different types, different operations
type coercion
• implicit conversion
Universal polymorphism
subtype polymorphism
• substitution principle
parametric polymorphism
38
21 + 21
21.0 + 21.0
print(42)
print(42.0)
"foo" + "bar"
21 + "bar"
82. classes
Imperative and Object-Oriented Languages
Modularity
Classes
• generalization of record types
• characteristics of objects: attributes, fields, properties
• behavior of objects: methods, operations, features
42
public class C {
public int f1;
private int f2;
public void m1() { return; }
private C m2(C c) { return c; }
}
83. classes
Imperative and Object-Oriented Languages
Modularity
Classes
• generalization of record types
• characteristics of objects: attributes, fields, properties
• behavior of objects: methods, operations, features
Encapsulation
• interface exposure
• hide attributes & methods
• hide implementation
42
public class C {
public int f1;
private int f2;
public void m1() { return; }
private C m2(C c) { return c; }
}
84. inheritance vs. interfaces
Imperative and Object-Oriented Languages
Modularity
Inheritance
• inherit attributes & methods
• additional attributes & methods
• override behavior
• nominal subtyping
43
public class C {
public int f1;
public void m1() {…}
public void m2() {…}
}
public class D extends C {
public int f2;
public void m2() {…}
public void m3() {…}
}
public interface I {
public int f;
public void m();
}
public class E implements I {
public int f;
public void m() {…}
public void m’() {…}
}
85. inheritance vs. interfaces
Imperative and Object-Oriented Languages
Modularity
Inheritance
• inherit attributes & methods
• additional attributes & methods
• override behavior
• nominal subtyping
Interfaces
• avoid multiple inheritance
• interface: contract for attributes & methods
• class: provides attributes & methods
• nominal subtyping
43
public class C {
public int f1;
public void m1() {…}
public void m2() {…}
}
public class D extends C {
public int f2;
public void m2() {…}
public void m3() {…}
}
public interface I {
public int f;
public void m();
}
public class E implements I {
public int f;
public void m() {…}
public void m’() {…}
}
87. polymorphism
Imperative and Object-Oriented Languages
Type Systems
Ad-hoc polymorphism
overloading
• same method name, independent classes
• same method name, same class, different parameter types
overriding
• same method name, subclass, compatible types
44
88. polymorphism
Imperative and Object-Oriented Languages
Type Systems
Ad-hoc polymorphism
overloading
• same method name, independent classes
• same method name, same class, different parameter types
overriding
• same method name, subclass, compatible types
Universal polymorphism
subtype polymorphism
• inheritance, interfaces
parametric polymorphism
44
89. static vs. dynamic dispatch
Imperative and Object-Oriented Languages
Type Systems
Dispatch
• link method call to method
45
90. static vs. dynamic dispatch
Imperative and Object-Oriented Languages
Type Systems
Dispatch
• link method call to method
Static dispatch
• type information at compile-time
45
91. static vs. dynamic dispatch
Imperative and Object-Oriented Languages
Type Systems
Dispatch
• link method call to method
Static dispatch
• type information at compile-time
Dynamic dispatch
• type information at run-time
• single dispatch: one parameter
• multiple dispatch: more parameters
45
92. single dispatch
Imperative and Object-Oriented Languages
Example: Java
public class A {} public class B extends A {} public class C extends B {}
public class D {
public A m(A a) { System.out.println("D.m(A a)"); return a; }
public A m(B b) { System.out.println("D.m(B b)"); return b; }
}
public class E extends D {
public A m(A a) { System.out.println("E.m(A a)"); return a; }
public B m(B b) { System.out.println("E.m(B b)"); return b; }
}
46
A a = new A(); B b = new B(); C c = new C(); D d = new D(); E e = new E();
A ab = b; A ac = c; D de = e;
d. m(a); d. m(b); d. m(ab); d. m(c); d. m(ac);
e. m(a); e. m(b); e. m(ab); e. m(c); e. m(ac);
de.m(a); de.m(b); de.m(ab); de.m(c); de.m(ac);
93. overloading vs. overriding
Imperative and Object-Oriented Languages
Example: Java
public class F {
public A m(B b) { System.out.println("F.m(B b)"); return b; }
}
public class G extends F {
public A m(A a) { System.out.println("G.m(A a)"); return a; }
}
public class H extends G {
public B m(B b) { System.out.println("H.m(B b)"); return b; }
}
47
A a = new A(); B b = new B(); F f = new F(); G g = new G(); H h = new H();
A ab = b;
f.m(b);
g.m(a); g.m(b); g.m(ab);
h.m(a); h.m(b); h.m(ab);
95. copyrights
Imperative and Object-Oriented Languages
Pictures
Slide 1: Popular C++ by Itkovian, some rights reserved
Slide 4: PICOL icons by Melih Bilgil, some rights reserved
Slides 7, 9, 13: Dual Processor Module by roobarb!, some rights reserved
Slides 11, 14: The C Programming Language by Bill Bradford, some rights reserved
Slides 12, 15, 16, 19: Tiger by Bernard Landgraf, some rights reserved
Slide 21: Adam and Eva by Albrecht Dürer, public domain
Slide 22: ABO blood type by InvictaHOG, public domain
Slide 23: Blood Compability and Plasma donation compatibility path by InvictaHOG, public domain
Slide 28: Delice de France by Dominica Williamson, some rights reserved
Slide 46: Nieuwe Kerk by Arne Kuilman, some rights reserved
49