A Proposed Software Description Language for Representing Program Logic in XML


Thèse de Master, 2012

125 Pages, Note: none


Extrait


Table of Contents

TITLE PAGEI

Authorization Statement

Examination Committee Decision

Acknowledgements

Dedication

List of Tables

List of Figures

الملخص

Abstract

CHAPTER 1 : Introduction
1.1 Preface
1.2 Problem Definition
1.3 Contributions
1.4 Significance
1.5 Limitations
1.6 Thesis Outline (Thesis Organization)

CHAPTER 2 : Literature Survey
2.1 Theoretical Background
2.1.1 Programming Languages, Syntax and Semantics
2.1.2 Paradigms of programming languages
2.2 Related Work
2.3 What Distinguishes This Thesis?

CHAPTER 3 : The Proposed Model
3.1 SDL and Its Role in the Conversion between Languages
3.2 SDL’s Features List
3.2.1 The Object Oriented Features
3.2.2 The Imperative Paradigm Features
3.3 SDL Schema
3.4 Transformation Algorithms and Functions

CHAPTER 4 : Experimental Results
4.1 Switch Statements
4.2 Conditional Statements
4.3 Bitwise Expression
4.4 Arrays
4.5 Object Oriented Programming
4.6 Sorting Algorithms
4.7 Sample of Validation Cases Execution Results

CHAPTER 5 : Conclusion and Future Work

References

Acknowledgements

I would like to express my sincere thanks to Prof. Azzam Sleit for his continuous support, efforts, and dedication.

I would also like to express my deepest gratitude, appreciation and love to Prof. Mohammad Al-Haj Hassan for encouraging me to continue in the idea while it was in the early beginnings. Special thanks are due to Dr.Hussien Owaied for helping me in publishing my first paper on the subject. I also thank my colleague Mohammed Salah Abu Saad for all his support, patience and invaluable advices.

I would like also to express my deep thanks, appreciation and admiration to Prof. Deya’ Edeen Arafa for his unique and exceptional support and for guiding me in the most critical stage of the thesis, which is choosing the appropriate supervisor.

I would also like to thank the discussion committee for enriching my thesis with their comments and to MEU.

Dedication

I would like to express my thanks to my family for helping me and supporting me during my study.

List of Tables

2-1 Example of different syntactic representation

2-2 Context Free Grammar Types

2-3 Examples of operational semantics

2-4 Lambda Calculus Expressions

3-1 Meanings of symbols used in the diagrams of the specification

4-1 Switch Statement Components in XML

4-2 Fragments of the SDL code for the conditional statements

4-3 Java source code of the binary form program

4-4 Fragments of the binary form program in SDL

4-5 SDL fragments for the arrays validation case

4-6 Fragments of the SDL representation of the object oriented validation case

4-7 Inputs and outputs for the sorting validation cases

4-8 Inputs and output for the linear search and binary search programs

4-9 Results for the binary form validation case

List of Figures

2-1 Statement with correct syntax and incorrect semantics

2-2 Examples of definition in BNF

2-3 Module declaration in SDF

2-4 Definition of a Boolean literal in syntax diagrams

2-5 Denotational semantics for arithmetic expressions

2-6 Part of denotational semantics for Boolean expressions

2-7 Variable Declarations in C

2-8 Variable Declarations in Pascal

2-9 Assignment Statements in C

2-10 Conditional Statement in C

2-11 For loop in Pascal

2-12 Classes and Objects

2-13 Inheritance

2-14 Polymorphism in Java

2-15 Lambda Calculus Syntax

2-16 Applied Lambda Calculus

2-17 Facts in first order predicate logic

2-18 Facts and rules in Prolog

2-19 Source Code Representation in Model Independent Source Code Repository

2-20 JavaML Representation of Source Code

2-21 C++ source code representation in XML

3-1 SDL and its rule in the conversion between languages

3-2 Condition Expression in C++

3-3 Loop structure in C++ and Java

