Introduction to Programming Languages PDF

Summary

This document provides an introduction to the history and milestones of programming languages. It covers the development of various languages, starting from Machine Language and Plankalkül, and describes their purposes, key features, and applications. The document also discusses concepts such as syntax and semantics.

Full Transcript

IT2409 Introduction to Programming Languages Milestones in Programming Languages A programming language is a formal notation system or instructions for writing computer programs and other software applications. Here are the milestones in Programming Languages throughout hist...

IT2409 Introduction to Programming Languages Milestones in Programming Languages A programming language is a formal notation system or instructions for writing computer programs and other software applications. Here are the milestones in Programming Languages throughout history. Year Programming Language Description Ada Lovelace invented the first machine algorithm. She made the leap that numbers could represent other things, leading to the idea 1843 Machine Language of programming languages. Her work was the first step in designing a language capable of giving computer instructions. Konrad Zuse, a German scientist, developed a language for expressing computations for the Z4, a computer from electromechanical relays. Plankalkül means program calculus. 1940s Plankalkül It was the first high-level computer programming language ever developed. This language included mathematical expressions, showing the current relationships between program variables and the ability to store codes that enabled engineers to carry out routine, repetitive tasks more efficiently and quickly. Kathleen Booth wrote the first assembly language, a low-level Assembly Language programming language developed to simplify machine code for 1949 writing instructions for processors. Implemented by William Schmitt to improve the operations of the Shortcode BINAC and UNIVAC computers. Alick Glennie coined “Autocode” to refer to a set of programming languages. It was developed for the Mark 1 computer at the University of Manchester. 1952 Autocode It was considered the first compiled programming language that could be translated into machine code using a special application known as the compiler. Formula Translation was created by John Backus to shorten the process of programming and make computer programming more 1957 Fortran accessible. It is still used today in supercomputers and scientific and mathematical computations. Algorithmic Language was created by American and European ALGOL computer scientists. It became the point of origin for other programming languages, including Pascal, Java, C, and C++. 1958 John McCarthy created the List Processor (LISP) for his artificial intelligence (AI) applications. It is one of the oldest computer LISP programming languages still used today by AI companies like Boeing and Genworks. Stands for Common Business Oriented Language. It was developed and designed by Dr. Grace Murray Hopper for business computer 1959 COBOL programs in industries. It was estimated to be in use by over 100 million people and is still widely used in today’s banking systems. 01 Handout 1 *Property of STI Page 1 of 7 IT2409 Created as a computer programming language for beginners by Dartmouth College students. BASIC stands for Beginner's All- 1964 BASIC Purpose Symbolic Instruction Code. Bill Gates and Paul Allen furthered its development, and it became Microsoft’s first commercially successful product. Developed by Niklaus Wirth, it was named after the famed mathematician Blaise Pascal. Apple was one of the leading 1970 Pascal companies to endorse this due to its streamlined and straightforward process. Dennis Ritchie developed the C language at the Bell Telephone Laboratories. It was named as such as it descended from the B C language. It is recommended for creating embedded system drivers and applications. Programming languages like C#, Java, JavaScript, 1972 Perl, PHP, and Python are all derived from C. Structured Query Language was developed by Raymond Boyce and SQL Donald Chamberlain. It was first called SEQUEL and was used for modifying, viewing, and altering information in databases. Bjarne Stroustrup, a C programmer, modified the programming C++ language and released it as C++. The changes include new features such as templates, classes, and virtual functions. 1983 Brad Cox and Tom Love created Objective-C, which is the primary Objective-C programming language used to create applications for Apple’s iOS, macOS, and iPad operating systems. Guido Van Rossum founded this as a support language for software Python developers, build control and management, testing, and many other ways. It is a general-purpose, high-level language. 1991 Created by Microsoft. It allows users to drag and drop sections of Visual Basic (VB) code simultaneously. Users can choose from various options in the drop-down menus and change different codes. Created by James Gosling for a software project for interactive TV. It is considered one of the world’s most famous and popular Java programming languages for coding web applications. It is a multi- platform, object-oriented, and network-centric language that can be used as a platform. Created by Brendan Eich and is primarily used as a scripting 1995 JavaScript language in websites. It is also used for web development, PDF documents, and desktop widgets. Rasmus Lerdorf developed PHP (previously known as Personal Home Page, now known as Hypertext Preprocessor) to build and PHP maintain web pages and server-side development. Facebook, Wikipedia, and WordPress use PHP. Table 1. Programming language milestones. 01 Handout 1 *Property of STI Page 2 of 7 IT2409 Programming Domains and Environments Programming Domains As great diversity in computer use develops through time, there have been different goals for developed programming languages. The following elaborates on the most common areas of computer applications and their associated languages. Domain Application Language Used The first digital computers from the late As efficiency is a concern in this 1940s to early 1950s were invented and domain, Fortran was the first used for this domain. language used. Scientific At the time, simple data structures such as Applications arrays and matrices and control structures such as counting loops and selection were used, but this required several floating- point arithmetic computations. Computer use in this domain began in the The first successful high-level Business 1950s when special computers were language for this domain was COBOL, Applications developed along with special languages. the initial version from 1960. AI is characterized by the use of symbolic As this requires flexibility, LISP was rather than numeric computations. In the first widely used programming symbolic computation, symbols consisting language for this domain before Aritificial of names rather than numbers are 1990. Intelligence (AI) manipulated and are more conveniently More recently, Python has been used done with linked lists of data rather than in AI applications. arrays. The WWW (World Wide Web) is supported Embedding programming code can by a collection of languages, ranging from be in the form of a scripting language HTML (not a programming language) to such as JavaScript or PHP. Java (general-purpose programming language). Web Software The need for dynamic Web content demands some computation capability, which can be provided by embedding programming code in an HTML document. Table 2. Programming domains. 01 Handout 1 *Property of STI Page 3 of 7 IT2409 Programming Environments It is the collection of tools in software development. It may consist of only a file system, a text editor, a linker, and a compiler, or sometimes, it may include a large collection of integrated tools wherein each is accessed through a uniform user interface. Microsoft Visual Studio Code It is a redefined and optimized code editor for building and debugging modern web and cloud applications. It is a lightweight yet powerful source code editor that runs on a desktop and is available for Windows, macOS, and Linux. It has built-in support for JavaScript, TypeScript, and Node.js and has a rich ecosystem of extensions for other languages and runtimes such as Java, Python, C++, C#, PHP, and.NET). NetBeans It is a free, open-source, integrated development environment (IDE) that allows the development of desktop, mobile, and web applications. It provides comprehensive support for JDK 7 technologies and the most recent Java enhancements. It also supports JavaScript, Ruby, and PHP. NetBeans and Visual Studio are more development environments as they are also frameworks. This means that they provide common parts of the code of the application. Arduino IDE It contains a text editor for coding, a message area, a text console, a toolbar for various functions, and a series of menus. It connects to the Arduino board to upload programs and communicate with them. Blockly It is a visual programming editor that uses drag-and-drop blocks for coding. It is made by Google and is currently empowering the most popular coding education programs worldwide. The user defines the block connections and input fields for Blockly to handle the complicated rendering, dragging, and connection of them. Programming Language Evaluation Criteria Evaluation criteria help analyze the impact of programming languages on the software development process, including maintenance. Figure 1. Language evaluation criteria and the characteristics that affect them. Retrieved from Sebesta, R. (2019). Concepts of programming languages. Pearson. 01 Handout 1 *Property of STI Page 4 of 7 IT2409 Readability An important criterion for assessing a programming language is the ease with which programs can be read and understood. In the 1970s, the software life-cycle concept was developed to relegate coding to a much smaller role and consider maintenance as a major part of the cycle in terms of cost. As ease of maintenance is determined in large part by the readability of programs, readability became a major measure of the quality of programs and programming languages. Readability must be considered in the context of the problem domain such that if a program that describes a computation is written in a language not designed for such use, the program may be unnatural and convoluted, making it difficult to read. The following describes the characteristics that contribute to the readability of a programming language: Simplicity: The overall simplicity of a programming language strongly impacts its readability. For example, a larger number of basic constructs in a language is more difficult to learn than one with a smaller number. The following can be considered problems in readability. o Feature Multiplicity – a scenario of more than one (1) way to accomplish a particular operation. o Operator Overloading – a scenario wherein a single operator symbol has more than one (1) meaning. It can result in reduced readability if users create their overloading and do not do it sensibly. o Oversimplicity – a scenario wherein the language is too simple to the point of lacking more complex statements and less obvious program structure. Orthogonality is the ability to change one thing without unseen effects on other things in the program. It is about the independence of components in a larger system. It deals with how a relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structure of the language. A lack of orthogonality leads to exceptions to the rules of the language. For instance, a programming language that supports pointers. It should be able to define a pointer to point to any specific type in the language. If not, many potentially useful user-defined data structures cannot be defined. The more orthogonal the design of a language, the fewer exceptions the language rules require. This results in a higher degree of regularity in the design, making it easier to learn, read, and understand. Data Types: The presence of adequate facilities for defining data types and data structure offers a significant aid to readability. For instance, it might not be easily understood if a numeric type is used for an indicator flag, such as in C language, because there is no Boolean type in the language. Syntax Design: The syntax or form of the elements has an impact on the readability of programs. The following exemplifies syntactic design choices that affect readability. o Special Words: Some programming languages have used matching pairs of special words or symbols to form groups. These languages have diminished readability as statement groups are always terminated in the same way, making it difficult to determine which group is being ended when an end or a right brace appears ( } ). 01 Handout 1 *Property of STI Page 5 of 7 IT2409 o Form and Meaning: Designing statements to make their appearance partially specify their purpose, which helps readability. Semantics, or meaning, must follow directly from syntax or form. For example, in C, the meaning of the keyword static depends on the context of its appearance. If used to define a variable inside a function, it means the variable is created at a compile time. If used outside of all functions, it means the variable is visible only in the file wherein its definition appears. Writability It is the measure of how easily a language can be used to create programs for a chosen problem domain. It is unfair to compare the writability of different languages of a particular application when one is designed for that application and one that was not. For instance, Visual Basic (VB) and C are different when creating a program with a GUI, for which VB is only ideal. While for writing systems programs like an operating system, C is ideal. The following describes the characteristics that contribute to the writability of a programming language: Simplicity and Orthogonality: A large number of different constructs in a language might confuse some programmers as they might not be familiar with them. This leads to the misuse and disuse of some features. Too much orthogonality can affect the writability of a programming language, as errors can go undetected when any combination of primitive is legal. This can lead to code absurdities that cannot be discovered by the compiler. Expressivity in a language refers to various characteristics. It means that there are more effective operators that allow a computation to be accomplished with a very small program. For instance, in C language, the notation count++ is more convenient and shorter than count = count + 1. Reliability It is met if a program performs to its specifications under all conditions. The following describes various language functions that affect the reliability of programs in a given language: Type Checking tests for the type of errors in a program, either by the compiler or during program execution. As runtime type checking is expensive, compile-time type checking is more desirable. The earlier the errors are detected, the less expensive it is to make the required repairs. Exception Handling is the ability of the program to intercept runtime errors and other unusual conditions detectable by the program, take corrective measures, and then continue. Aliasing happens when there are two (2) or more distinct names in a program that can be used to access the same memory cell. It is considered and accepted as a dangerous feature in a programming language. Readability and Writability: A language that does not support natural ways to express the required algorithms in a program will use unnatural approaches that are likely to be incorrect for all possible situations. A program is more likely to be correct if it is easier to write. Additionally, a program that is difficult to read can also be difficult to write and modify. 01 Handout 1 *Property of STI Page 6 of 7 IT2409 References: Sebesta, R. (2019). Concepts of programming languages. 12th edition. Pearson. Heirso, S. (2022). Coding from 1849 to 2022: A guide to the timeline of programming languages. [Web Article]. Retrieved on November 15, 2024, from https://www.computer.org/publications/tech-news/insider-membership- news/timeline-of-programming-languages 01 Handout 1 *Property of STI Page 7 of 7 IT2409 Syntax and Semantics Studying programming languages can be divided into examinations of syntax and semantics. These two (2) make up a language along with the alphabet (set of symbols used to build words of a certain language) and lexis (or a dictionary, a set of words the language offers its users). A language, natural (English) or artificial (Python), is a set of strings of characters from the alphabet. Syntax In natural language, such as English, syntax is the set of rules that determines if a certain string of words forms a valid sentence. In programming language, syntax is the form of its expressions, statements, and program units. It defines the meaning of the various combinations of symbols used in programming and describes which strings of characters comprise a valid program. It is important to note that every programming language uses different word sets in different orders, meaning they have their syntax. This is why programmers must carefully and strictly adhere to their programming language’s syntax, as any deviation could lead to syntax errors, resulting in the computer being unable to run the source code. A source code is a program written in a high-level programming language, while the source file is the file containing the source code. Components of Syntax There are several key components to understanding syntax in programming languages: Keywords – reserved words that have a special meaning in the language. They form the basic building blocks for writing programs. Examples include if, else, for, and while. Operators – symbols that perform operations on variables and values. Examples include arithmetic operators like + and -and logical operators like && and ||. Punctuation includes symbols such as commas, semicolons, and braces that help structure the program. They indicate the end of statements or encapsulate blocks of code. Identifiers are names that identify user-defined items such as variables, functions, and arrays. BNF (Backus-Naur Form) It is a natural notation for describing syntax. Though not immediately accepted, it became the most popular method of concisely describing programming language syntax. It is also considered a metalanguage for programming language. A metalanguage is a language or set of terms used to describe another language. Computer scientists use BNF to describe the syntax of a programming language as it allows them to write a detailed description of a language’s grammar. BNF notation consists of three (3) core pieces: Component Description Examples Terminals Strings that must exactly match specific items in the input "def", "return", ":" Nonterminals Symbols that will be replaced by a concrete value. , Rules Conventions of terminals and nonterminals that defined ::= "a" how the elements relate 02 Handout 1 *Property of STI Page 1 of 5 IT2409 BNF rules can be created by combining terminals and nonterminals. BNF rules, also called production rules, are the core components of BNF grammar (a set of BNF rules). A set of BNF rules can be set to specify the grammar of a language. For example, the Python syntax has a grammar defined as a set of BNF rules used to validate the syntax of any piece of Python code. If the code fails to fulfill these rules, a SyntaxError appears. A variety of symbols with specific meanings can be used in building BNF rules, such as the following symbols: Symbol Meaning "" Encloses a terminal symbol Indicates a nonterminal symbol () Indicates a group of valid options + Specifies one or more of the previous element * Specifies zero or more of the previous element ? Specifies zero or one occurrence of the previous element | Indicates that one of the options can be selected [x-z] Indicates letter or digital intervals An example of a general BNF rule is: ::= expression Parts Description a nonterminal variable, often enclosed in angle brackets (). :: = indicates that the nonterminal on the left will be replaced with the expression on the right. expression consists of a series of terminals, nonterminals, and other symbols that define a specific piece of grammar. Knowing how to write BNF rules and which symbols to use will allow the creation of unique rules. Here is an example of a BNF rule: Grammar for a Full Name Assume that a BNF rule needs to be defined for how users should input a person’s full name (first, middle, and family name), whitespace between each component, and the middle name treated as optional. This rule can be defined as: ::= "" ( "")? The left-hand part of this BNF rule is a nonterminal variable that identifies the person’s full name. The ::= indicates that will be replaced with the right-hand part of the rule. The right-hand part of the rule has various components. Firstly, the first name is defined as the nonterminal. Then, a space that separates the first name from the next component. A terminal, which consists of a space character between quotes, is used to define this space. After the nonterminal, a middle name can be accepted, then another space is used. These two elements are enclosed in parentheses to group them. Then, and the " " terminal is created. Both are optional, so a question mark (?) is used after to indicate that condition. Finally, the family name. Another nonterminal, , is used to define this component. A BNF rule is built, but a working grammar still needs to be created. This is only a root rule. 02 Handout 1 *Property of STI Page 2 of 5 IT2409 The rules for , , and must be defined to complete the grammar. The following requirements must be met to do this: - Only letters must be accepted by each component - A capital letter will start each component and continue with lowercase letters With this, it can be defined as: ::= "" ( "")? ::= [A-Z] ::= [a-z] The first added rule accepts all the ASCII letters from uppercase A to Z, while the second rule accepts all the lowercase. This indicates that accents or other non-ASCII letters will not be supported. To complete the rest of the rules, the rule can be added. ::= "" ( "")? ::= [A-Z] ::= [a-z] ::= * Starting with the nonterminal expresses that the first letter must be uppercase, continued with the nonterminal followed by an asterisk (*). The asterisk indicates that the first name will accept zero or more lowercase letters after the initial uppercase letter. The same rule can be applied to the and rules. For Python, it uses a custom variation of the BNF notation to define its grammar. Symbol Meaning name Holds the name of a rule or nonterminal ::= Means expand into | Separates alternatives * Accepts zero or more repetitions of the preceding item + Accepts one or more repetitions of the preceding item [] Accepts zero or one occurrence, which means that the enclosed item is optional () Groups options "" Defines literal strings space Only meaningful to separate tokens Unlike regular BNF rules, Python does not use angle brackets () to enclose nonterminal symbols. It only uses the nonterminal name or identifier, making the rules cleaner and more readable. Additionally, square brackets ([]) are used differently in Python. In regular BNF, it is used to enclose sets of characters like [a-z], but in Python, the brackets mean that the enclosed element is optional. "a"…"z" is used instead to define something like [a-z] in Python. 02 Handout 1 *Property of STI Page 3 of 5 IT2409 For example, the return statement: return_stmt ::= "return" [expression_list] This BNF grammar contains the rule’s name, return_stmt, ::=, and a terminal symbol consisting of the word return. The second component is an optional list of expressions, expression_list, enclosed in square brackets, signifying optionality in Python’s BNF notation. Syntax Tree Also called Abstract Syntax Tree (AST), it is a tree representation of the syntactic structure of the source code. Each node in the tree denotes a construct occurring in the source code. The compiler uses the syntax tree to understand the hierarchical structure of the source code, which is crucial for code analysis and optimization. Understanding syntax helps ensure that code is written in a manner that the compiler or interpreter can effectively translate into machine code. For instance, knowing the most efficient way to implement loops or recursive functions in a given language involves a deep understanding of that language's syntax. Semantics Semantics is the meaning of those expressions, statements, and program units that syntax forms. While syntax refers to the set of rules that define the structure of a programming language, semantics is concerned with the meaning behind that structure. Static and Dynamic Semantics Semantics in programming languages can be broadly divided into two categories: static semantics and dynamic semantics. Static semantics involves rules checked simultaneously, such as type checking and scope resolution. These rules ensure that certain errors are caught before the program runs, enhancing reliability and robustness. For instance, if a variable is used without being declared, a statically typed language will flag an error before execution. Dynamic semantics refers to the behavior of a program when it is run. It includes the execution of expressions, control structures like loops and conditionals, and manipulating data through functions and procedures. Dynamic semantics defines how the state of a program changes as it executes, which is critical for understanding and predicting program behavior. Formal Semantics Formal methods are often employed to define a programming language's semantics. These include: Operational Semantics – describes the behavior of a program in terms of abstract machine execution steps. For instance, it outlines how each expression or statement is evaluated step-by- step, making it ideal for simulating program execution. Denotational Semantics – maps syntactic constructs to mathematical objects, offering an abstract, mathematical description of their meaning. This approach helps in reasoning about program correctness and equivalence. For example, a function in programming might be represented as a mathematical mapping between input and output values. 02 Handout 1 *Property of STI Page 4 of 5 IT2409 Axiomatic Semantics – uses logical assertions, such as preconditions and postconditions, to specify and prove properties about a program. It is especially useful in verifying the correctness of algorithms. Each of these methods offers a different perspective on how to interpret the meaning of a program, allowing for a deeper understanding of programming language behavior. Semantics plays a crucial role in writing efficient code. By understanding the underlying logic and execution flow of a program, programmers can eliminate unnecessary computations, streamline operations, and ensure that the code adheres to the intended functionality. For example, understanding the semantic implications of a function call in a language that supports lazy evaluation allows developers to defer computations until necessary, thereby saving resources. References: Sebesta, R. (2019). Concepts of programming languages. Pearson.s Ramos, L. (2024). BNF notation: Dive deeper into Python’s grammar. [Web Article]. Retrieved on January 8, 2025, from https://realpython.com/python-bnf-notation/ 02 Handout 1 *Property of STI Page 5 of 5

Use Quizgecko on...
Browser
Browser