-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathoexpl-specification.html
363 lines (296 loc) · 20.8 KB
/
oexpl-specification.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<!Doctype html>
<html lang="en">
<head>
<title>OExpL Specification</title>
<meta charset="UTF-8">
<!--<link rel="stylesheet" href="css/bootstrap.min.css">-->
<link rel="stylesheet" href="css/style_new.css">
<!-- <link rel="stylesheet" href="css/style.css"> -->
<script src="js/jquery-1.12.1.min.js" charset="utf-8"></script>
<script src="js/bootstrap.min.js" charset="utf-8"></script>
<script src="js/sticky_sidebar.js" charset="utf-8"></script>
</head>
<div class="container">
<header id="navtop">
<a href="index.html" class="logo fleft"><img src="img/logo.png" alt=""></a>
<nav class="fright">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="roadmap.html">Roadmap</a></li>
<li><a href="documentation.html" class="navactive">Documentation</a></li>
</ul>
</nav>
</header>
<div class="Services-page main grid-wrap">
<header class="grid col-full">
<hr/>
<p class="fleft">OExpL Specification</p>
<br>
<br>
<a class="button" href="pdfs/oexpl.pdf">Download as PDF(pending)</a>
</header>
<aside class="grid col-one-quarter mq2-col-full sticky_sidebar">
<menu>
<ul>
<li><a class="sec" href="#nav-intro">Introduction</a></li>
<li><a class="sec" href="#nav-class-definitions">Class Definitions</a></li>
<li><a class="sec" href="#nav-inheritance">Inheritance</a></li>
<li><a class="sec" href="#nav-class-variables-and-instantiation">Class variables and Instantiation</a></li>
<li><a class="sec" href="#nav-subtype-polymorphism">Subtype Polymorphism</a></li>
<li><a class="sec" href="#nav-run-time-binding">Run time Binding</a></li>
<li><a class="sec" href="#nav-sample-programs">Sample Programs</a></li>
<li><a class="sec" href="#nav-appendix">Appendix</a></li>
</ul>
</menu>
</aside>
<body>
<section class="grid col-three-quarters mq2-col-full">
<div class="grid-wrap">
<article class="grid col-full" id="nav-intro">
<h2>Introduction</h2>
<p>
An informal specification for a minimal object oriented extension of the ExpL languge with support for
<a href="https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)" target="_blank">Inheritance</a> and<a href="https://en.wikipedia.org/wiki/Polymorphism_(computer_science)" target="_blank"> subtype polymorphism </a> is outlined here.
</p>
</article>
<article class="grid col-full" id="nav-class-definitions">
<h2>Class Definitions</h2>
<p>
Classes extend the notion of ExpL types. A class <a href="https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)" target="_blank">encapsulates </a> <b><i>member fields</i></b> and <b><i>member functions</i></b> (called <b>methods</b> in OOP jargon). The following is an example for a class definition. Standard syntax and semantics conventions followed in languages like Java and C++ are assumed.
</p>
<script src="../js/a5a21ac08e12e3a57e8a7136100e0a50.js"></script>
<p>
All the class definitions in a program must be placed together, between the keywords <i>class</i> and <i>endclass</i>. Declaration of class variables follow exactly the same syntax as declaration of user defined type variables in ExpL. <b>The member fields of a class must be declared before member functions are declared.</b> Class definitions must be placed after type definitions, but before global declarations. (Further example programs are provided at the end).
</p>
<p>
Since OExpL is designed for pedegogical purposes, the following restrictions are imposed to simplify implementation.
<ol type="a">
<li>
<b>The member fields of a class may be of type integer, string, user defined types, previously defined classes or of the same class.</b> Thus the language supports both<a href="https://en.wikipedia.org/wiki/Composition_over_inheritance" target="_blank"><i> Composition and Inheritance.</i></a>
</li>
<li>
<b>Member fields of a class are private to the class</b> in the sense that they can be accessed only by the methods defined in the class. The language does not permit <i>access modifiers</i> like <a href="https://en.wikipedia.org/wiki/Access_modifiers" target="_blank"><b>public</b> or <b>protected</b>.</a>
</li>
<li>
<b>Class variables can be declared only globally. Class variables cannot be arguments to functions; a function cannot have a class as its return type</b> and class variables cannot occur as local variables within functions.
<!--(Exercises in the <a href="http://silcnitc.github.io/roadmap.html" target="_blank">roadmap</a> extends the language by dropping some of these restrictions).-->
</li>
<li> All the member fields and methods should be declared between <i>decl</i> and <i>enddecl</i>. </li>
<li>
In methods defined within a class, the special keyword <b>self</b> refers to the instance of the class through which the method was invoked. ( The usage is similar in spirit to <a href="https://en.wikipedia.org/wiki/This_(computer_programming)" target="_blank"><b>this</b> in C++.</a> )
</li>
<li>
The methods defined in a class may have parameters as well as local variables. The syntax and semantics rules are similar to other ExpL functions.
However, there are some important differences:
<p>
a) <b>Methods</b> of a class, apart from its arguments and local variables,<b> have access only to the member fields of the corresponding class.</b>
<br>
b) <b>A method can invoke only functions of the same class or functions inherited from its parent class or methods of class variables occuring as member fields of the class. </b> <!-- However, <b> recursive calls to the same function are permitted.</b>-->
(Be aware of the <a href="https://en.wikipedia.org/wiki/Fragile_base_class" target="_blank"> <i>fragile base class problem</i></a>).
</p>
</li>
</ol>
</p>
<p>
</p>
<p>
To put in short
<ol type="a">
<li>
class variables can only be global.
</li>
<li>
Member functions of a class can access only its member fields, methods, local variables, arguments and methods of member fields.
</li>
<li>
Member fields of a class can be accessed from outside only through member functions of the class.
</li>
</ol>
<p>
</article>
<article class="grid col-full" id="nav-inheritance">
<h2>Inheritance</h2>
<p>
The language supports class<b> extension</b>. A class defined by extension of another class is called a <i>derived class</i> (or <i>child class</i>) of the <i>parent class</i> (sometimes called the <i>base class</i>). The following example demonstrates the syntax of class extension. The language does not support<a href="https://en.wikipedia.org/wiki/Multiple_inheritance" target="_blank"> multiple inheritance </a> .
</p>
<script src="../js/6a973317f3e10937b42981b2147be063.js"></script>
<p>
The semantics of class extension can be summarized as follows:
<ol>
<li>
<b>The derived class inherits all member fields of the parent class automatically. </b> If additional fields are defined, they will be specific to the derived class. <b>The derived class cannot re-declare a member field already declared in the parent class.</b>
</li>
<li>
<b>The derived class inherits only those methods of the parent class which are not re-defined (overridden).</b> If a method is overridden, the new definition will be the only valid definition for the derived class. All the overridden methods must be declared again in the derived class. <b>The signature of the overridden method must match exactly in both number and types of arguments with the signature of the function in the parent class.
</b> Only one function of the same name is permitted in a class. Thus, the language does <b>not</b> permit <a href=" https://en.wikipedia.org/wiki/Function_overloading" target="_blank">function overloading</a>.
</li>
</ol>
</p>
</article>
<article class="grid col-full" id="nav-class-variables-and-instantiation">
<h2>Class variables and Instantiation</h2>
<p>
Class variables are declared just like other variables in the global declaration section after type definitions and class definitions.
</p>
<p>
Example:
<script src="../js/406d14fb431de1b8d5cb3fb517a3c271.js"></script>
</p>
<p>
Object instance is created for a variable of a class with the built-in function <i>new</i>. The language does not support <a href="https://en.wikipedia.org/wiki/Constructor_(object-oriented_programming" target="_blank">constructors and destructors</a>. Hence intitialization of objects has to be done explicitly. An object can be deallocated using the built-in function <i>delete</i>. The function <i>new</i> will create an object of a specified class at run time, and assigns a <i>reference</i> to the object into a variable. A variable of a given class may be assigned a reference to an object of any desendent class using <i>new</i>. Access semantics of class variables is similar to ExpL user-defined-types, except for the details associated with methods defined within classes. These details are described below.
</p>
</article>
<article class="grid col-full" id="nav-subtype-polymorphism">
<h2>Subtype Polymorphism</h2>
<p>
<b>A variable of a parent class can refer to any object in its inheritance hierarchy.</b> That is, if class B extends class A and class C extends class B, then a variable of class A can refer to objects of classes A, B or C, whereas a variable of class B can refer to any object of class B or C. (References are set using the ExpL <i>assignment statement</i> in the normal way, as with user defined types. The function <i><b> new </b></i> can also be used to set the reference for a variable). When a method is invoked with a variable of class B or C, if the method is inherited from an ancestor class, the ancestor's method is invoked. This is illustrated by the following examples.
</p>
<p>
<script src="../js/23c82bb7f80ddc45cbf8f968b53a2bf3.js"></script>
</p>
</article>
<article class="grid col-full" id="nav-run-time-binding">
<h2> Run time Binding</h2>
<p>
Suppose that a variable declared to be of a parent class in an inheritance hierarchy holds the reference to an instance of a derived class. On invocation of a method of the parent class variable, if the method is over-ridden by the derived class, the method of the derived class is invoked.
</p>
<p>
This pivotal feature of object oriented programming compilcates the compiler implementation because<b> at the time of generating code for a method invocation, the correct method to call may not be known,</b> as illustrated in the example below.
</p>
<p>
<script src="../js/9271df4a7c12014d200ead3692452291.js"></script>
</p>
<p>
In the above code, the value of the variable n read from the input at run-time determines whether the variable <i>arbitrary</i> refers to an object of the class - person or the class - student. Consequently, at compile time, we cannot decide whether the call <i>arbitrary.printDetails()</i> must be translated to an invocation of the function in the parent class or the child class.
</p>
<p>
To resolve such function invocations, the method of <a href="https://en.wikipedia.org/wiki/Late_binding" target="_blank">dynamic binding</a> must be implemented using the <a href="https://en.wikipedia.org/wiki/Virtual_method_table" target="_blank">The virtual function table method</a> .A tutorial explaining the implementation of virtual function tables is given <a href="http://silcnitc.github.io/oexpl-run-data-structures.html" target="_blank"> here </a>.
</p>
<!--- <p>
<b>Note:</b> The project road-map permits a program to be split into multiple class files that can be compiled seprately into object files and build together. In the present documentation, we ignore this feature.
</p> -->
<p>
<b> Important Note : </b>
If a variable of a parent class holds the reference to an object of a descendent class, only
methods defined in the parent class are allowed to be invoked using the variable of the parent class.
</p>
</article>
<article class="grid col-full" id="nav-sample-programs">
<h2>Sample Programs</h2>
<p>
Example Programs are <a href = "oexpl-testprograms.html" target="_blank">here</a>.
</p>
</article>
<article class="grid col-full" id="nav-appendix">
<h2>Appendix</h2>
<h4>Keywords</h4>
<p>The following are the reserved keywords in OExpL and it cannot be used as identifiers.</p>
<table style="width:80%;text-align:center;">
<tbody>
<tr>
<td>class</td>
<td>endclass</td>
<td>extends</td>
<td>new</td>
<td>delete</td>
<td>self</td>
</tr>
<!--<tr>
<td>endif</td>
<td>do</td>
<td>endwhile</td>
<td>break</td>
<td>while</td>
<td>end</td>
</tr>
<tr>
<td>int</td>
<td>str</td>
<td>return</td>
<td>decl</td>
<td>enddecl</td>
<td>alloc</td>
</tr>
<tr>
<td>type</td>
<td>endtype</td>
<td>NULL</td>
<td>continue</td>
<td>main</td>
<td>free</td>
</tr>-->
</tbody>
</table>
<!--<br/>
<h4>Operators and Delimiters</h4>
<p>The following are the operators and delimiters in ExpL</p>
<table style="width:80%;text-align:center;">
<tbody>
<tr>
<td>></td>
<td><</td>
<td>>=</td>
<td><=</td>
<td>!=</td>
<td>==</td>
<td>(</td>
<td>)</td>
</tr>
<tr>
<td>{</td>
<td>}</td>
<td>[</td>
<td>]</td>
<td>/</td>
<td>;</td>
<td>*</td>
<td>=</td>
</tr>
<tr>
<td>+</td>
<td>-</td>
<td>%</td>
<td>AND</td>
<td>NOT</td>
<td>OR</td>
<td>.</td>
</tr>
</tbody>
</table>
<br/>
<h4 id="expl-identifiers">Identifiers</h4>
<p>Identifiers are names of variables and user-defined functions. Identifiers should start with an letter, and may contain both letters and digits. Special characters are not allowed in identifiers.</p>
<p style="text-indent: 5em;">letter -> [a-z]|[A-Z]</p>
<p style="text-indent: 5em;">digit -> [0-9]</p>
<p style="text-indent: 5em;">identifier -> (letter)(letter | digit)*</p>
<br/>
-->
</article>
</div>
</section>
<hr>
<footer class="center part clearfix">
<ul class="grid col-one-third social">
<li><a href="http://github.com/silcnitc">Github</a></li>
<li> <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">
<img alt="Creative Commons License" style="border-width:0" src="img/creativecommons.png" /></a></li>
</ul>
<div class="grid col-one-third" style="color:black;">
<p style="font-weight: bold;">Contributed By : <a> Muralikrishnan K. </a>
</p>
</div>
<nav class="grid col-one-third ">
<ul >
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<!-- <li><a href="uc.html">Contact</a></li> -->
</ul>
</nav>
<br>
</footer>
<script>window.jQuery || document.write('<script src="js/jquery-1.7.2.min.js"><\/script>')</script>
<script src="js/scripts.js"></script>
<script src="js/inject.js"></script>
</body>
</html>