3-4 Loop structure in VB.NET

3-5 The ‘source’ element

3-6 ‘source’ element XSD specification

3-7 The ‘package’ element

3-8 ‘package’ element XSD specification

3-9 The ‘class’ element

3-10 XSD specification for the ‘class’ element

3-11 The ‘interface’ element

3-12 XSD Specification for the ‘interface’ element

3-13 The ‘type’ element

3-14 XSD specification for the ‘type’ element

3-15 XSD specification of the ‘method’ element

3-16 The ‘method’ element

3-17 The’variable-data-declaration’ element

3-18 ‘variable-data-declaration’ XSD specification

3-19 ‘variable-declaration’ XSD specification

3-20 The ‘variable-declaration’ element

3-21 The ‘constructor’ element

3-22 XSD specification for the constructor element

3-23 The ‘statement’ group

3-24 The ’expression’ group

3-25 The ‘literal-expression’ group

3-26 ‘literal-expression’ XSD specification

3-27 The “loop” element

3-28 ‘Loop’ element XSD specification

3-29 The ‘if’ element

3-30 XSD specification of the ‘if’ element

3-31 The ‘switch’ element

3-32 XSD specification of the ‘switch’ element

3-33 The ‘while’ element

3-34 XSD specification of the ‘while’ element

3-35 The ‘arithmetic-expression’ element

3-36 XSD specification for the ‘arithmetic-expression’ element

3-37 The ‘cast’ element

3-38 XSD specification for the ‘cast’ element

3-39 The ‘instantiation’ element

3-40 XSD specification for the ‘instantiation’ element

3-41 The ‘variable-reference’ group

3-42 The XSD specification for the ‘variable-reference’ group

3-43 The ‘return’ element

3-44 XSD specification for the ‘return’ element

3-45 The ‘parenthesised-expression’ element

3-46 XSD specification for the ‘parenthesized-expression’ expression

3-47 The ‘array-access-expression’ element

3-48 The XSD specification for ‘array-access-expression’

3-49 The ‘array-creation-expression

3-50 The ‘array-creation-expression’

3-51 The entry point function for the transformation

3-52 The transformation function for the class construct

3-53 Transformation of statements

3-54 The transform statement function

3-55 Transform “for” statement into “while” statement

3-56 The structure of the “Switch” statement in C++ and Java

3-57 Adapting the “switch” statement into VB.NET

4-1 Java Source Code for the Switch flow program

4-2 VB.NET Source Code for the Switch flow program

4-3 Java Source Code for the Conditional Statements Program

4-4 VB.NET Source Code for the Conditional Statements Program

4-5 Java code fragment for the array initialization

4-6 VB.NET code fragment for the array initialization

4-7 Java code of the object oriented validation case

4-8 VB.NET code of the object oriented validation case

4-9 Java code of the Insertion sort

4-10 VB.NET code of the Insertion sort

4-11 Representation of Insertion sort in SDL

4-12 Representation of bubble sort in Java

4-13 Representation of bubble sort in VB.NET

4-14 Representation of Bubble sort in SDL

4-15 Representation of Merge Sort in Java

4-16 Representation of Merge Sort in VB.Net

4-17 Representation of Merge Sort in SDL

لغة وصف برمجيات مفترضة لتمثيل البرامج بلغة التوصيف الموسعة

الطالب

خالد زهير محمود

المشرف

الأستاذ الدكتور عزام سليط

الملخص

يقوم هذا البحث بطرح لغة برمجيات مفترضة لتمثيل البرامج المكتوبة بلغة C++و الجافا و VB.netعن طريق لغة التوصيف الموسعة. إن التشابهات الدلالية بين هذه اللغات، تتيح تمثيل الشيفرات المصدرية بطريقة يمكن من خلالها مشاركة منطق، و شيفرة البرنامج، و إعادة استخدامها بسهولة بين هذه اللغات. و من خلال إجراء مقارنة بنائية، و دلالية بين لغات C++، و جافا و VB.net، تم تصميم اللغة المقترحة لتتضمن الصفات والتراكيب المتشابهة والمتطابقة، حيث تم تطوير تركيب متماثل في اللغة المقترحة لكل تركيب لغوي معتمد.

