High-Level Programming Languages

Slides:



Advertisements
Similar presentations
Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
Advertisements

Copyright © 2002 W. A. Tucker1 Chapter 1 Lecture Notes Bill Tucker Austin Community College COSC 1315.
True or false A variable of type char can hold the value 301. ( F )
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Basic Elements of C++ Chapter 2.
Programming Languages
High-Level Programming Languages: C++
CIS Computer Programming Logic
Hello World 2 What does all that mean?.
Programming. What is a Program ? Sets of instructions that get the computer to do something Instructions are translated, eventually, to machine language.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
Chapter 4 Software. Chapter 4: Software Generations of Languages Each computer is wired to perform certain operations in response to an instruction. An.
CPS120: Introduction to Computer Science Variables and Constants.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Conditions - compare the values of variables, constants and literals using one or more relational.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Chapter VII: Arrays.
Variables, Identifiers, Assignments, Input/Output
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 1.2 Introduction to C++ Programming
Chapter 3 Selection Statements
Review 1.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Basics (Variables, Assignments, I/O)
REPETITION CONTROL STRUCTURE
Chapter 1.2 Introduction to C++ Programming
Programming Introduction to C++.
Ch. 7 Programming Languages
Basic Elements of C++.
Revision Lecture
Introduction to C++.
Engineering Innovation Center
Basic Elements of C++ Chapter 2.
Chapter 8: Introduction to High-Level Language Programming
Compiler Construction
Hello World 2 What does all that mean?.
Chapter 10 Programming Fundamentals with JavaScript
Basics (Variables, Assignments, I/O)
CSCE Fall 2013 Prof. Jennifer L. Welch.
Procedural Programming
CSCE 121: Simple Computer Model Spring 2015
Variables, Identifiers, Assignments, Input/Output
Chapter 7 Conditional Statements
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Looping III (do … while statement)
CSCE Fall 2012 Prof. Jennifer L. Welch.
Focus of the Course Object-Oriented Software Development
Programming Introduction to C++.
Fundamental Programming
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

High-Level Programming Languages Chapter 8: High-Level Programming Languages Third-generation languages (e.g., BASIC, FORTRAN, COBOL, C) were developed as a solution to the assembly language problems. Third-generation languages are structured to avoid considering machine operations at all, instead concentrating on relatively straightforward instructions on how the data is being manipulated. Each type of computer that executes programs in a TGL has a special program (called a compiler) that translates the TGL code into the computer’s machine language. Example: int negative (int x) { if (x < 0) return 1; else return 0; } Consequently, a TGL program written on one machine can be run on any other computer, as long as the computer has a compiler for that TGL! Chapter 8 High-Level Programming Languages Page 73

High-Level Programming Languages Compilation Source Program (in TGL) Object Program (in Machine Language) Lexical Analysis Parsing Code Generation Lexical Analysis The compiler takes the TGL program (called the source program) and determines which strings of characters form separate items (e.g., “if (count > 100)” is split into “if”, “(”, “count”, “>”, “100”, and “)”), and all comments and white space (blanks, line feeds, etc.) are deleted. Parsing The compiler then analyzes the grammatical syntax of the program (e.g., “if”, “(”, “count”, “>”, “100”, “)” is determined to make sense, but a syntax error would be noticed in “if”, “count”, “>”, “100”, “)”.) Code Generation Once the program has been satisfactorily parsed, the compiler generates an equivalent program in machine language (called the object program). Chapter 8 High-Level Programming Languages Page 74

High-Level Programming Languages Linking and Loading Since the individual portions of the TGL program are compiled as separate units (e.g., your program, a math library, a graphics library, etc.), the resulting machine code cannot be executed until all of the units are connected together as a single machine language program. Source Program Object Program Load Module Executable Program Compile Link Load Linking A TGL programmer usually relies on pre-compiled libraries of code (math functions, graphics routines, I/O operations, etc.) that are connected to the programmer’s code prior to execution by a linker program. Loading Finally, a special loader program places the resulting machine code in main memory, tying up all loose ends (e.g., setting the instruction addresses for JUMP instructions) so the code is ready for execution. Chapter 8 High-Level Programming Languages Page 75

Standard Source Program Organization Source programs in most third-generation languages generally follow a standard pattern. void main() { const int maxCount = 10; int count; int value; float sum = 0.0; cout << “Input values” << endl; count = 0; while (count < maxCount) cin >> value; sum += value; count++; } cout << “Mean value: ” << sum/count << endl; void main() { const int maxCount = 10; int count; int value; float sum = 0.0; cout << “Input values” << endl; count = 0; while (count < maxCount) cin >> value; sum += value; count++; } cout << “Mean value: ” << sum/count << endl; void main() { const int maxCount = 10; int count; int value; float sum = 0.0; cout << “Input values” << endl; count = 0; while (count < maxCount) cin >> value; sum += value; count++; } cout << “Mean value: ” << sum/count << endl; Declarative Statements Constant and variable values representing terms that will be manipulated as the program is executed. Imperative Statements The procedural specification of the algorithm itself. Chapter 8 High-Level Programming Languages Page 76

