(A) - Ada+SQL - An Overview
(A) - Ada+SQL - An Overview
Arthur V. L o p e s
Universidade Luterana do Brasil
Rua Inhandui 303, Ap. 204
90.820-170 Porto Alegre, FIS -
BRAZIL
+55 (51) 241 3903
avl @ z a z . c o m . b r
re,w _ _ . _
...............................
m
llilllll-ll
....... II1 .......... I1 ......................................................................................................................................................................................
mx I
m m E,. SQL Teems Library .Q.ptien, T e m p l a t e ,
Edit muad Decumentatien V4indew Help F:I-dFI[~
with &~bs.T~xt_IO; u~ Ada. Text_ZO~ m
proc~sdu~ Ada__SQL_Ew~xpl~ is
~ i n
~eN~t~ table Students
(Id (Long_Intogmr)
,Cour~o_Id (Integer)
.Sex (Character)
,Nax~ (String(l..30)));
insert into Studonts(10101998, I010, 'M' , " M o n i t z Taxaguizo" ):
in~rt into Students(10201998, 1010, 'F', "E1iea Cruzetaizen");
alter
~le=t
table
~ from Stud~nte
Studsnte add GPA (Float):
order by Nax~ aeoendin~; |
~nd &da__~Exa~ple; v
157
One editing window shows an Ada program that uses SQL SQL create command has been extended with Ada 95 types.
commands. As c a n be seen the Ada 95 programming The program output for figure 1 is shown in figure 2.
language has been extended with SQL commands and the
Figure 2 - O u t p u t of P r o g r a m Ada_SQL_Example
This allows the user to either write Ada code intermixed set of SQL commands interactively from the PE.
with SQL commands, as shown in figure 1, or to execute a
~1 Com,n,m~
-C.iimind (s } - ,
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . I
!
. . . . . . . . . . . . . .
i
|
[
• I I
. . . . . . . . . . . . . . . . . . . . lrmul- . . . . . . . .
158
These syntax templates are available to assit novice generic unit components making text replacements among
programmers to code basic SOL commands. There are a set generic formal parameters and generic actual parameters.
of 60 Ada 95 syntax templates dialog boxes to assit novice Internal code generated is associated with information on
programmers to code the language constructs. both source file and line number that originated each
instruction (see figure 7). When either a compile or run-
4. COMPILER STRUCTURE time error is detected this information is used to report the
Compiler components include the usual basic modules such exact error location. The SQL select command was
that scanner, parser, symbol table management, error extended to allow, as an option, the inclusion of a block
handling, and intermediate code generation. Besides these statement. Each time a select command retrieves data, that
components a library module keeps track of source files and satisfy a where clause when present, the block statement is
the program units they contain. The library manager tells executed.
the compiler the source file that contains a given program
t,nit such that a package. A source file may contain any 4.3 Symbol Table
number of program units. For instance, when a compilation The symbol table uses a nested hash table scheme. Each
A finds a with clause that refers to a package P, the compiler instance contains a global hash table. Program
compilation makes a pause with the current source file, a. A units such that packages, main programs and SQL tables are
new compilation, B, is started to process source file, b, common entries within this scope. These types of entries
which contains package P. When compilation B concludes, have descendant hash tables. For instance, a descendant
then compilation A resumes now accumulating the program hash table for a procedure will contain all elements that
units stored in source files b and partially a. Therefore, no belong to its declarative part. Figure 6 shows the symbol
intermediate code is ever stored. Only source code is used. table representation considering the compilation for the
4.1 Scanner code fragment within figure 5. An outer square represents a
scope. Each scope contains 20 fields. Only two of these
Lexical analysis operates mostly under parser's conlrol.
fields are being shown: the father and the bucket vector.
Some subprograms belonging to predefined packages also
The father field stores a pointer to the ancestor scope. Each
use some scanner operations at run-time. To increase
bucket entry points to a linked list of table entries that share
compiler speed, the entire source file is read into a memory
buffer by one low-level input system call. A token look- the same hash value. Figure 6-(a) shows the entries Ada and
ST. A full symbol table entry contains 65 fields from which
ahead buffer of varying length is used to provide the parser
many are pointers into other data structures. Only two of
with a means of inspecting the source code in order to
these fields are being shown:/d and son. The id field stores
identify specific language constructs. Examples of such
the characters that represent the symbol. Names, all forms
constructs are aggregates and SQL commands. The use of
of literals and temporaries are common symbol table
context clauses and generic units cause the parser to switch
its focus among a number of source files. Subprograms that entries. The son field stores a pointer into its descendant
store all scanner information into its local storage are used scope for entries like packages subprograms and records.
to deal with this problem. The scanner parameters are then Figure 6-(b) shows the descendant scope for procedure ST.
initialized with the information needed to compile the new Figure 6-(c) shows the descendant scope for package Ada.
coming compilation and the parser is then called to act on Experiments have shown that this structure is responsible
for part of the compiler speed.
it. When the parser returns these subprograms restore the
scanner information with the previously saved local storage w~:h Ada.Text_IO; u e e Acla.Text_IO;
allowing the parser to resume its work with the source file pEOC~Et ST ~S
that caused this type of action. ~=yIMn Date As .t'm~O~l.
Month : Integer;
4.2 Parser Day : Integer;
Syntax analysis is performed by a recursive descendant
parser (k) where k stands for any number of look-ahead
tokens. As pointed out before, language constructs such as
Year : Integer;
aggregates and SQL commands require a number of look-
a n d z~=ozdl
ahead tokens in order to be identified properly. SQL
commands are parsed by context. SQL commands may be f u m a t L o m Fat (N : Integer)
also coded anywhere an Ada statement is allowed. As zotuxm Long_Integer is
mentioned before, instantiation of generic units cause the 1~gLn
parser to save the scanner state and redirect its input to the Figure 5 - Fragment of an Ada 95 Program
159
father
^ I Ud eaR Son
Ada
//
~ f a t h e
Id ... So~ father
Id
/1"--'°1
... Son
I-I-
bucl~
Fat
i /
(~
bucket bucket
0o) (c)
Figure 6 - Partial Symbol Table Representation
Pre-defined package specifications are only stored within Examples of three operand instructions are related to the
the symbol table when refereed. first, last, length and range attributes. Four operand
instructions are used to implement SQL constructs such as
4.4 Error Handling the one shown in figure 8, part (b). Inslruction number 48
A simple sUrategy is used for dealing with errors. Once an shows an intermediate instruction that implements the
error is detected it is reported and the compiler terminates. where clause shown in part (a),
Over one thousand messages are used in both English and
Hn~*- 16 ~lJ g Eil,* L6 Ei~,a, 32 Ba,J
Portuguese. Two external programs are used to format and
display the error messages.
160
select ~ from Grades where ~s ~e no~ in ("AP", "IN" ) ;
(a) Select C o m m a n d
Inst,uc~on#
/ Souzce file#
//.__-. Source line#
44 0 ? I_SOL_OPEN_WRITE $Select I 724168
45 0 7 I SQL SELECT START NOTAS $Index GRADES 1
46 0 ? I SQL_EOF $ Index_GRADES_I g o t o 60
47 0 7 I_SQL_READ H O T A S $'rndex G R A D E S .1 m
48 0 7 I_SQL_IS_IN_SET O B S $ S Q L S E T IS I N 1 $ S Q L SET is in 1 1
49 0 7 I SQL NOT $ S Q L S E T is i n 1 g o ~ o 5 8
50 0 7 I_SQL ADD_ONE $Select: I
Q I |
57 O ? I_SQL_MRITE $Selec~ 1
58 0 7 Z_SQL._NEXT GRADES $1ndex GRADES 1
59 0 7 I DIRECTGOTO 46
(b) Intermediate Code
Figure g - Intermediate Instructions
4.6 Graphics disk files with special headers that contain information on
Basic two-dimensional graphics allows the following tuple utilization.
operations: window creation and des.laction, line. text~
6. Aria 95 & SQL CONSTRUCTS
pixel, ellipse and circle. It uses the Windows MFC CDialog
Most core conslructs of Ada 95 are operational. Variant
and CDC classes from a console application. Other
parts, access to subprogram definition, dynamic
complementary MPC classes are also used. These resources
dispa¢l~ng, abstract types and subprograms, named array
and related types are accessed from Ada programs by using
aggregates, user-defined assignment and finalization,
the implementation-defined package Windows_2D.
requeue statements, asynchronous "ansfer of control,
5. INTERPRETER shared variables, praginas and a number of attributes are
The symbol table and the intermediate code represent any cons~'uets under implementation.
set of compiled program units. This representation together SQL commands available are create, insert, update, select,
with a non empty set of run-time stacks are used by the delete, alter and drop.
Ada+SQL abstract machine which is implemented by an
interpreter. Each task and protected units have their own 7. DOCUMENTATION
stack. The tasking model implementation uses a round Full hypertext documentation is provided on the
robing scheduler. The user can change the quantum as a environment, the Ada 95 Referenc~ Manual V. 6.0, SQL. In
way of experimenting different concurrent program addition, a tutorial on basic Ada 95 is also provided. The
behavior. When a dead state is detected among a set of E95.I-ILP compressed file is accessed from within the PE
tasks these tasks are placed in the abnormal state and the and also fTom the winhelp utility program.
exception Tasking_Error is raised. The stack model is used
8. PERFORMANCE
as the run time storage management strategy. Two
Running the compiler/interpreter on a COMPAQ Presario
exceptions are the allocation of dynamic memory, requested
300MHz under Windows 98 with 502 Ada source files,
explicitly by the programmer, and the occurrence of
where some sources contain more than one program unit,
unconstrained arrays. For instance, the bounds of an
with a total of 61,000 LOC.s takes less than two minutes to
unconstrained array declared within a subprogram may be
compile and interprete. A few of these programs use delay
taken from parameters. Only when such subprogram is
statements which increased the overall elapsed time.
executed the array storage area is allocated. These arrays
make use of descriptors that point to memory allocated 9. CONCLUSIONS AND FUTURE WORK
from the heap. Special memory controls are used to avoid Ada+SQL has been used as a tool to assist novice
memory leaks when a block containing such arrays leaves programmers enrolled in Data Smlcmres and Concurrency
the stack. Aria 95 and SQL commands are interpreted as the classes for several years at undergrsduate CS programs in
same level. The current version treats tables as independent the "Universidade Luterana do Brasil" located in the cities
161
of Canoas and Gravataf both within the state of Rio Grande [ l l ] A d a 95 Rationale - The Language - The Standard
do Sul, Brazil. Students' reactions indicate that Ada+SQL Libraries. Intermetrics, Inc., Cambridge, Ma, 1995.
has been helpful to them. Future work will continue to [ 12] Bacon, J. Concurrent Systems, Addison-Wesley, 1996.
implement additional Ada 95 and SQL consu'ucts as well as
improving the PE. Special attention is being given to [13]Ben-Ari, M. Principles od Concurrent Programming,
incorporate some Visual Basic features that could make its Prentice-Hall, 1982.
usage easier as well as CGI capability. Version 3.0 of [14]Cormen, T. H. et al. InUroduetion to Algorithms. 15 ed.
Ada+SQL will be distributed upon request for a limited McGraw-Hill, 1995.
period of time. [15]Aho, A.V. et al. Data Structures and Algorithms, 28 ed.
10. REFERENCES Addison-Wesley, 1987.
[1] Hawryszkiewycz, I. T. Database Analysis and Design. [16]Aho, A.V., Sethi, R. and Ullman, J. D. Compilers,
Science Research Associates, 1984. Principles, Techniques, and Tools. Addison Wesley,
[2] Bradley, J. File. Data Base Techniques. CBS College 1985.
Publishing, 1982. [17]Aho A. and Ullman, J. D. The Theory of Parsing,
[3] Date, C. J. An Introduction to Database Systems. Translation and Compiling. Prentice-Hall, 1972.
Addison Wesley, 1977. [18] CJries, D. Compiler Conslruction for Digital
[4] Date, C. J. and Darwen, Hugh. A Guide To Sql Computers. John Wiley & Sons, 1971.
Standard. Addison Wesley, 1996. [19]Fisher, C. N. and LeBlanc, R. J. Crafting a Compiler.
[5] Ladanyi, H. Sql Unleashed; The Comprehensive Benjamin Cummings, 1988.
Solutions Package With Cdrom. Sams, 1997. [20] Hopcroft, J. D., Ullman, J. D. Introduction to Automata
[6] Lopes, Arthur V. '2ntrodu~o ~t Programaf~o coin Ada Theory, Languages and Computation. Addison Wesley,
95," Ed. ULB R.A, 1997. 1979.
[7] Lopes, Arthur V. "Estruturas de Dados para [21]Harvey, T. J. and Cooper, K. D. Compiler-Controled
Constru~o de Software," Volume 1 - "Nfvel B~ico," Memory. In Proceedings of the 8th International
Ed. ULBRA, 1999. Conference on Architectural Support for Programming
[8] Lopes, Arthur V. "Estruturas de Dados para Languages and Operating Systems, San Jose, October
ConstruqAo de Software," Volume 2 - "Nfvel 1998, pp. 2-11, volume 33, number 10. ACM Press,
Intermedi(trio," Ed. ULBRA, 1999. 1998.
[9] Freeze, Wayne. The Sql Programmer's Reference, With [22] Sebesta, R. W., Concepts of Programming
Cd. Ventana Press, 1998. Languages,3" Ed. Addison-Wesley, 1996.
[10] Ada 95 Reference Manual. Intermetrics, Inc.,
Cambridge, Ma, 1995. ANSIfISO-8652:1995.
162