لقد تمت أيضا، دراسة صحة اللغة المقترحة، و إثباتها نظريا من خلال عقد مقارنة دلالية بين اللغات الثلاثة، و تجريبيا عن طريق تطوير تطبيق يحول الشيفرة المصدرية من لغة جافا إلى اللغة المقترحة، و من اللغة المقترحة إلى لغة VB.net.

و بالنسبة لحالات التحقق، فقد تم تصميمها لتشمل عدة برامج، منها الفرز والبحث، و لتشمل أيضا التراكيب البرمجية الأكثر استخداما في اللغات الثلاثة.

تم تحويل الشيفرة المصدرية لحالات التحقق من الجافا إلى اللغة المقترحة، و من اللغة المقترحة إلى VB.net. أما برامج الجافا و VB.netلحالات التحقق، فقد تم تنفيذها و مقارنة النتائج، و كانت النتائج متطابقة في جميع التجارب.

للغة المقترحة بعض الفوائد الأساسية في عمليات التحويل بين لغات البرمجة، كلغة وسيط، يمكن استخدامها في التكامل والدمج بين الأنظمة، كما أنها تسمح بمشاركة منطق البرامج خلال وقت التشغيل، في حين أن تقنيات الدمج الحالية تتيح فقط مشاركة البيانات بين الأنظمة المختلفة.

لم تتطرق هذه الرسالة إلى تكيف مكتبات لغات البرمجة و وظائفها، إلا أن العمل في المستقبل قد يوسع اللغة المقترحة للتكيف مع مختلف المواصفات، كالمؤشرات، و التوارث المتعدد.

A Proposed Software Description Language for Representing Program Logic in XML

By

Khaled Zuhair Mahmoud

Supervised by

Prof. Azzam Sleit

Abstract

This thesis proposes a software description language to represent the source code of C++, Java, and VB.NET in the Extensible Markup Language. The similarity of semantics between these languages enables representing the source code in a form such that both, the source code and logic can be easily shared and reused between these languages.

By performing semantic and syntactic comparison between C++, Java and VB.NET, the proposed language has been designed to include the similar and identical features and language constructs. For every adopted language construct, a corresponding construct in the proposed language has been developed.

The validity of the proposed language has been investigated and proved theoretically by conducting a semantic comparison between the three languages and experimentally by developing applications to convert source code from Java into the proposed language and from the proposed language into VB.NET. Validation cases have been designed to include various programs such as sorting, searching and also to include the most used programming constructs in the three languages. Source code of the validation cases have been converted from Java into the proposed language, and from the proposed language into VB.NET. Java and VB.NET programs of the validation cases have been executed and results compared. The results were identical for all conducted experiments.

The proposed language has some major benefits in the conversion between programming languages as an intermediary language. It may also be used in the integration between systems as it enables sharing of programming logic at runtime. Existing integration technologies only enable the sharing of data between various systems.

This thesis is not concerned with adapting programming languages libraries and functions. Future work may extend the proposed language to adapt different features such as pointers and multiple-inheritance into the proposed language.

Chapter One Introduction

1.1 Preface

The object oriented programming paradigm is widespread and many of the well-known and most used programming languages were designed to support this paradigm; Java and C++ are examples of such languages. Also, there are languages which were originally designed not to support the object oriented paradigm but have started to support it recently; PHP is a good example of those languages.

Many of the languages that support the object oriented paradigm have many semantics in common, for instance C++, VB.NET and Java support inheritance, overriding of functions, function overloading, and type casting. Differences also exist, for example while Java and VB.NET support interface declaration, C++ has no support for interfaces. In addition, nearly all programming languages provide the same basic set of features; control statements, declaration of variables, and calling of subroutines. Since there are similarities between programming languages, a description language can be developed to represent code written in similar languages so that code and logic can be easily shared and reused between similar languages, and this is the purpose and scope of this thesis where the features of different object oriented programming languages are compared to develop a proposed representation in XML (Extensible Markup Language) that includes the common features among C++, VB.NET and Java. This proposed representation has been named Software Description Language (SDL).

