Stage 11
ExPL Language
Primitive Data Types
int a, b, c;
str mystring;
int a[10];
str stringlist[10];
User Defined Types
- These types must be allocated dynamically.
mytype {
int a;
str b;
}
mytype var1, var2;
var = alloc();
var.a = 10;
retval = free(val);
General Program Structure
- Type Definitions - (For user defined)
- Global Declarations
- Functional Definitions
Type Definitions
type
linkedlist {
int data;
linkedlist next;
}
marklist{
str name;
linkedlist marks;
}
endtype
// global declarations
// functions
Global Declarations
- Begins with decl keyword and ends with keyword enddecl.
- string, integer or user defined type.
- Only single dimensional arrays are allowed.
- Values cannot be assigned during this phase.
- Every function except main must be declared before it is used. This is known as Forward Declaration (So that the compiler gets to know about the signature beforehand)
- Parameter Passing - Copy-by-Value and Copy-by-Reference
- Arrays cannot be passed as the parameters (must be globally)
- ExPL allows you to group different kinds of entities of same type (variables, arrays and functions)
str t, q[10], f3(str x)
Function Definitions and the Main function
int fun(int a, int b)
{
decl
int c, d;
enddecl
begin
c = a + b;
d = a - b;
write(c);
write(d);
return c;
end
}
- Assignment Statement
- Conditional Statement
- Iterative statement
- Return statement
- Input/Output statements
- Break statement
- Continue statement
Statements and Expressions
- integer or quoted string
- NULL is allowed
Arithmetic and String Expressions
- +,-,*,/,%
- Eg. 5, a[a[5+x]]+x , (f2() + b[x] + 5), sum + listObject.data , a[listObject.data] + f2(listObject) * 8
Conditional Statement
if < Logical Expression > then
Statements
else
Statements
endif;
Iterative Statement
while < Logical Expression > do
Statements
endwhile;
Breakpoint Statement
breakpoint;
Dynamic memory Allocation
intialize();
t = alloc();
retval = free(t); -> should return NULL
Parameter Passing
type
node {
int x;
}
endtype
decl
node fun(node t);
enddecl
node fun(node t) {
begin
t.x = 3;
t = null;
return t;
end
}
. Visualizing the Stack vs Heap
Imagine r is a piece of paper in main's pocket that has the address "123 Heap Street" written on it.
-
When you call
fun(r), you givefuna copy of that paper. Nowfunhas a piece of paper (t) that also says "123 Heap Street". -
fungoes to "123 Heap Street" and paints the door red (t.x = 3). -
Then,
funtakes its copy of the paper and scribbles it out (t = null). -
When you go back to
main,mainstill has its original piece of paper (r) that says "123 Heap Street", and the door at that house is still red.
High Level Library Interface
t = exposcall(fun_code, arg1, arg2, arg3)
(https://exposnitc.github.io/os_spec-files/dynamicmemoryroutines.html)
The libary.lib occupies two pages of disk (13,14) and resides in (63,64)
Important
For any library implementation, remember to save to context of the used registers before call the interrupt
CALL is used for subroutines, but INT is used for interrupt handlers, for library - CALL 0