Download Programming Languages

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Comment (computer programming) wikipedia , lookup

Program optimization wikipedia , lookup

Logic programming wikipedia , lookup

Stream processing wikipedia , lookup

Library (computing) wikipedia , lookup

One-pass compiler wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Abstraction (computer science) wikipedia , lookup

Functional programming wikipedia , lookup

Control flow wikipedia , lookup

Compiler wikipedia , lookup

Programming language wikipedia , lookup

Parsing wikipedia , lookup

Assembly language wikipedia , lookup

Go (programming language) wikipedia , lookup

Reactive programming wikipedia , lookup

History of compiler construction wikipedia , lookup

Cross compiler wikipedia , lookup

Object-oriented programming wikipedia , lookup

Interpreter (computing) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Structured programming wikipedia , lookup

Transcript
Chapter 17
Programming Tools
The Architecture of Computer Hardware
and Systems Software:
An Information Technology Approach
3rd Edition, Irv Englander
John Wiley and Sons 2003
Programming Tools Overview
 Editors
 Assemblers
 Debuggers




Compilers
Linkers
Loaders
Interpreters
Integrated Development Environments (IDEs)
combine several of the above programming tools
Chapter 17 Programming Tools
17-2
The Program Translation Process
 Terms,
terms, and
more terms!
Source
Translator
Object
Linker
Loader
Executable
Chapter 17 Programming Tools
17-3
Visual Basic IDE
Chapter 17 Programming Tools
17-4
Program Text Editors
 Word processors format the appearance of the text
 Text editors
 Format the spacing between words for legibility
 Ideal for structured languages
 Text is the same font size
 Examples
 DOS – Edit
 Windows – Notepad, Wordpad
 Unix / Linux – ed, vi, emacs
 IDEs
 MS Visual C++, Symantec Visual Cafe
Chapter 17 Programming Tools
17-5
Programming Language
Categories
 Machine Language
 Binary coded instructions
 Assembly Language
 Symbolic coded instructions
 Procedural Languages
 procedural statements or arithmetic notation
 Four-generation Languages
 Natural language and nonprocedural statements
 Object-oriented Languages
 Combination of objects and procedures
Chapter 17 Programming Tools
17-6
Assembly Language
 When to use




When speed or size of program is critical
Hybrid approach
Hardware Drivers
Can use specialized instructions
 Disadvantages
 Inherently machine specific
 Architectures may become obsolete
 Lack of programming structure
Chapter 17 Programming Tools
17-7
Assemblers
 Binary code = machine code
 Hex code
 Assembly Language






Mnemonic names  op codes
Labels  memory addresses
Comments
Symbol table
Operations table
Memory Relocation
 Cross Assembler
Chapter 17 Programming Tools
17-8
What Does This Program Do?
00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
IN
STO 99
IN
STO 98
IN
STO 97
SUB 98
BRP 10
LDA 98
BR 11
LDA 97
STO 96
SUB 99
BRP 16
LDA 96
BR 17
LDA 96
OUT
COB
901
399
901
398
901
397
298
811
598
611
597
396
299
816
599
617
596
902
000
Chapter 17 Programming Tools
;input three numbers and save
;subtract number in 98 from that in 97
;number in 97 larger
;number in 98 larger, restore 98
;restore 97
;store larger of (97, 98) in 96
;subtract number in 99 from larger
;number in 96 larger
;number in 99 larger, restore 99
;restore 96
17-9
LMC Program in Java
 Use instructions in a more understandable
language
static int max (int x[])
{
for (i=1; i<=3; i++)
x[i] = input.getint();
max_int = x[1];
for (i=2; i<=3; i++)
if (x[I] > max_int)
max_int = x[I];
System.output.println(max_int);
}
Chapter 17 Programming Tools
17-10
Procedural Languages
 COBOL
 Wordy but easier to maintain
 FORTRAN
 Scientists and engineers
 BASIC
 Pascal
 Highly structured teaching language
 C
 high-level commands and low-level access to