XML is widely used to store and exchange data, and its features that are borrowed from the relational, object oriented, and hierarchical models made it very powerful for data representation (Elmasri , et al. 2005). The structure of an XML document is specified by a document written in any of the schema description languages such as XSD( XML Schema Definition) and DTD (Document Type Definition) (Evjen, et al. 2007), and this enables automatic validation of XML documents. Since XSD is more powerful and expressive than DTD, XSD has been used for the specification of the developed model language.

1.2 Problem Definition

There are more than one hundred programming languages (Chen 2009), and many systems that use a wide variety of these languages. A subroutine written in VB.NET cannot be used directly by a subroutine written in Java and vice versa, unless that subroutine is converted from its language to the target subroutine's language. It is also the nature of software that there are functions that are similar in many different systems regardless of the implementing programming language. There even exist organizations whose main purpose is the development of reusable components in certain languages; Apache software foundation is a good example. If one of those companies wants to support another programming language, it has to rewrite its code for that language.

This thesis addresses the following issues:

1. There is no universally agreed upon representation for programming logic
2. If a program or module is to be converted from language A to language B, knowledge in both, the syntax and semantics of language B (the destination language) is required.

1.3 Contributions

The contributions of the thesis are as follows:

1. The development of the Software Description Language which is an XML representation of source code for C++, VB.NET, and Java that includes the common features between these languages.
2. The development of the algorithm that transforms an abstract syntax tree into the Software Description Language.

1.4 Significance

The adaptation of the proposed software description language facilitates converting a program from one language to another and it will initiate and ignite more advancement in different areas such as software integration between different platforms and systems. As an example of its significance as an intermediary language in the conversion between languages, programming language vendors such as Sun, Microsoft and Oracle may create tools to export and import source code from and to the proposed language. This enables a VB.NET developer to easily share and convert source code and libraries into C++ and Java.

Integration technologies such as XML web services and CORBA (Common Request Broker Architecture) enable heterogeneous systems to exchange data by agreeing on a well defined format of messages such as XML, JSON or other format, but they cannot exchange program logic. Adaptation of the proposed language enables systems to exchange algorithms and program logic at runtime by exchanging XML documents containing source code represented in the software description language. An application of is that a VB.NET application may send some part of its logic to be executed at a high performance application server running a C++ application The results of execution maybe exchanged via XML or any other appropriate formats.

1.5 Limitations

1. The proposed description language covers only C++, VB.NET, and Java.
2. The proposed description language does not adapt APIs specific to each of the three programming languages.
3. This research covers a subset of the semantics and features of the three languages that are common such that they can be adapted and migrated between the three languages.

1.6 Thesis Outline (Thesis Organization)

Chapter 2 presents information and theoretical background about the syntax and semantics of programming languages, types of programming languages including the object oriented programming languages and some of the technologies that are used by this thesis such as XML and XSD. It also lists the related researches about source code representation.

Chapter 3 presents the proposed model and the specifications of the proposed language as well as the algorithms that transform source code into the proposed description language. It also lists the features that are included in the proposed language.

Chapter 4 lists the experimental verification results that include source code in Java, its representation in SDL, and its representation after being transformed from SDL to VB.NET.

Finally Chapter 5 discusses the results and draw conclusions and future work.

Chapter Two Literature Survey

This chapter presents knowledge and theoretical background about the syntax and semantics of programming languages, and types of programming languages including the object oriented programming languages and some of the technologies that are used by this thesis such as XML and XSD. It also presents the related researches about representation of source code in XML.

2.1 Theoretical Background

This section presents the necessary theoretical background and concepts necessary for understanding the topics related to thesis.

