4G LANGUAGE : An Introduction… Dr. Mohammad Iqbal Source : www.wittyengineers.com Programming Language • A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer. • Programming languages can be used to create programs that specify the behavior of a machine,to express algorithms. • Many programming languages have their syntax and semantics. Generations of Programming Language • 1st Generation: (1950-60) machine language. • 2nd Generation: (1961-75) assembly language. • 3rd Generation: (1976-92) high-level programming languages, such as C, C++, and Java. • 4th Generation: (1993-2005) typical high-level programming languages closer to human languages. • 5th Generation: (2005-..) used for artificial intelligence and neural networks. First-generation programming language • A first-generation programming language is a machine-level programming language. • No translator was used to compile or assemble the firstgeneration language. • The main benefit of first-generation programming language is that the code a user writes can run very fast and efficiently. • It is a lot more difficult to learn than higher generational programming languages, and it is far more difficult to edit if errors occur. • Machine language is an example of 1st G Language. • Sometimes referred to as machine code or object code. • It is a collection of binary digits or bits that the computer reads and interprets. Second-generation programming language • Second-generation programming language is a generational way to categorize assembly languages. • Second-generation programming languages have the following properties: • The code can be read and written by a programmer. To run on a computer it must be converted into a machine readable form, a process called assembly. • The language is specific to a particular processor family and environment. Assembly language • It is an example of 2nd G Language. • Assembly languages are a family of low-level languages for programming computers. • It implements a symbolic representation of the numeric machine codes. • Other constants needed to program a particular CPU architecture. Assembly language Assembler • Assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities. • Assemblers are generally simpler to write than compilers for high-level languages. Third-generation programming language • The introduction of the compiler in 1952 spurred the development of third-generation computer languages. • These languages enable a programmer to create program files using commands that are similar to spoken English. • Third-level computer languages have become the major means of communication between the digital computer and its user. • Such as BASIC, C, FORTAN and Pascal. Third-generation programming language High-level language • 3rd G Languages are High-level Languages. • After a program is written in one of the high-level languages, it must be either compiled or interpreted. Third-generation programming language • A Compiler program rewrites the program into machine language that the CPU can understand. This is done all at once and the program is saved in this new form. • A compiled program is generally considerably larger than the original. • An Interpreter program translates the program statements into machine language one line at a time as the program is running. • An interpreted program will be smaller than a compiled one but will take longer to execute. Fourth-generation programming language • A fourth-generation programming language (1970s1990) (abbreviated 4GL) is a programming language or programming environment designed with a specific purpose in mind, such as the development of commercial business software. • In the evolution of computing, the 4GL followed the 3GL in an upward trend toward higher abstraction and statement power. • The 4GL was followed by efforts to define and use a 5GL. Fourth-generation programming language • 3GL development methods can be slow and error-prone. • Some applications could be developed more rapidly by adding a higher-level programming language and methodology which would generate the equivalent of very complicated 3GL instructions with fewer errors. • All 4GLs are designed to reduce : programming effort, the time it takes to develop software and the cost of software development. Fourth-generation programming language • Fourth-generation languages have often been compared to domain-specific programming languages (DSLs). • For example, a typical 4GL command is FIND ALL RECORDS WHERE NAME IS "SMITH" Types of 4 GL :• Table-driven (codeless) programming, usually running with runtime framework and libraries. Instead of using code. • Report generators take a description of the data format and the report to generate and from that they either generate the required report directly or they generate a program to generate the report. • Data management 4GLs such as SAS, SPSS and Stata provide sophisticated coding commands for data manipulation, file reshaping, case selection and data documentation in the preparation of data for statistical analysis and reporting. Some fourth-generation languages • • • • • • • • FoxPro PowerBuilder SQL Report Builder Oracle Reports Graph Talk MATLAB CSS Examples of 4G Languages FoxPro FoxPro has two meanings: • Visual FoxPro - an object-oriented programming language and RDBMS, published by Microsoft, for Microsoft Windows. • FoxPro 2 - a text-based procedural programming language and RDBMS, originally published by Fox Software and later by Microsoft, for MS-DOS, Microsoft Windows, Macintosh, and UNIX Examples of 4G Languages Database query languages • Query languages are computer languages used to make queries into databases and information systems. • Query languages can be classified according to whether they are database query languages or information retrieval query languages. • SQL is a well known query language for relational databases. • XQuery is a query language for XML data sources. Fifth-generation programming language • Fifth generation computing devices, based on artificial intelligence, are still in development, though there are some applications, such as voice recognition, that are being used today. • The use of parallel processing and superconductors is helping to make artificial intelligence a reality. • The goal of fifth-generation computing is to develop devices that respond to natural language input and are capable of learning and self-organization. Fifth-generation programming language Examples : Artificial intelligence : • The branch of computer science concerned with making computers behave like humans. • There are several programming languages that are known as AI languages because they are used almost exclusively for AI applications. The two most common are LISP and Prolog. Fifth-generation programming language Examples : Neural network • A type of artificial intelligence that attempts to imitate the way a human brain works. • A neural network works by creating connections between processing elements, the computer equivalent of neurons. • Neural networks are currently used prominently in voice recognition systems, image recognition systems, industrial robotics, medical imaging, data mining and aerospace applications. 4th Generation Programming Languages • A fourth-generation programming language (or 4GL) is a programming language designed with a specific purpose in mind such as the development of commercial business software. • fourth-generation languages are closer to human languages than typical high-level programming languages. • Most 4GLs are used to access databases. History Of 4GL • The term 4GL was according to James Martin first used in his 1982 book Applications Development Without Programmers to refer to non-procedural high-level specification languages. – A SPECIFICATION language is one that enables a programming task to be performed by the construction of a set of non-procedural statements. • In 1987 Grindley distinguished between a Pure and a HYBRID 4GL Why 4GL? • Programming effort – They can be easily learnt since there are relatively few commands, functions and structures. • • • • The cost of software development. Alter and maintain Ease of use Simplicity of design and implement Why 4GL? • The time it takes to develop software – Programs written in a 4GL can be written very quickly. Each statement written may generate a large amount of code containing a high level of functionality and productivity. For example, consider the SQL statement: SELECT surname, line_no, ddress_line FROM patient, patient_address WHERE patient.nhs_no=patient_address.nhs_n ORDER BY patient.nhs_no, line_no To write the equivalent in a 3GL would require many lines of code and the procedural and iteration structures that are absent from SQL. Different Types Of 4GL – Theory • Pure 4GL: A specification language made up of non-procedural instruction sets. • HYBRID 4GL: A number of pure 4GLs combined with and held together by a more procedural language. – Implementation • Report generators • Forms generators • 4GLs (sometimes termed fourth generation environments) – attempt to automatically generate whole systems from the outputs of CASE tools, specifications of screens and reports, and possibly also the specification of some additional processing logic. Additional Components • Some 4GLs have integrated tools which allow for the easy specification of all the required information. – James Martin's Information Engineering systems development methodology • allow the input of the results of system analysis and design in the form of Data Flow Diagrams, Entity Relationship Diagrams, Entity Life History Diagrams etc from which hundreds of thousands of lines of COBOL would be generated. – Oracle Corporation’s Oracle Designer and Oracle Developer • could be integrated to produce database definitions and the forms and reports programs. 4GL Advantages & Disadvantages • Being specification languages, their use requires, in theory at least, no programming task; the necessary code will be generated directly from the specification. • Can only address a small and very highly specialized area of development 4GL In Action • Database query languages: – SQL – Oracle SQL*Plus – Progress 4GL • Data-stream languages: – AVS – APE – Iris Explorer • Screen painters and generators: – Oracle Forms 4GL In Action • Report Generators: – Oracle Reports – LINC – GEMBase – BuildProfessional – Informix-4GL – Focus – Metafont – RPG-II – S – IDL-PV/WAVE – Gauss – Mathematica Oracle As A 4GE FOURTH GENERATION ENVIRONMENT (4GE) ? • In order to provide an environment in which a complex system can be developed, a number of different types of "pure" fourth generation languages must be integrated, and further procedural programming facilities must be provided. 4GE Components Typical 4GE components: – END-USER QUERY LANGUAGE (e.g. SQL), – SCREEN FORMATTER (e.g. Oracle's screen painter in SQL*Forms), – REPORT GENERATOR. 4GE Components • DATA DICTIONARY : – Central to all fourth generation environments – A system database, rather than a user database, which holds metadata as opposed to the data itself and the DATABASE MANAGEMENT SYSTEM. – A place to store all the various schemas and mappings in both source and object form – Cross-reference information : • • • • Which programs use which pieces of the database Which user requires which reports Qhat terminals are connected to the system … Page 15 Of 33 DBMS Rules • The database management system performs two functions: – Filehandler for the systems developed using the components of the 4GE – It is the software that manages the data dictionary. Page 16 Of 33 Oracle as a 4GE – SQL*Plus Allows users to create and manipulate tables using SQL. – SQL*Forms An interactive applications generator for creating advanced, forms-based applications. – SQL*Loader A module to simplify the process of the entry of large quantities of data into tables. – SQL*Report A module for generating complex reports. – SQL*Menu A module to enable the coordination of forms by an interactive menuing system. – SQL*DD Design Dictionary - a structured system to monitor and control the development from the initial analysis to running and maintenance. – EASY*SQL An interface for inexperienced users of SQL using a mouse and screen graphics. – SQL*Calc An Excel compatible spreadsheet that may use database data; the spreadsheet cells can call SQL statements. – SQL*Graph Provides a graphical representation of data retrieved from the database. – SQL*Text A module for creating a forms interface to large text databases. Page 17 Of 33 SQL Structured Query Language Page 18 Of 33 SQL Command Types Query Commands – Select – Create View – … • Update Commands – – – – Insert Delete Update … Page 19 Of 33 Retrieving Data (Select Command) • A typical SQL query has the form: select A1, A2, ..., An from r1, r2, ..., rm where P – Ais represent attributes – ris represent relations – P is a predicate. • The result of an SQL query is a relation. Page 20 Of 33 Retrieving Data (Views) • Provide a mechanism to hide certain data from the view of certain users. To create a view we use the command: where: <query expression> is any legal expression The view name is represented by v • A view consisting of branches and their customers create view all-customer as (select branch-name, customer-name from depositor, account where depositor.account-number = account.account-number) union (select branch-name, customer-name from borrower, loan where borrower.loan-number = loan.loan-number) Page 21 Of 33 Modification of the Database • Delete all account records at the Perryridge branch delete from account where branch-name = ‘Perryridge’ • Add a new tuple to account with balance set to null insert into account values (‘A-777’,‘Perryridge’, null) • Increase all accounts with balances over $10,000 by 6%, all other accounts receive 5%. update account set balance = balance 1.06 where balance > 10000 Page 22 Of 33 Domain Types in SQL • • • • • • • • • char(n). Fixed length character string, with user-specified length n. varchar(n). Variable length character strings, with user-specified maximum length n. int. Integer (a finite subset of the integers that is machine-dependent). smallint. Small integer (a machine-dependent subset of the integer domain type). numeric(p,d). Fixed point number, with user-specified precision of p digits, with n digits to the right of decimal point. real, double precision. Floating point and double-precision floating point numbers, with machine-dependent precision. float(n). Floating point number, with user-specified precision of at least n digits. Null values are allowed in all the domain types. Declaring an attribute to be not null prohibits null values for that attribute. create domain construct in SQL-92 creates user-defined domain types create domain person-name char(20) not null Page 23 Of 33 Date/Time Types in SQL (Cont.) • date. Dates, containing a (4 digit) year, month and date – E.g. date ‘2001-7-27’ • time. Time of day, in hours, minutes and seconds. – E.g. time ’09:00:30’ • time ’09:00:30.75’ timestamp: date plus time of day – E.g. timestamp ‘2001-7-27 09:00:30.75’ • Interval: period of time – E.g. Interval ‘1’ day – Subtracting a date/time/timestamp value from another gives an interval value – Interval values can be added to date/time/timestamp values • Can extract values of individual fields from date/time/timestamp – E.g. extract (year from r.starttime) • Can cast string types to date/time/timestamp – E.g. cast <string-valued-expression> as date Entity Management Commands • An SQL relation is defined using the create table command: – create table branch (branch-name char(15) not null, branch-city char(30), assets integer) • The drop table command deletes all information about the dropped relation from the database. • The alter table command is used to add attributes to an existing relation. – alter table r add A D • The alter table command can also be used to drop attributes of a relation – alter table r drop A Page 25 Of 33 Embedded SQL • The SQL standard defines embeddings of SQL in a variety of programming languages such as Pascal, PL/I, Fortran, C, and Cobol. • A language to which SQL queries are embedded is referred to as a host language, and the SQL structures permitted in the host language comprise embedded SQL. • EXEC SQL statement is used to identify embedded SQL request to the preprocessor EXEC SQL <embedded SQL statement > END-EXEC Note: this varies by language. E.g. the Java embedding uses # SQL { …. } ; Sample: EXEC SQL declare c cursor for select customer-name, customer-city from depositor, customer, account where depositor.customer-name = customer.customer-name and depositor account-number = account.account-number and account.balance > :amount END-EXEC Dynamic SQL • Allows programs to construct and submit SQL queries at run time. • Example of the use of dynamic SQL from within a C program. char * sqlprog = “update account set balance = balance * 1.05 where account-number = ?” EXEC SQL prepare dynprog from :sqlprog; char account [10] = “A-101”; EXEC SQL execute dynprog using :account; • The dynamic SQL program contains a ?, which is a place holder for a value that is provided when the SQL program is executed. Microsoft English Query What Is English Query? With English Query, developers can use their SQL and OLAP databases as a basis to build an English Query application, which allows end users to query the database in English. SELECT sum(Orders.Quantity) from Orders, Parts WHERE Orders.State='WA' and Datepart(Orders.Purchase_Date,'Year')='1996' and Part.PartName = 'ProductX' and Orders.Part_ID = Parts.Part_ID How it works? References • • • • • • • Microsoft English Query Tutorials Microsoft SQL Server 2000 User Manual http://portal.acm.org http://burks.brighton.ac.uk/ http://www.soi.city.ac.uk/ http://en.wikipedia.org/wiki/4GL http://encyclopedia.fablis.com/index.php/Fourth-generation_language