You are on page 1of 25

BABULAL TARABAI INSTITUTE OF RESEARCH & TECHNOLOGY,

SAGAR(M.P.)

SESSION DEC 2021-22

DEPARMENT OF COMPUTER SCIENCE & ENGINEERING


MCSE-207

Lab-IV [MCSE-203(ADBMS) & MCSE-204(SP)]

Submitted To Submitted By
Department of CSE Suyash Vishwakarma

vsuyash165@gmail.com

0608CS21MT18

Mtech-CSE 2nd SEM

Experiment No. - 01
Introduction of system programming and its components.

The dictionary definition of a system is “a set of things working together as parts of a mechanism
or an interconnecting network.” This is a pretty apt way of thinking about systems as they pertain
specifically to the IT world. A computer system is a collection of components (both hardware and
software) that function as a part of a whole.

A system is comprised of five primary elements: architecture, modules, components, interfaces, and
data.

Systems design involves defining each element of a system and how each component fits into the
system architecture. System designers focus on top-level concepts for how each component should
be incorporated into the final product. They accomplish this primarily through the use of Unified
Modeling Language (UML) and flow charts that give a graphical overview of how each component
is linked within the system.

Systems programming involves the development of the individual pieces of software that allow the
entire system to function as a single unit. Systems programming involves many layers such as the
operating system (OS), firmware, and the development environment.

Components of system programming are:

1) Loader

2) Assembler

3) Compiler

4) Macro

5) Interpreter

1) Loader: Loader plays an important role in system programming. It palaces the program in the main memory
and prepare it for execution. Loading program means reading contents of executable file and loading program in
the memory and then carryout tasks and prepare them for running, as the loading is complete the operating
system starts the program execution by passing control to program code.

2) Assembler: An assembler is used to convert assembly language program into machine level language.
Assembler provides access to Software and Application developers to manage computer hardware and its
components. Assembler act as a compiler of assembly language program.
3) Compiler: A Compiler is program used to convert high level programming language to low level
programming language. Compilers are a type of translator that translates digital devices and computer
languages.

Further compiler is divided into two types:-

i) Cross Compiler: A cross compiler is a compiler which is capable of generating an executable code
for other platform where it resides on another platform.
ii) Source to Source Compiler: A source to source compiler accepts an input written in one
programming language and produces output for same written in another language.

4) Macro A macro is a single line abbreviation for group of statements or block of code. Macro allows
programmer to write the short part of the program. A macro can be expanded into no. of instructions.

5) Interpreter In System Programming interpreter is a program which directly executes the program without
compiling it to the machine language.

Experiment No - 02
To write a program to generate the symbol table for the given assembly
language.
1. Starting symtabtest.cc...
2. Inside p2:
3. symbol:
4. id: c
5. type: INTEGER
6. level: 3
7. hash_link: 15
8. back_link: 99
9. offset: 0
10. tag: SYM_VAR
11. class: variable_symbol
12.
13. symbol:
14. id: b
15. type: REAL
16. level: 2
17. hash_link: 11
18. back_link: 98
19. offset: 0
20. tag: SYM_VAR
21. class: variable_symbol
22.
23. symbol:
24. id: a
25. type: INTEGER
26. level: 1
27. hash_link: -1
28. back_link: 97
29. offset: 0
30. tag: SYM_VAR
31. class: variable_symbol
32.
33. Inside p1:
34. symbol:
35. id: c
36. type: REAL
37. level: 2
38. hash_link: 12
39. back_link: 99
40. offset: 8
41. tag: SYM_VAR
42. class: variable_symbol
43.
44. symbol:
45. id: b
46. type: REAL
47. level: 2
48. hash_link: 11
49. back_link: 98
50. offset: 0
51. tag: SYM_VAR
52. class: variable_symbol
53.
54. symbol:
55. id: a
56. type: INTEGER
57. level: 1
58. hash_link: -1
59. back_link: 97
60. offset: 0
61. tag: SYM_VAR
62. class: variable_symbol
63.
64. 7GLOBAL.4VOID7INTEGER4REAL4READ5WRITE7INT-ARG5TRUNC8REAL-ARG4prog1a1b1c2p11b1c2p21c
65. -----------------------------------------------------------------------------------^ (pool_pos = 83)
66.
67. Symbol table (size = 17):
68. Pos Name Lev Hash Back Offs Type Tag
69. -----------------------------------------------
70. 0: GLOBAL. 0 -1 159 0 GLOBAL. SYM_PROC lbl = -1 ar_size = 0
71. 1: VOID 0 -1 82 0 VOID SYM_NAMETYPE
72. 2: INTEGER 0 -1 462 0 VOID SYM_NAMETYPE
73. 3: REAL 0 -1 324 0 VOID SYM_NAMETYPE
74. 4: READ 0 -1 316 0 INTEGER SYM_FUNC lbl = 0 ar_size = 0
75. 5: WRITE 0 -1 139 0 VOID SYM_PROC lbl = 1 ar_size = 0
76. 6: INT-ARG 0 -1 210 0 INTEGER SYM_PARAM
77. 7: TRUNC 0 -1 332 0 INTEGER SYM_FUNC lbl = 2 ar_size = 0
78. 8: REAL-ARG 0 -1 427 0 REAL SYM_PARAM
79. 9: prog 0 -1 24 0 VOID SYM_PROC lbl = 3 ar_size = 24
80. 10: a 1 -1 97 0 INTEGER SYM_VAR
81. 11: b 1 -1 98 8 INTEGER SYM_VAR
82. 12: c 1 -1 99 16 INTEGER SYM_VAR
83. 13: p1 1 -1 161 0 VOID SYM_PROC lbl = 4 ar_size = 16
84. 14: b 2 -1 98 0 REAL SYM_VAR
85. 15: c 2 -1 99 8 REAL SYM_VAR
86. 16: p2 2 -1 162 0 VOID SYM_PROC lbl = 5 ar_size = 8
87. 17: c 3 -1 99 0 INTEGER SYM_VAR
88. ENDING TEST PROGRAM RUN -----------------------------