2.1.1 Programming Languages, Syntax and Semantics

A language is a set of symbols combined together according to a set of rules, known as the grammar or the syntax of the language, that are understood by both the sender and the receiver (Fischer & Grodzinsky, 1992). A language can either be natural or artificial. A natural language is a language that evolves naturally as means of communication between people (Vargas, J.V, 2011), while an artificial language is a language that is developed intentionally by the human for a specific purpose. Examples of natural languages include English, French, and Spanish and most human spoken languages. Examples of artificial languages include computer programming languages such as C++, Java, SmallTalk and Ada. Another example is Esperanto which is a planned human language intended for communication between people (Kadhim & Waite, 1996).

All languages have two types of rules which are the syntax rules and the semantic rules. The syntax rules define how to build correct sentences and structures and also include the set of words to be used in the language. Semantic rules define how to interpret those sentences and structures. A sentence that has a correct syntax is not necessarily meaningful. Figure 2-1 shows a sentence that has correct syntax but incorrect semantics because an integer variable cannot be assigned a string literal.

illustration not visible in this excerpt

Figure 2-1: Statement with correct syntax and incorrect semantics

Syntax specification of a programming language can be either concrete or abstract (Moses, 2006). Concrete syntax describes the phrase structure of the language (Kadhim & Waite, 1996) and determines which strings are accepted as programs (Moses, 2006), while abstract syntax deals with structure of programs without paying attention to the actual characters used to write the program. Abstract syntax specifies what the elements constitute the language and what the components of each element are. Abstract syntax for example may specify that an assignment statement is composed of one variable reference element on the left side and an expression element on the right side without specifying the actual textual representation. One concrete syntax specification may choose to use the ‘=’ to denote equation and another may choose to use the word ‘equals’, and another one may prefer to surround the expression between square brackets ‘[]’. A sentence written in the abstract syntax form may be written in many concrete syntax forms. Table 2-1 shows how an arithmetic operation statement is written in various syntactic forms.

Table 2-1: Example of different syntactic representation

illustration not visible in this excerpt

Concrete syntax rules specify the keywords of the programming language and the naming rules of variables and also what the operators in the language are. In Java, syntax rules specify that a variable name is case sensitive and that it may only start with either '_', '$' or an alphabetical character.

Syntax of a programming language, either abstract or concrete, is specified through phrase-structure grammars. Language specification in phrase structure grammars consists of a set of symbols V, which is used to form sentences, words and literals and all members of the language, a set of terminal symbols T, a set of non-terminal symbols N, and a set of production rules P and a start element S. Elements of T and N are strings of finite elements of V. Terminal symbols cannot be broken into smaller parts and examples of them include the keywords of the programming language, and other symbols such as the semi colon, curly braces and square brackets. Non-terminal symbols can be broken into parts and they represent structural elements in the language. Productions are rules that specify what string from the set of all possible strings of V may replace another string from the same set. Productions are of the form 'a --> b'. An example is the use of a production to specify variable declaration. where the left hand side is the non-terminal symbol 'declaration' and the right hand side is the terminal symbol 'declare' followed by the non-terminal symbol 'variable name' followed by the non-terminal symbol 'type', assuming that the non terminal symbols 'type', 'variable name' are also declared and specified by other productions.

Phrase-structure grammars have four types; type 3 (regular grammar), type 2 (context free grammar), type 1 (context sensitive grammar) and type 0 (Rosen, 2011). Those types differ in the way productions are written. Table 2-2 shows the differences between these four types.

Table 2-2: Context Free Grammar Types

illustration not visible in this excerpt

