This document provides an introduction to programming languages. It discusses the different generations of programming languages from machine language to high-level languages like C++ and Java. It also covers the differences between interpreters and compilers and the basic steps involved in implementing a programming language which are scanning, parsing, and code generation.
2. PROGRAMMING LANGUAGE
? First-generation: Machine language
? Second-generation: Assembly
language
? Third-generation: High-level language
? Fourth-generation
? (Fifth-generation)
3. MACHINE LANGUAGE
? A set of primitive instructions built into every
computer
? The instructions are in the form of binary
code
? 1101101010011010
4. ASSEMBLY LANGUAGE
? Low-level programming language to represent machine-
language instructions
? E.g.: ADDF3 R1, R2, R3
? Assembly code need to be converted into machine code by
using an assembler
? Assembly program
? is platform dependent
? Combination of mnemonic and machine instruction
5. HIGH-LEVEL LANGUAGE
? English-like and easy to learn and program.
? E.g.:
? Area = 5 * 5 * 3.1415;
? COBOL, FORTRAN, BASIC, Pascal, Ada, C, Visual Basic, Delphi,
C++, C#, Java
? Source program is compiled into machine code by a
compiler and linked to supporting library code by a linker to
form an executable file.
6. 4GL / 5GL
? 3GL offered greater power to the programmer, while
4GL open up the development environment to a wider
population. (Applications Development Without
Programmers)
? Database query languages: SQL¡
? Data manipulation, analysis, and reporting languages:
MATLAB, SPSS¡
7. CATEGORY (3GL)
? Windows Application
? C, C++, Java, Visual Basic, C#
? Web Application
? Server Side
? PHP, JSP (Java), ASP.NET (Visual Basic, C#), ¡
? Client Side
? JaveScript, VBScript
8. THE BINARY MACHINE
? A modern computer can run programs written in
JavaScript, Pascal, Visual Basic, Visual C++, etc.
? However, computers can only understand one
language: the machine language it is not easy to
use.
? The machine language of a Sun workstation is
different from a PC (or other platform), however,
they can run the same C++ program.
9. TWO TYPES OF TRANSLATORS
(3GL TO 1GL)
? Interpreter:
? translate and run the source code one line at a time. Easy to
write and easy to find the errors in the program, but
running very slow.
? JavaScript, VBScript, PHP, ¡
? Compiler:
? translates the source code once and for all, producing a
complete machine language program. Very fast, but when
the program fails, difficult to show the programmer where
are the errors.
? C, C++, Java, C#, and so on.
10. IMPLEMENT A LANGUAGE
? Generally, the action of any translating program can be divided into
three phases
? Scanning
? Parsing
? Code generation
11. IMPLEMENT A LANGUAGE - SCANNING
? Scanning process: a long string of characters is broken into tokens.
? Example: sum = a + b is broken into 5 tokens sum, =, a, +, b
? A token is the smallest meaningful unit of information.
12. IMPLEMENT A LANGUAGE - PARSING
? Parsing: the string of tokens is transformed into a syntactic structure.
? What happens in a compiler or interpreter is that the list of tokens is
converted to a parse tree in memory via a complicated algorithm.
=
sum +
a b