hardware
Chapter 17 Programming Tools
17-11
Object-Oriented Languages
 SmallTalk
 C++
 Java
 Based on C++
 Platform independent
Chapter 17 Programming Tools
17-12
Compilers
 Translates high-level language into lowlevel instructions
 High-level language: Source code
 Machine-level: Object code
 Changes, including bug fixes, require
recompiling
Chapter 17 Programming Tools
17-13
Language Components
 Lexicon
 All legal words in the language
 Meaning and type
 Syntax
 grammar rules
 Semantics
 meaning of command
Chapter 17 Programming Tools
17-14
Computer Language Descriptions
 Narrative
 Syntax (Railroad) Diagrams
 BNF
 Backus-Naur Form
 Context-Free Grammar
Chapter 17 Programming Tools
17-15
Railroad Diagram Examples
Chapter 17 Programming Tools
17-16
Typical BNF Rules for Java
Chapter 17 Programming Tools
17-17
Parsed English Sentence
Chapter 17 Programming Tools
17-18
The Compilation Process
Checks for
errors
Updates
internal
tables
Generates CPU
instructions or
library calls
Chapter 17 Programming Tools
17-19
Process of Parsing
 Lexical analysis
 Also known as scanning
 Divides the string of input characters into
single elements, tokens, based on strict
computer punctuation
 Syntactic analysis
 Checks for errors in grammar rules
 Semantic parsing
 Determines the meaning of the string
Chapter 17 Programming Tools
17-20
Source Code Instructions
 Data declarations:
 Data type such as floating point, integer
 Data operations
 Instructions that update or compute data value
(lots of moving around!)
 Control Structures
 Branches, Goto (yetch!), If-then-else, loops such
as While-do and Repeat-until
 Function, procedure, or subroutine calls
 Receives control via a call instruction, receives
and possibly modifies parameters, and returns
control to the instruction after the call
Chapter 17 Programming Tools
17-21
Recursive Descent Parsing
Chapter 17 Programming Tools
17-22
Optimization
 Compiler analyzes code in order to
 Reduce amount of code
 Eliminate repeated operations
 Reorganize parts of of the program to execute
faster and more efficiently
 Use computer resources more effectively
 Example
 Move a calculation repeated within the body of a
loop that does not use any value modified by the
loop
 Different compilers can produce different
results!
Chapter 17 Programming Tools
17-23
Linking
Object file
Object
file or object
module
Linker
Executable
file
C library
Chapter 17 Programming Tools
17-24
Linkers
 Searches program libraries to find library
routines used by the program
 Library: collection of pre-written functions and
subroutines made available to perform commonly
required activities
 Determines the memory locations that code
from each module will occupy and relocates
instructions by adjusting absolute references
 Resolves references among files
Chapter 17 Programming Tools
17-25
Why Link?
 Construct single executable program from
multiple object code files compiled at different
times
 Program can be subdivided into components
and parceled out to different developers
 Example
 Main program and multiple subroutines written
and compiled by different programmers at different
times
Chapter 17 Programming Tools
17-26
Loader
 Loads binary files that have been linked
into main memory
 Program is ready for execution
Chapter 17 Programming Tools
17-27
Interpreters
 Translates source code instructions into
machine language and executes it one
statement at a time
 Disadvantages
 Longer to execute, particularly bad for loops
 Uses more memory
 Advantage
 Faster testing and code modification
 Examples of interpreted languages
 Java, BASIC, LISP
Chapter 17 Programming Tools
17-28
Interpreter vs. Compiler
Resources during execution
Interpreter
Compiler
Interpreter/compiler
Yes
No
Source code
Partial
No
Executable code
Yes
Yes
Translation operations
Yes
No
Library linking
Yes
No
Application program
Yes
Yes
Contents in memory
CPU cycles
Chapter 17 Programming Tools
17-29
Debuggers




Assembly language debuggers
Source code debuggers
Step through programs
Check variable values
Chapter 17 Programming Tools
17-30