Formal syntax of a programming language is specified using a syntax meta- language, which is a notation for defining the syntax of a language by a number of rules (Scowen, 1993). BNF (Backus Naur Form) is a syntax meta-language that is widely used in language specifications and documentations such as MSDN (Microsoft Developer Network) and the official Java language specification (Gosling, Steele & Joy, , 2008). A variation of BNF is EBNF (Extended BNF) that it is used to specify syntax of context free languages. Production rules in EBNF consist of a non-terminal symbol on the left hand side and any number of terminals and non-terminals on the right hand side. EBNF has operators and symbols that enable it to define proper productions and of these symbols is the double quote, which is used to define terminal symbols. Figure 2-2 shows various examples of definitions in EBNF. The example shows the usage of various symbols such as ',' which denotes concatenation, '[ ]' which denotes that the symbols enclosed by the square brackets are optional, '{ }' which denotes that symbol enclosed by those curly braces may appear zero or more times, and the '|' which denotes an alternative.

illustration not visible in this excerpt

Figure 2-2: Examples of definition in BNF.

SDF (Syntax Definition Formalism) is another language for describing syntax that is distinguished over BNF and EBNF by allowing syntax description to be divided into modules (Heering, Hendriks, Klint & Rekers, 1989). Each module declares its own syntax rules..For example, a dedicated module for numbers may contain definitions for floating point numbers, integers, hexadecimal representations of numbers, and a module may export his rules so they may be reused by other modules. Productions in SDF are written from right to left, which means that the defined entity is on the right side. Module declarations include the ‘sorts’ section, which declares the non-terminal symbols to be used in the productions, an imports section which imports grammars and other entities such as aliases from other modules. Figure 2-3 shows an example of a module declaration in SDF. In this declaration, the non terminal symbols declared are ‘Word’ and ‘Command. The non terminal ‘Word’ is declared as an alphanumeric string, and the non-terminal symbol ‘Command’, have five distinct forms. Valid syntactic statements according to this definition include ‘go to MEU’, ‘move to Amman’, ‘put Books on Shelf’, ‘fetch Pepsi from Refrigerator’.

illustration not visible in this excerpt

Figure 2-3: Module declaration in SDF

Syntax is also specified using syntax diagrams (Reis, 2011) which graphically show how structural parts of the syntax are defined and connected to each other. Syntax diagrams are capable of specifying context free grammars and they were first used to specify the syntax of the Pascal language. The symbols of syntax diagrams consist of rectangles which denote non terminal symbols, and ovals which denote terminal symbols and arrows to specify the flow of definition. Parallel arrow paths within a declaration denotes options, equivalent to the symbol ‘|’ in EBNF. Sequential symbols in a single arrow denote concatenation which is equivalent to the symbol ‘,’ in EBNF. Figure 2-4 shows part of a syntax diagram that declares a Boolean literal.

illustration not visible in this excerpt

Figure 2-4: Definition of a Boolean literal in syntax diagrams

Syntax alone is not enough to specify a programming language, and without the specification of semantics a program is just a sequence of characters. Semantics show how a program should be interpreted and the meaning of each language element. Specification of semantics can be formal or in informal. In languages such as Java, C#, VB.NET, an informal semantic description is included in the official language documentation as textual paragraphs, clarifying examples and tutorials, while formal semantics is of narrow use in practice and it heavily makes use of mathematical notations, equations, and formal methods. There are three main types of formal semantics; denotational semantics, operational semantics, and axiomatic semantics (Zhan & Xu, 2004).

Denotational semantics, which are also called mathematical semantics, assign meanings to language elements by mapping them into mathematical objects such as functions and sets (Slonneger & Kurtz, 1995). A specification in denotational semantics consists of a description of the abstract syntax that lists all of the abstract syntax elements and the production rules which define the structure of those abstract elements, a semantic domain which consists of mathematical objects such as sets, structures, functions and equations that maps abstract syntactic elements into mathematical elements defined in the semantic domain. Figure 2-5 presents a part of the denotational semantics for arithmetic expressions. The abstract syntactic element 'ArithmeticExpression' is defined in the syntactic domain declaration, and a semantic domain denoted by the symbol 'Z' is defined to be the set of all natural numbers. In the semantic functions declarations, function 'A' is defined to map an ‘ArthimeticExpression’ element into a natural number. In the semantic equations declaration, four equations are defined to illustrate how function 'A' operates on plus, minus, multiplication, and division. At any point of program execution, a program is said to be in a certain state which is the value of all variables at that point, and this is denoted by the ‘σ’ symbol. A [[x]] σ means the denotational meaning of applying function ‘A’ on expression x under state ‘σ’. The first equation defines the arithmetic denotational meaning of (lexpression + rexpression) as the sum of arithmetic denotational meaning of lexpression and arithmetic denotational meaning of rexpression.