Experiment No. - 03
Write a program to create symbol table for a given high-level language
program.

// C++ program to implement Symbol Table


// C++ program to implement Symbol Table
#include <iostream>
using namespace std;

const int MAX = 100;

class Node {

string identifier, scope, type;


int lineNo;
Node* next;

public:
Node()
{
next = NULL;
}

Node(string key, string value, string type, int lineNo)


{
this->identifier = key;
this->scope = value;
this->type = type;
this->lineNo = lineNo;
next = NULL;
}

void print()
{
cout << "Identifier's Name:" << identifier
<< "\nType:" << type
<< "\nScope: " << scope
<< "\nLine Number: " << lineNo << endl;
}
friend class SymbolTable;
};

class SymbolTable {
Node* head[MAX];

public:
SymbolTable()
{
for (int i = 0; i < MAX; i++)
head[i] = NULL;
}

int hashf(string id); // hash function


bool insert(string id, string scope,
string Type, int lineno);

string find(string id);

bool deleteRecord(string id);

bool modify(string id, string scope,


string Type, int lineno);
};

// Function to modify an identifier


bool SymbolTable::modify(string id, string s,
string t, int l)
{
int index = hashf(id);
Node* start = head[index];

if (start == NULL)
return "-1";

while (start != NULL) {


if (start->identifier == id) {
start->scope = s;
start->type = t;
start->lineNo = l;
return true;
}
start = start->next;
}

return false; // id not found


}

// Function to delete an identifier


bool SymbolTable::deleteRecord(string id)
{
int index = hashf(id);
Node* tmp = head[index];
Node* par = head[index];

// no identifier is present at that index


if (tmp == NULL) {
return false;
}
// only one identifier is present
if (tmp->identifier == id && tmp->next == NULL) {
tmp->next = NULL;
delete tmp;
return true;
}

while (tmp->identifier != id && tmp->next != NULL) {


par = tmp;
tmp = tmp->next;
}
if (tmp->identifier == id && tmp->next != NULL) {
par->next = tmp->next;
tmp->next = NULL;
delete tmp;
return true;
}

// delete at the end


else {
par->next = NULL;
tmp->next = NULL;
delete tmp;
return true;
}
return false;
}

// Function to find an identifier


string SymbolTable::find(string id)
{
int index = hashf(id);
Node* start = head[index];

if (start == NULL)
return "-1";

while (start != NULL) {

if (start->identifier == id) {
start->print();
return start->scope;
}

start = start->next;
}

return "-1"; // not found


}

// Function to insert an identifier


bool SymbolTable::insert(string id, string scope,
string Type, int lineno)
{
int index = hashf(id);
Node* p = new Node(id, scope, Type, lineno);

if (head[index] == NULL) {
head[index] = p;
cout << "\n"
<< id << " inserted";

return true;
}

else {
Node* start = head[index];
while (start->next != NULL)
start = start->next;

start->next = p;
cout << "\n"
<< id << " inserted";

return true;
}

return false;
}

