Programming Languages PDF

Document Details

ZippyStar

Uploaded by ZippyStar

Biruni University

Perihan Pehlivanoğlu

Tags

programming languages computer science programming paradigms computer programming

Summary

This document provides an introduction to programming languages, covering different types, levels, and paradigms. It includes examples of various programming languages and concepts like compilation, interpretation.

Full Transcript

Introduction to Computer Engineering 09-PROGRAMMING LANGUAGES Perihan Pehlivanoğlu Dr. Computer Engineering Department 1 Programming Language Programming Language (PL) is a language that can “precisely des...

Introduction to Computer Engineering 09-PROGRAMMING LANGUAGES Perihan Pehlivanoğlu Dr. Computer Engineering Department 1 Programming Language Programming Language (PL) is a language that can “precisely describe” an algorithm to a computer so that it can execute the algorithm: 0-2 3 C++ Programming Language 4 Why C++ 5 From 1966 to 2024 Programming Languages https://www.youtube.com/watch?v=xOW3Cehg_qg 6 7 8 9 Ruby is... A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. 10 Design Considerations There are two extremes in designing a PL: Use human language Use machine code Human languages as programming languages Imprecise Inefficient (for computer as well as human) Easy to use Hard to debug Machine instruction code as programming languages Precise Efficient for computers Verbose to use Hard to debug 0-11 Assembly Language Since machine codes are too hard to remember, each processor manufacture designs an “easy-to remember” names for each op-code Assembly language – a mnemonic system for representing machine instruction codes Mnemonic names for op-codes Names for all registers Identifiers: descriptive names for memory locations, chosen by the programmers Assembly language is referred to as the 2nd generation of programming language 0-12 Assembly Language Characteristics One-to-one correspondence between machine instructions and assembly instructions Programmer must think like the machine Inherently machine-dependent Before execution by a computer, we must translate a machine language program into machine codes by an assembler 0-13 Assembly Language Example Machine language program 156C LD R5, [Price] 166D LD R6, 5056 [ShippingCharge] 306E ADDI R0, R5 R6 C000 ST R0, [TotalCost] HLT; ORG 6Ch Price db 25 ShippingCharge db 5 TotalCost db 00 14 15 Levels of PL 16 Programming Languages 17 Compilation 18 Execution 19 Compilation vs Interpretation 20 21 22 Programming Paradigms (1/2) Imperative (procedural) programming language A program is a sequence of commands Earliest way of programming Functional programming language A program is a description of a data flow (connections of functional units) 23 Programming Paradigms (2/2) Declarative programming language Describes conditions that satisfy the intended solution; the specific steps needed to arrive at that solution are up to an unspecified interpreter Only works for a specific domain of problems (e.g. For knowledge-based inference) Object-oriented programming language A “data-centric” programming language Operations are attached to data A program is composed of a list of objects, each annotated by a list of permissible operations of that object 24 25 Third Generation Languages Uses high-level primitives Machine independent (mostly) Early examples: FORTRAN – for numerical computations COBOL – for financial computations and database systems PYTHON ? JAVA ? C++ ? Each primitive corresponds to a short sequence of machine instruction codes Can be translated into machine codes by a compiler 26 Formal Languages Programming languages are “formal languages” since they are artificial languages defined precisely by grammars Natural (human) languages are not precisely defined by grammars, instead, grammars are created afterwards to “summarize” the language usage Esperanto is an “formal” human language artificially developed in late 1870s. 27 Imperative Programming Language The imperative programming paradigm is the most intuitive and effective way of expressing our commands to computers 28 Example of Data Declaration Variable (data) declarations in C, C++, C#, and Java are as follows: Scalar data declaration: float Length, Width; int Price, Tax, Total; char Symbol; Aggregate data declarationsint scores; //array struct { char Name; int Age; //structure (heterogeneous array) float SkillRating; } Employee; 29 Pseudocode Primitives Assignment name = expression Example RemainingFunds = CheckingBalance + SavingsBalance 5-30 Memory Layout of Aggregate Data 31 Elements of an Imperative PL An imperative programming language provides statements to: Express constants and literals Assign values to variables Control the execution sequence of the program Conditional control Looping control Commenting the program Call procedural units 32 Pseudocode Primitives (continued) Conditional selection if (condition): activity Example if (sales have decreased): lower the price by 5% 5-33 Pseudocode Primitives (continued) Conditional selection if (condition): activity else: activity Example if (year is leap year): daily total = total / 366 else: daily total = total / 365 5-34 Pseudocode Primitives (continued) Repeated execution while (condition): body Example while (tickets remain to be sold): sell a ticket 5-35 Pseudocode Primitives (continued) Indentation shows nested conditions if (not raining): if (temperature == hot): go swimming else: play golf else: watch television 5-36 Procedural Calls (1/2) 37 Procedural Calls (2/2) 38 Parameter Passing Methods There are several ways to pass a parameter from the calling program unit to the called procedure: Call-by-value (passed by value in the textbook) Call-by-reference (passed by reference in the textbook) Call-by-name not mentioned in the textbook, and not popular anymore similar to macro expansion in C/C++, but it’s a real function call 39 Call by Value & Call by Reference 40 Function Calls 41 Definition of Algorithm An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process. 5-42 Algorithm Representation Requires well-defined primitives A collection of primitives constitutes a programming language. 5-43 Next Week Be ready for the quiz. 44 End of Chapter Copyright © 2015 Pearson Education, Inc.

Use Quizgecko on...
Browser
Browser