illustration not visible in this excerpt

Figure 2-5: Denotational semantics for arithmetic expressions

Figure 2-6 shows part of the semantic denotation specification for Boolean expressions, and it uses the 'A' function declared in Figure 2-4. The first two equations, map the literals ‘true’ and ‘false’ into the mathematical values ‘true’, ‘false’ declared in the semantic domain. The third equation is an example of a Boolean expression resulting from comparison between two arithmetic expressions.

illustration not visible in this excerpt

Figure 2-6: Part of denotational semantics for Boolean expressions.

During the execution of program statements, changes to the state of program occur. Operational semantics is concerned with the details of execution and how it transforms the program from a state to another. Specification in operational semantics is composed primarily of transition rules, also called execution rules, with each rule showing a transition in state (Turbak, Gifford, & Sheldon, 2008). An execution rule is composed of two parts, the premise and the conclusion. The premise is a set of preconditions that must be met in order for the program to be in the new state defined by the conclusion. Table 2-3 shows various executions rules along with their meanings.

Table 2-3: Examples of operational semantics

illustration not visible in this excerpt

Axiomatic semantics describe the meaning of a program by providing assertions about the program (Regan, 2007), and they have wide applications in proving the correctness of algorithms and programs. Assertions are written as Hoare Triples which are based on predicate logic. Assertions are of the form C {S} Q where S is the program structure or statement, C are a set of assertions about the state of the program before executing and Q is a set of assertions about the state of the program after executing.

2.1.2 Paradigms of programming languages

Difference in semantics and features of programming languages is what makes them different. Some languages are similar to each other although they are different in syntax such as VB.NET and Java. According to their features and semantics, languages are classified to belong to one of the main paradigms; the object oriented paradigm, the functional paradigm, the logical paradigm and the imperative paradigm (Madsen, 2000). This section presents the main four programming language paradigms.

2.1.2.1 The Imperative Paradigm

Programs in imperative languages are composed of sequence of statements and commands that change the program state (Dowek, 2009), which is the set of all variables declared by the program. Almost all imperative programming languages include conditional statements, iteration structures, variable declaration statements, variable assignments, procedure and function declarations, and a mechanism for handling exceptions and errors.

A variable declaration statement allocates space in memory and associates it to a variable. The allocated space may contain an actual value or a pointer to another memory location. The contents of the reserved space is changed and controlled through the variable. A variable declaration statement must at least consist of the variable name, and according to the language type , statically or dynamically typed, may also consist of the type of the declared variable, and an optionally an initialization expression. C and Pascal are examples of statically typed imperative languages (Salus, 1999).

Declaration statements in C are composed of the variable type followed by the variable name and optionally the equal sign and an initialization expression, while in Pascal the ‘var’ keyword is used to begin the declaration statement, followed by a carriage return, and followed by multiple lines, each line declaring one or more variables. Figures 2-7 and 2-8 presents examples of variable declarations in C and Pascal.

illustration not visible in this excerpt

Figure 2-8: Variable Declarations in Pascal

In dynamically typed languages, the type of the variable is inferred at runtime based on the values assigned to it and according to the operations performed on the variable. An assignment statement that assigns a variable an integer value will set the variable type to integer. Also, the variable type in some dynamically typed languages such as JavaScript can be changed at run type by assigning the variable to another value of different type.