int SymbolTable::hashf(string id)


{
int asciiSum = 0;

for (int i = 0; i < id.length(); i++) {


asciiSum = asciiSum + id[i];
}

return (asciiSum % 100);


}

// Driver code
int main()
{
SymbolTable st;
string check;
cout << "**** SYMBOL_TABLE ****\n";

// insert 'if'
if (st.insert("if", "local", "keyword", 4))
cout << " -successfully";
else
cout << "\nFailed to insert.\n";

// insert 'number'
if (st.insert("number", "global", "variable", 2))
cout << " -successfully\n\n";
else
cout << "\nFailed to insert\n";
// find 'if'
check = st.find("if");
if (check != "-1")
cout << "Identifier Is present\n";
else
cout << "\nIdentifier Not Present\n";

// delete 'if'
if (st.deleteRecord("if"))
cout << "if Identifier is deleted\n";
else
cout << "\nFailed to delete\n";

// modify 'number'
if (st.modify("number", "global", "variable", 3))
cout << "\nNumber Identifier updated\n";

// find and print 'number'


check = st.find("number");
if (check != "-1")
cout << "Identifier Is present\n";
else
cout << "\nIdentifier Not Present";

return 0;
}
Experiment No. – 04

Exploring various features of debug command and also use of LAX and
YACC tools.

Lexical Analyzer