High-Level Programming Languages Data Types Data types are used to specify how the bit patterns used to represent data should be interpreted by the program. Scalar: Single-valued data types (e.g., integer, floating-point, character, boolean) int count; float price; bool flag; Structured: Multiple-valued data types Built-In: Arrays, character strings float CaffeineOuncesPerDay[7]; char chosenCola[] = “Pepsi”; User-Defined: Specially constructed struct Student { char name[30]; int examScore[5]; int quizScore[25]; int paperScore[2]; char letterGrade; }; Student FALL111[25]; Chapter 8 High-Level Programming Languages Page 77

High-Level Programming Languages Imperative Statements - Part One Assignment & I/O Assignment statements are used to assign a value to a variable. x = 127; c count E m x 186000 78 3309875 5 290 c count E m x 186000 78 3309875 5 127 c count E m x 186000 79 930000 5 127 c count E m x 186000 79 3309875 5 127 c count E m x 186000 79 930000 5 127 count = count + 1; E = m * c * c; Input/output statements are used to retrieve external values (input) and to file away or print information (output). Enter user’s name: MOE cout << “Enter user’s name: ”; cin >> username; dataFile >> nextDataValue; if (nextDataValue > 0) positiveFile << nextDataValue; dataFile positiveFile 25 63 17 48 50 77 13 91 23 89 34 56 25 63 17 48 50 77 13 91 23 89 34 56 25 nextDataValue 25 nextDataValue 94 nextDataValue 25 Chapter 8 High-Level Programming Languages Page 78

High-Level Programming Languages Imperative Statements - Part Two Control Statements Conditional statements are used to enable alternative steps based on a condition. if (total == 0) cout << “Possible Drop”; else cout << “Total: ” << total; switch (AreaCode) { case 701: cout << “ND”; break; case 218: case 507: case 612: cout << “MN”; break; } Iterative statements are used to loop through a sequence of instructions. while (flag == false) { cin >> newValue; if (newValue > 0) flag = true; } total = 0; for (i = 0; i <= 24; i++) { quizFile >> score[i]; total += score[i]; } Chapter 8 High-Level Programming Languages Page 79

High-Level Programming Languages Imperative Statements - Part Three Procedures & Functions Procedures and functions are used to conveniently write programs in a modular fashion. typedef int intList[100]; void getList(intList list) { int count; for (count = 0; count < 100; count++) cin >> list[count]; } int maximum(intList list) int maxSoFar; maxSoFar = list[0]; for (count = 1; count < 100; count++) if (list[count] > maxSoFar) maxSoFar = list[count]; return maxSoFar; void main() { intList IQlist; intList SATlist; int maxIQ; int bestSAT; getList(IQlist); maxIQ = maximum(IQlist); getList(SATlist); bestSAT = maximum(SATlist); cout << “The highest IQ is ” << maxIQ << “ and the ” << “best SAT score is ” << bestSAT; } Chapter 8 High-Level Programming Languages Page 80

Example: What Does This Program Do? typedef int intList[4]; void getList(intList list) { int count; for (count = 0; count < 4; count++) cin >> list[count]; } int drew(intList list, int item) int bestSoFar, bestIndex, index; bestIndex = -1; bestSoFar = 0; for (index = 0; index < 4; index++) if ((list[index] > bestSoFar) && (list[index] <= item)) bestIndex = index; bestSoFar = list[index]; return bestIndex; void main() { intList estimate; int bestGuesser; int price; cin >> price; getList(estimate); bestGuesser = drew(estimate, price); if (bestGuesser == -1) cout << “NO WINNER”; else cout << bestGuesser << “ WINS! ”; if (estimate[bestGuesser] == price) cout << “WITH A BONUS!!!”; } What would be the output of this program for the following input file? 600 400 675 525 450 Chapter 8 High-Level Programming Languages Page 81

High-Level Programming Languages Object-Oriented Programming Early third-generation programming languages used a “procedure-oriented” approach, in which the way something was done was the center of attention for the programmer. More recently, with the advent of graphical user interfaces and massive databases, the focus has shifted to an “object-oriented” approach, emphasizing what is being manipulated instead of how. Chapter 8 High-Level Programming Languages Page 82

High-Level Programming Languages The Three Principles of OOP “Hide” information from objects that don’t need it. Is the search being performed sequential or binary? Is the data in an array or separate variables? Is the input coming from the user or from a file? The code will be more robust if it’s not unnecessarily dependent on information that it can perform without! Encapsulation Don’t “reinvent the wheel” when creating new data types. A GUI Window is rectangular with a title bar. A Document Window also has a menu bar, and max & min buttons. Why not let the Document Window “inherit” as much behavior as possible from the GUI Window (e.g., how to draw it, how to place text in its title bar)? Inheritance Some objects are “similar”, without being the same. A Triangle object needs its own method for “Drawing”. A Circle object needs its own method for “Drawing”. With polymorphism, you can write code to invoke “Drawing” without having to spell out what type of “Drawing” is intended. Polymorphism Chapter 8 High-Level Programming Languages Page 83