Assignment statements are composed of three main parts; referencing a variable, the assignment operator and the assignment expression. The assignment operator in C and Fortran is the equal sign while Pascal uses the '’:=’ symbol. The assignment expression can be a literal value such as 4, ‘a’, “A simple string”, true or a reference to another variable, and in this case the value of the declared variable will be the same value of the referenced variable in the assignment expression. Also, any valid expression may be used in the assigned expression such as arithmetic expressions and Boolean expressions. Figure 2-9 presents various examples on assignment expressions in C.

illustration not visible in this excerpt

Figure 2-9: Assignment Statements in C

Conditional statements enable the conditional execution of a statement or group of statements based on the value of a boolean expression and the most common type is the if/else-if/else statement. Figure 2-10 shows a part of C program that prints whether an integer is even or odd.

illustration not visible in this excerpt

Figure 2-10: Conditional Statement in C

Iteration structures enable the execution of a sequence of statements repeatedly based on certain conditions. While-do/loop is one form of the iteration structures, which consists of a loop condition, and the body of the loop. In the While-do/loop, statements inside the body of the loop will be executed repeatedly until the loop condition evaluates to false. Another form of iteration structure is the do-while loop and it has the same structure as the while-do loop except that it will execute the body of the loop before checking the condition. Also there is the for-loop, which is in many languages such as Pascal and VB.NET consists of a lower bound and an upper bound and a loop step and a loop body. The loop body will be executed as long as the lower bound is not greater than the upper bound, and after each iteration the step statement will be executed to change the value of the lower bound. Figure 2-11 shows a complete program in Pascal that uses for-loop to calculate the sum of numbers from one to ten.

illustration not visible in this excerpt

Figure 2-11: For loop in Pascal

During the execution of a program, various types of errors may occur such as unexpected errors due to division by zero, hardware failure, network communication, and other reasons. Also, the program code itself may decide that there is an error condition according to certain business rules, such as validating that the age is not less than zero. In both cases, if the exception is not handled, the program will terminate. Many imperative programming languages provide mechanisms for handling errors and taking actions such as logging the error in a log file, sending alert, or informing the user of incorrect input. The C++ language provides the try-catch structure for handling errors. The try-catch is composed of a try block containing the statements that are expected to generate errors, a catch block containing the statements to execute in case of error conditions, and an optional finally block that will always be executed. When an exception occurs, the flow of execution stops and moves up in the method stack until a ‘try’ block and its associated ‘catch’ block are encountered, where the statements inside the catch block get executed.

Imperative languages enable the declaration of subroutines which are groups of instructions declared inside the program that perform a specific task (Dhotre & Puntambekar, 2008) and can be called at any point by any part of the program. Using subroutine helps against writing the same group of statements whenever needed, thus reducing code size, increasing modularity and code clarity. Programming languages have rich libraries of built-in subroutines, in addition to the commercial and open source libraries. POSIX thread is an example of a library providing multi threading functionality to C++.

[...]

Fin de l'extrait de 125 pages

Résumé des informations

Titre
A Proposed Software Description Language for Representing Program Logic in XML
Cours
Information Technology
Note
none
Auteur
Année
2012
Pages
125
N° de catalogue
V209330
ISBN (ebook)
9783656369684
ISBN (Livre)
9783656370352
Taille d'un fichier
1095 KB
Langue
anglais
Mots clés
proposed, software, description, language, representing, program, logic
Citation du texte
Khaled Mahmoud (Auteur), 2012, A Proposed Software Description Language for Representing Program Logic in XML, Munich, GRIN Verlag, https://www.grin.com/document/209330

Commentaires

  • Pas encore de commentaires.
Lire l'ebook
Titre: A Proposed Software Description Language for Representing Program Logic in XML



Télécharger textes

Votre devoir / mémoire:

- Publication en tant qu'eBook et livre
- Honoraires élevés sur les ventes
- Pour vous complètement gratuit - avec ISBN
- Cela dure que 5 minutes
- Chaque œuvre trouve des lecteurs

Devenir un auteur