Algorithm:
Step 1: Start Step 2: Read the file and open the file as read mode. Step 3: Read the
string for token identifiers, variables.
Step 4: Take parenthesis also a token.
Step 5: Parse the string
Step 6: Stop
52 ! so rcnp( st r, " st ruct" ) | | ! st rcnp( st r, "goto" ) )
53 return ( t rue ) , |
54 retu rn T false) ;
55 }
56
57 // Returns 'true' if the strinj is an INTEGER.
58 book isInIeger(char* str)
59
60 int i, ten = str{en(str),
61
62 if (ten 0)
63 return ( fa 1se ) ;
64 for ( 1 = 6 ; 1 < ten; 1++) ¿
65 if (st r [1] != ' 0 ' 66 st r [1] != ' 1 ' 66 st r [1] != ' 2 '
66 66 st r [1] != ' 3 ' 66 st r [1] != ' 4 ' 6A st r [1] != ' 5 '
67 66 st r [ 1] != ' 6 ' 66 sI r [ 1] != ' 7 ' &A st r [1] != '8'
68 66 st r [1] != ' 9 ' | | ( st r [ 1] == ' — ' GA 1 > 6) )
69 return ( la 1se ) ;
70
71 return ltrue),
72
73
74 // Returns 'true' if the string is a REAL NUMBER.
75 book isRealNumber(char* str)
76
77 int i, len = strIen(str);
78 book hasDecimal = false,
79
80 if (ten 0)
81 return ( fa 1se ) ,
82 for ( 1 = 6 ; 1 < ten; 1++) ¿
83 if (st r [1] != ' 0 ' 66 st r [1] != ' 1 ' 66 st r [1] != ' 2 '
84 66 st r [1] != ' 3 ' 66 st r [1] != ' 4 ' 6A st r [1] != ' 5 '
85 66 st r [ 1] != ' 6 ' 66 sI r [ 1] != ' 7 ' &A st r [1] !='8'
86 66 st r [1] != ' 9 ' 66 st r [1] != ' . ' I I
87 (st r [1] 66 1 > 0) )
88 return (false);
89 If (str[1] ')
9 hasDec1mal I rue ;
91
92 ret u rn ( has Dec 1ma 1 ) ,
93
94
95 // Ext ract s the SUBSTRING.
96 char* subSIring(char* str, int left, int right)
97 {
98 int i;
99 cha re substr = (char*)malloc(
Output:
Experiment No. – 05

Develop a database application to demonstrate storing & retrieving of


BLOB and CLOB object.
Experiment No. – 06

Develop a database application to demonstrate representation of multi


valued attributes and use of nested table to represent complex objects.

Introduction
Attributes (like phone numbers) that are explicitly repeated in a class definition are
not the only design problem that we might have to correct. Suppose that we want to
know what hobbies each person on our contact list is interested in (perhaps to help
us pick birthday or holiday presents). We might add an attribute to hold these. More
likely, someone else has already built the database, and added this attribute without
thinking about it.

The multivalued attribute is obvious in this example as its name is in plural. Be


aware that this won’t always be the case. We can only be sure that there’s a design
problem when we find data in a table as depicted below.
In this case, the hobby attribute wasn’t repeated in the scheme, but there are many
distinct values entered for it in the same column of a row. This is called a
multivalued attribute. The problem with this design is that it is now difficult (but
possible) to search the table for any particular hobby that a person might have, and it
is impossible to create a query that will individually list the hobbies that are shown
in the table. Unlike the phone book example, NULL is probably not part of the
problem here, even if we don’t know the hobbies for everyone in the database.

Using UML Multiplicity for multivalued attributes


In UML, we can again use the multiplicity notation to show that a contact may have
more than one value for hobby.
Mapping to the relational model As you should expect by now,
we can’t represent the multivalued attribute directly in the Contacts relation scheme.
Instead, we will model it using its own relation scheme. Thus, we remove the old
hobbies attribute and create a new scheme, very similar to the one that we created
for phone numbers in the repeated attribute design pattern.
The relationship between Contacts and Hobbies is one-to-many, so we create the
usual pk-fk pair. The new scheme has only one descriptive attribute, the hobby
name. To uniquely identify each row of the table, we need to know both which
contact this hobby belongs to and which hobby it is—so both attributes form the pk
of the scheme.

With data entered, the new table looks similar to the PhoneNumbers. It can also be
joined to Contacts on matching pk-fk contactID pairs, re-creating the original data in
a form that we can now conveniently use for queries.
Experiment No. – 07

Explain E-R model with suitable examples.

ER Model: Entity relationship (ER) models are based on the real-world entities
and their relationships. It is easy for the developers to understand the system by
simply looking at the ER diagram. ER models are normally represented by ER-
diagrams.

Components:
ER diagram basically having three components:
 Entities − It is a real-world thing which can be a person, place, or even a
concept. For Example: Department, Admin, Courses, Teachers, Students,
Building, etc are some of the entities of a School Management System.

 Attributes − An entity which contains a real-world property called an


attribute. For Example: The entity employee has the property like employee
id, salary, age, etc.

 Relationship − Relationship tells how two attributes are related. For


Example: Employee works for a department.
An entity has a real-world property called attribute and
these attributes are defined by a set of values called domain.

Example 1 : -
In a university,
 A student is an entity,
 University is the database,
 Name and age and sex are the attributes.
 The relationships among entities define the logical association between entities.
Example 2 :-

Given below is another example of ER:

In the above example,


Entities − Employee and Department.
Attributes −
 Employee − Name, id, Age, Salary
 Department − Dept_id, Dept_name
The two entities are connected using the relationship. Here, each employee works
for a department.

Features of ER :
The features of ER Model are as follows −
 Graphical Representation is Better Understanding − It is easy and simple
to understand so it can be used by the developers to communicate with the
stakeholders.

 ER Diagram − ER diagrams are used as a visual tool for representing the


model.

 Database Design − This model helps the database designers to build the
database.

Advantages :
The advantages of ER are as follows −
 The ER model is easy to build.
 This model is widely used by database designers for communicating their
ideas.
 This model can easily convert to any other model like network model,
hierarchical model etc.
 It is integrated with the dominant relational model.

Disadvantages :
The disadvantages of ER are as follows −
 There is no industry standard for developing an ER model.
 Information might be lost or hidden in the ER model.
 There is no Data Manipulation Language (DML).
 There is limited relationship representation.
Experiment No. – 08

To study of ORDBMS language Query.

Object oriented Query:

Object Query Language (OQL) is a query language standard for object-oriented


databases modeled after SQL and developed by the Object Data Management
Group (ODMG). Because of its overall complexity the complete OQL standard has
not yet been fully implemented in any software. The OQL standard influenced the
design of later query languages such as JDOQL and EJB QL, though none are
considered to be any version of OQL.

General rules:

The following rules apply to OQL statements:

 All complete statements must be terminated by a semi-colon.


 A list of entries in OQL is usually separated by commas but not terminated by a
comma(,).
 Strings of text are enclosed by matching quotation marks.
Examples:

Simple query:
The following example illustrates how one might retrieve the CPU-speed of all
PCs with more than 64MB of RAM from a fictional PC database:

SELECT pc.cpuspeed
FROM PCs pc
WHERE pc.ram > 64;

Query with grouping and aggregation:


The following example illustrates how one might retrieve the average amount
of RAM on a PC, grouped by manufacturer:

SELECT manufacturer, AVG(SELECT part.pc.ram FROM partition part)


FROM PCs pc
GROUP BY manufacturer: pc.manufacturer;

You might also like