Principles of Programming Languages
Principles of Programming Languages
Introduction
Outline
An introductory tour
Kinds of languages
Objectives
Compiler and Interpreter
Language Tour
dosseg
.model small
.stack 100h
.data
hello_message db 'Hello, World!',0dh,0ah,'$'
.code
main proc
mov ax,@data
mov ds,ax
mov ah,9
mov dx,offset hello_message
int 21h
mov ax,4C00h
int 21h
main endp
end main
C
#include <stdio.h>
main()
{
for(;;)
{
printf ("Hello World!\n");
}
}
C++
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
}
C#
class HelloWorld
{
static void Main () {
System.Console.Write("Hello World!");
}
}
HTML
<HTML>
<HEAD>
<TITLE>Hello, World Page!</TITLE>
</HEAD>
<BODY>
Hello, World!
</BODY>
</HTML>
Java
class HelloWorld {
public static void main (String args[]) {
for (;;) {
System.out.print("Hello World ");
}
}
}
Javascript
<TITLE>
Hello World in JavaScript
</TITLE>
<SCRIPT>
document.write ("Hello, world!")
</SCRIPT>
LATEX
\documentclass{article}
\begin{document}
\begin{center}
\Huge{HELLO WORLD}
\end{center}
\end{document}
Lisp
(DEFUN HELLO-WORLD ()
(PRINT (LIST 'HELLO 'WORLD)))
(while t
(message "Hello World")
(message "") ; force emacs to update the display
)
Prolog
hello :-
printstring("HELLO WORLD!!!!").
printstring([]).
printstring([H|T]) :- put(H), printstring(T).
Smalltalk
Transcript show: 'Hello World„.
Visual Basic
Private Sub FOrm_Load()
Static I
I=1
for I = 1 to 10
msgbox "Hello World"
Next I
end sub
Visual C++
/////////////////////////////////////////////////////////////////////////////
// CHelloDlg dialog
Memory
CPU
0101001001101011
1101111001001001
0001101010101010
I/O
Machine Language
Instruction:
10110011010010010011010110110
001
Assembly Language
A := B + C
if A = 0 then body
Natural
Language High-Level
Low-
Level
Machine
Language
Language Classification
• Imperative
von Neumann Fortran, Pascal, Basic, C
object-oriented Smalltalk, Eiffel, C++, Java
• Declarative
functional Lisp, ML, Haskell
dataflow Id, Val
logic Prolog, VisiCalc
Von Neumann Languages
• Imperative statements
• Message passing among objects
Prolog, VisiCalc
Objectives
• Programming environment
• Portability of programs
• Cost of use
program execution
program translation
program creation, testing, use
program maintenance
Compilation and Interpretation
Source
program Interpreter Output
Input
Compilation and Interpretation
www.google.com
www.wikipedia.com