Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 39

PRESIDENCY UNIVERSITY, BENGALURU

A report on
Programming Language: SAW

By:- Respective Faculty


Siddharth (2016CSE362) Mrs. Poornima (Dept. of CSE)

Ashutosh Kumar Sahu (2016CSE399)

Mirza Waris Ali Beigh (2017LCS006)

Page 1 of 39
ABSTRACT

The language in which programs are written can have a substantial effect
on their reliability. This report discusses the design of programming
languages to enhance reliability. It presents several general design
principles, and then applies them to the grammar designed. This language
is based on system programming domain. This is a middle level language as
it as it comprises a combination of both high-level and low-level language
features. This language is statically typed, compiled, general-purpose, not
case-sensitive, free-form programming language that supports procedural,
and generic programming.

Page 2 of 39
Table of Contents

1. Introduction 4

2. Domain 5

3. Comparison of various Programing Languages 6

4. Evaluation Criteria: Requirements and specification 21

5. Data types and structures 22

6. Programming Language Requirement Specification 24

7. Grammar for Programing Language ‘SAW’ 28

8. Test Cases 31

Page 3 of 39
1. INTRODUCTION

In our Programming Language every program begins inside a function called


“main" having a keyword “function” before it. A function is simply a collection
of commands that do "something". The main function is always called when
the program first executes. From main, we can call other functions, whether
they are written by us or use built-in language features.

The function main(). This line tells the compiler that there is a function named
main, The "square brackets" ([ and ]) signal the beginning and end of functions
and other code blocks. Inside the main function we mostly declare the
variables first which has to be used in that program and then continue with
other commands like expressions.

Commonly used functions inside main functions are the out function which is
the standard way of displaying output on the screen. The quotes tell the
compiler that you want to output the literal string as-is (almost). The '\b'
sequence is actually treated as a single character that stands for a newline, just
remember that there are a few sequences that, when they appear in a string
literal, are actually not displayed literally by out and that '\b' is one of them.
The actual effect of '\b' is to move the cursor on your screen to the next line.
You will see that two backslash is used to terminate line in this. Similarly the in
function which is used to take input from external devices such as keyboard.

Finally, at the end of the program, we return a value from main to the
operating system by using the return statement (return[]\\). This return value
is important as it can be used to tell the operating system whether our
program succeeded or not. The final brackets (]) closes off the function.

Page 4 of 39
2. DOMAIN

Our Programming Language falls under “Systems Programming” domain

In the 1960’s and 1970’s system software was used.


The OS & all of the programming support tools of a computer system are
collectively known as its system software. System software is almost used
continuously.

Characteristics: The system software must have the following


a) As it is continuously used it must be efficient.
b) It must have low level features that allow the s/w interface to external
devices to be written
c) It must provide security
Previously Developed Languages are
I) IBM for mainframes developed PL/s , a dialect of PL/I
II) For digital systems BLISS was developed
III) For Burroughs extended ALGOL
IV) Unix OS was written almost in C But it is too dangerous to use C on large
important Systems

Page 5 of 39
3. Comparison of various Programing Languages
3.1. The comparisons based on
1. Statements.
2. Exception handling.
3. Object oriented support.
4. Sub Programs Design and parameter passing techniques

Statements
Pascal Wolfram Mathematica Auto Lisp
 The declarative  The declarative  The declarative
statements: statements: statements:
Each variable in Pascal The Wolfram Language Any variable can
has a specific type, incorporates an extreme form take any LISP
which determines the of the declarative concept, object as its value,
size and layout of the with highly automated super unless you have
variable's memory; the functions for accomplishing declared it
range of values that specified high-level goals. explicitly.
can be stored within  The assignment The type
that memory; and the statement: predicate is used
set of operations that The Wolfram Language's for finding
can be applied to the symbolic architecture supports whether an object
variable. a highly generalized notion of belongs to a
assignment, in which you can specific type.
The name of a variable specify a transformation for
can be composed of any class of expressions  The assignment
letters, digits, and the defined by a Wolfram statement:
underscore character. Language pattern. Simple
It must begin with cases correspond to Def var x 234
either a letter or an assignments for "variables", this is an example
underscore. Pascal is "indexed variables", or of defining a
not case-sensitive, so "structure elements". Other variable in LISP.
uppercase and cases define functions or The value of x gets
lowercase letters mean general transformations. set to 234.
same here. x=v — assign a value (Set)
{x,y}={u,v} — assign multiple  The if statement:
values It can normally be
{x,y}={y,x} — swap values a if statement of
 The assignment  The If Statement: an if statement
statement: If evaluates only the followed by a then
All variables must be argument determined statement,
declared before we use by the value of the If statement:
them in Pascal condition. (if (test-clause)
program. All variable (action1) (action2))
Page 6 of 39
declarations are If [condition,t,f] is left
followed by the var unevaluated if If then statement:
keyword. A declaration condition evaluates to (setq a 10)
specifies a list of neither True nor False. (if (> a 20)
variables, followed by If [condition,t] gives Null if then (format t
a colon (:) and the condition evaluates to False. "~% a is less than
type. Syntax of variable Eg:- abs[x_] := If[x < 0, -x, x] 20"))
declaration is − abs /@ {-1, 0, 1} (format t "~% value
O/P:- of a is
var ~d " a)
variable_list :
 Loops: The if statement works
type;
Looping is a core same as in python and
 The if statement: concept in fortran.
It is a conditional programming. The
statement that checks Wolfram Language  Loop construct
for a particular provides powerful The loop
condition in a block of primitives for construct is the
statements. specifying and simplest form of
controlling looping, not iteration provided
Eg; only in traditional by LISP. In its
Using if else: procedural simplest form It
if color = red then programming, but also allows to execute
writeln('You have chosen a in other, more modern some statement
red car') and streamlined repeatedly until it
else programming finds a return
writeln('Please choose a paradigms. statement.
color for your car'); Eg. (loop (s-expressions))
Eg. (loop (s- The loop keeps on
expressions)) executing till the
Nested if else: The loop keeps on condition holds true.
if( boolean_expression 1) then executing till the  Loop For
begin condition holds true.
if(boolean_expression The loop for construct
2)then  For loop allows to implement a
S1 for-loop like iteration as
else For[start, test, most common in other
S2; increment, body] languages.
end; executes start, then
Note: repeatedly evaluates It allows to
If the situation demands the body and increments
later construct, then you must  set up variables
until test fails to give
put “begin” and “end” for iteration
True.
keywords at the right place.  specify expression
that will
 For evaluates its
Page 7 of 39
arguments in a conditionally
nonstandard way. terminate the
 Loops: iteration
 The for loop:  For[start, test, incr]  specify expression
This is also a does the loop with a for performing
conditional statement null body. some job on each
which iterates holding  The sequence of iteration
each iterative value in evaluation is test, body,  specify
a local variable. increment. For exits as expression, and
Eg; soon as test fails. expressions for
for i:= 1 to 10 do  If Break[] is generated doing some job
writeln(i); in the evaluation of before exiting the
body, the For loop loop.
1) The initial step is executed exits.  Do Construct:
first, and only once. This  Continue[] exits the The do construct
step allows you to declare evaluation of body, and is also used for
and initialize any loop continues the loop by performing
control variables. evaluating incr. iteration using
2) Next, the condition is  Unless an explicit LISP. It provides a
evaluated. If it is true, the Return is used, the structured form of
body of the loop is value returned by For is iteration.
executed. If it is false, the Null.
body of the loop does not  Note that in an (do ((variable1 value1
execute and flow of example like updated-value1)
control jumps to the next For[tot=0;i=0,i<3,i++,to (variable2 value2
statement just after the t+=f[i]] the roles of the updated-value2)
for-do loop. semicolon and comma (variable3 value3
3) After the body of the for- are reversed relative to updated-value3)
do loop executes, the C-like programming ...)
value of the variable is languages. (test return-value)
either increased or Eg:- For[i = 1; t = x, i^2 (s-expressions)
decreased. < 10, i++, t = t^2 + i; )
4) The condition is now Print[t]]
evaluated again. If it is O/P – 1+x2  The initial values
true, the loop executes 2+(1+x2)2 of each variable is
and the process repeats 3+(2+(1+x2)2)2 evaluated and
itself . After the condition  While Loop bound to the
becomes false, the for-do respective
loop terminates. While[test, body] variable. The
 The while loop: evaluates test, then updated value in
This statement body, repetitively, until each clause
executes a block of test first fails to give corresponds to an
statements till the True. optional update
condition holds true. statement that

Page 8 of 39
The syntax of a while-  While[test] does the specifies how the
do loop is − loop with a null body. values of the
while (condition) do S;  If Break[] is generated variables will be
Where, condition is a Boolean in the evaluation of updated with
or relational expression whose body, the While loop each iteration.
value would be true or false exits.  After each
and S is a simple statement or  Continue[] exits the iteration, the test
group of statements within evaluation of body, and is evaluated, and
BEGIN ... END block. continues the loop. if it returns a non-
Eg:  Unless an explicit nil or true, the
while number>0 do
begin
Return is used, the return-value is
sum := sum + number; value returned by evaluated and
number := number - 2; While is Null. returned.
end;  Note that in an  The last s-
example like expression is
i=0;While[i<0,tot+=f[i];i optional. If
++] the roles of ; and , present, they are
are reversed relative to executed after
C-like programming every iteration,
languages. until the test
value returns true.
Ex:- While[n < 4,  Dotimes
Print[n]; n++] Construct
O/P:-1
2 The dotimes construct
3 allows looping for some
 Do Loop fixed number of
Iterations.
 Do[expr,n] evaluates Eg;
expr n times. (dotimes (n 11)
 Do[expr,{i,imax}] (print n) (prin1 (* n n))
evaluates expr with the )
variable i successively The above fragment
taking on the values 1 generates:
through imax (in steps 00
of 1). 11
 Do[expr,{i,imin,imax}] 24
starts with i=imin. 39
 Do[expr,{i,imin,imax,di} 4 16
] uses steps di. 5 25
 Do[expr,{i,{i1,i2,…}}] 6 36
uses the successive 7 49
values i1, i2, …. 8 64
 Do[expr,{i,imin,imax},{j, 9 81

Page 9 of 39
jmin,jmax},…] 10 100
 evaluates expr looping
over different values of  Dolist construct
j etc. for each i. The dolist construct
allows Iteration through
 Do uses the standard each element of a list.
Wolfram Language For eg;
iteration specification. (dolist (n '(1 2 3 4 5 6 7 8
 You can use Return, 9))
Break, Continue, and (format t "~% Number:
Throw inside Do. ~d Square: ~d" n (* n n))
 Unless an explicit )
Return is used, the The above fragment
value returned by Do is generates
Null. Number: 1 Square: 1
 Do[expr,Infinity] Number: 2 Square: 4
continues evaluating Number: 3 Square: 9
expr until explicitly told Number: 4 Square: 16
to exit through a Number: 5 Square: 25
function such as Break, Number: 6 Square: 36
Return, Throw, Abort, Number: 7 Square: 49
or Quit. Number: 8 Square: 64
 Do[expr,spec] first Number: 9 Square: 81
evaluates spec, then
localizes the variable
specified and
successively assigns
values to it, each time
evaluating expr.
 Do effectively uses
Block to localize values
or variables.
 Do[expr,spec1,spec2] is
effectively equivalent
to
Do[Do[expr,spec2],spe
c1].
Eg:-1. Do[Print[n^2], {n,
4}]
O/P:-1
4
9
16

Page 10 of 39
2.
Do[Print[RandomInteg
er[10]], 4]
O/P:-3
10
1
4

 Table Loop
 Table[expr,n] generates
a list of n copies of
expr.
 Table[expr,{i,imax}]
generates a list of the
values of expr when i
runs from 1 to imax.
 Table[expr,{i,imin,imax}
] starts with i=imin.
 Table[expr,{i,imin,imax,
di}] uses steps di.
 Table[expr,{i,{i1,i2,…}}]
uses the successive
values i1, i2, ….
 Table[expr,{i,imin,imax}
,{j,jmin,jmax},…] gives a
nested list. The list
associated with i is
outermost.

 You can use Table to


build up vectors,
matrices, tensors, and
other arrays.
 Table uses the standard
Wolfram Language
iteration specification.
 Table evaluates its
arguments in a
nonstandard way.
 Table[expr,spec] first
evaluates spec, then
localizes the variable
specified and
successively assigns

Page 11 of 39
values to it, each time
evaluating expr.
 Table effectively uses
Block to localize values
or variables.
 Table[expr,spec1,spec2
] is effectively
equivalent to
Table[Table[expr,spec2
],spec1].

Ex:-1. Table[10 i + j, {i, 4},


{j, 3}]
O/P:-

2. ListPlot[Table[Prime[i], {i,
50}]]
O/P:-

Page 12 of 39
Exception Handling
Pascal Wolfram Mathematica Auto Lisp
 An exception is an  Check  In Common LISP
error that happens terminology,
during the running of  Check[expr,failexpr] exceptions are
the program. evaluates expr, and called conditions.
 When an error returns the result,  In fact, conditions
occurs, Pascal unless messages were are more general
generates an generated, in which than exceptions in
case it evaluates and
exception that traditional
returns failexpr.
prevents the program programming
 Check[expr,failexpr,{s1
from getting crashed. ::t1,s2::t2,…}] checks languages, because
try a condition
only for the specified
// code that might generate an represents any
messages.
exception occurrence, error,
finally  Check[expr,failexpr,"na
me"] checks only for or not, which might
// will always be executed as
last statements messages in the named affect various levels
end; message group. of function call
stack.
 Whenever an exception  Check has  Condition handling
occurs, the code attribute HoldAll. mechanism in LISP,
between except and  Check does not test handles such
end will be executed. for messages that situations in such a
have been switched way that conditions
try off using Off, or by are used to signal
// code that might generate an uses of Quiet that
warning (say by
exception occur inside it.
except printing an
 The operation
// will only be executed in case of Check is not warning) while the
of an exception affected by being upper level code on
on E: EDatabaseError do enclosed the call stack can
ShowMessage( 'Database inside Quiet. continue its work.
error: '+ E.ClassName + #13#10  In Check[expr,failexp  The condition
+ E.Message ); r,"name"], possible handling system in
on E: Exception do named message LISP has three
ShowMessage( 'Error: '+ groups are given parts:
E.ClassName + #13#10 + by $MessageGroups.  Signalling a
E.Message );
end; condition
 Catch  Handling
 Catch[expr] returns the
the argument of the condition
first Throw generated
Page 13 of 39
in the evaluation of  Restart the
expr. process

 Catch[expr,form]
returns value from
the first
Throw[value,tag] for
which form matches
tag.
 Catch[expr,form,f]
returns f[value,tag].

 Catch[expr,…]
always returns the
value of expr if no
Throw was generated
during the evaluation.
 form can be any
expression, and is
often a pattern.
 tag in
Throw[value,tag] is
re‐evaluated every
time it is compared to
form.

Page 14 of 39
Object Oriented Support
Pascal Wolfram Mathematica Auto Lisp
 Object Oriented  Objectica  Common Lisp is
Programming is a directly
programming Objectica adds full-scale, perfectly concerned with
paradigm which integrated object orientation to the usual
deals “objects” Mathematica. You can rapidly build features of
which contains
your mathematical models using object-oriented
data in the form of
attributes and
classes, objects, inheritance, programming,
code in the form of polymorphism and encapsulation. such as classes
procedures. With Objectica, the capabilities of and methods.
 PASCAL is not Mathematica are combined with the  Common LISP
object oriented power of object orientation. predated the
language. advance of
Key Feature
object-oriented
programming by
 Full-scale object orientation
couple of
 Simple and easy-to-learn decades.
syntax However,
 Perfect integration into object-
Mathematica orientation was
incorporated
 Familiar concepts such as into it at a later
classes, objects, constructors, stage.
destructors, fields, methods  We will want to
and properties do three things:
 Declarative control over  Define
binding, inheritance, classes.
polymorphism and  Construct
encapsulation objects
that are
 Automatic variable generation instances
that allows switching to any of
solver after building the model classes.
 Special support of commercial  Define
class libraries methods
and
 Quick object access generic
functions.
 Many consistency checks and
thorough documentation

Page 15 of 39
Sub Program Design and Parameter Passing Techniques
Pascal Wolfram Mathematica Auto Lisp
 The call by reference  Procedures  The call by
method of passing reference method
arguments to a  The functions you define in of passing
subprogram copies the Wolfram Language are arguments to a
the address of an essentially procedures that subprogram copies
argument into the the address of an
execute the commands you
formal parameter. argument into the
Inside the
give. You can have several formal parameter.
subprogram,the steps in your procedures, Inside the
address is used to separated by semicolons. subprogram,the
access the actual  When you write procedures address is used to
argument used in in the Wolfram Language, it access the actual
the call. This means is usually a good idea to argument used in
that changes made make variables you use the call. This means
to the parameter inside the procedures local, that changes made
affect the passed so that they do not to the parameter
argument. interfere with things affect the passed
argument.
outside the procedures.
 In order to pass the
You can do this by setting
arguments by  In order to pass the
reference,Pascal up your procedures as arguments by
allows to define modules, in which you give reference,Pascal
variable parameters. a list of variables to be allows to define
This is done by treated as local. variable
preceding the parameters. This is
formal parameters  Parameters done by preceding
by the keyword var. the formal
Let us take the  The Wolfram Language uses parameters by the
example of the a uniform scheme to make keyword var. Let us
procedure swap() sure that the names of take the example of
that swaps the the procedure
formal parameters that
values in two swap() that swaps
variables and reflect
appear in constructs like the values in two
the change in the pure functions and rules are variables and reflect
calling subprogram. kept local, and are never the change in the
confused with global calling subprogram.
procedure names. The basic idea is to
swap(var x, y: replace formal parameters procedure
integer); swap(var x, y:
var when necessary by symbols integer);
temp: with names of the form x$. var
integer; By convention, x$ is never temp:
used as a global name. integer;
begin
temp := x; begin
x:= y; Eg:-Function[{x}, Function[{y}, x temp := x;
y := temp; + y]] x:= y;
end; y := temp;
end;

Page 16 of 39
3.2. The comparisons based on
1. Data Abstraction.
2. Support for parallelism.
3. Garbage Collector.

Data abstraction
Pascal Wolfram Mathematica Auto Lisp
Abstraction provides It doesn’t support for data LISP doesn’t have data
modularity but since PASCAL abstraction. abstraction.
is not a object oriented This does not mean that data
language, it doesn’t support abstraction is considered as
Abstraction. unimportant by Lisp users,
but merely that Lisp is open
to several different
approaches to it because of
which data abstraction is not
an important character. The
following are some of the
views that are represented in
actual Lisp systems:
• The use of an extension of
Lisp that provides object
orientation, in particular the
CLOS system (CommonLisp
Object System). CLOS is
defined as an IEEE standard,
along with the standards
definition of CommonLisp as
such. CLOS is a large and
relatively complex language,
and will not be considered in

Page 17 of 39
this course.
• The use of macro-like
facilities that can be defined
by an individual user or a
small user community,
providing a simple extension
of the Lisp language.
• The use of specialized
languages that are
embedded in Lisp, which
means that Lisp is used as a
high-level implementation
language for the new
language and as an
execution environment for it.
Specialized languages tend
to provide not only data
abstraction, but also control
abstraction, since some of
the control flow may be
defined in the interpreter for
the specialized language and
not in the programs written
by the user.

Page 18 of 39
Support for Parallelism
Pascal Wolfram Mathematica Auto Lisp
It does not support  Seamless local and network It does not support
operation, the symbolic character of
for Parallelism. for Parallelism.
the Wolfram Language allows
immediate support of a variety of
NOTE:SuperPascal is existing and new parallel NOTE:SuperPascal is
programming paradigms and data-
an imperative, an imperative,
sharing models.
concurrent  Automatic Parallelization concurrent computing
 Parallelize — evaluate an expression
computing programming
using automatic parallelization
programming  ParallelTry — try different language developed
computations in parallel, giving the
language developed by Brinch Hansen. It
first result obtained
by Brinch Hansen. It  Computation Setup & Broadcasting » was designed as a
 ParallelEvaluate — evaluate an
was designed as a publication language:
expression on all parallel subkernels
publication language:  DistributeDefinitions — distribute a thinking tool to
definitions to all parallel subkernels
a thinking tool to enable the clear and
 ParallelNeeds — load the same
enable the clear and package into all parallel subkernels concise expression of
 Data Parallelism »
concise expression of concepts in parallel
 ParallelMap ▪ ParallelTable ▪
concepts in parallel ParallelSum ▪ ... programming. This is
 ParallelCombine — evaluate
programming. This is in contrast with
expressions in parallel and combine
in contrast with their results. implementation
 Shared Memory & Synchronization »
implementation languages which are
 SetSharedVariable — specify symbols
languages which are with values to synchronize across often complicated
subkernels
often complicated with machine details
 SetSharedFunction — specify
with machine details functions whose evaluations are to be and historical
synchronized
and historical conventions. It was
 $SharedVariables ▪ $SharedFunctions
conventions. It was ▪ UnsetShared ▪ CriticalSection. created to address
 Multi-Processor and Multicore
created to address the need at the time
Computation
the need at the time  Compile — create compiled functions for a parallel
that run in parallel
for a parallel publication language
 Parallelization — execute compiled
publication language functions in parallel
 CompilationTarget — create machine-
level parallel compiled functions

Page 19 of 39
Garbage Collector
Pascal Wolfram Mathematica Auto Lisp
Garbage collection (GC) is a The Wolfram System is careful Garbage collection was
form of automatic memory about the way it uses memory. invented by John
management. The garbage Every time an intermediate McCarthy around 1959 to
collector, or just collector, solve problems in Lisp.
expression you have generated is
attempts to reclaim garbage, or
no longer needed, the Wolfram
memory occupied by objects Every Common Lisp
System immediately reclaims the
that are no longer in use by the implementation, must
memory allocated to it. This have garbage collection
program.
means that at any point in a defined, since any
 Pascal and some languages session, the Wolfram System standard implementation
like C don't traditionally use stores only those expressions that must comply to Common
garbage collections. They are actually needed; it does not Lisp ANSI standard.
used manual memory keep unnecessary objects which
management instead
have to be "garbage collected"
(malloc/free for C and
later.
new/dispose in Pascal)

 MemoryInUse[]
number of bytes of
memory currently being
used by the Wolfram
System
 MaxMemoryUsed[]
maximum number
of bytes of memory used
by the Wolfram System in
this session

Page 20 of 39
4. Evaluation criteria: Requirements and specification
Language evaluation criteria

1) Readability :
Our program can be easily read and understood by the user.
Eg: c:=a+b\\ ,i++
2) Orthogonality :
We are allowing programmers to build the program with primitive
constrains.
Eg: user has to terminate the statements by \\.
3) Writeability:
User can easily create programs in program domain.
Eg: out[“presidency university”]\\
4) Reliability :
We can’t assure that our program will work in all kinds of situation
5) Abstraction :
Low degree of abstraction .
Ability to define and then use complicated structures or operations in
ways that allow many of the details to be ignored.
6) Structured programming support :
Program can be written , tested and maintained.
Few errors are created while writing a program for the problem.
7) Compactness :
our programming language is compact that is able to express the
intended operations concisely without losing readability.

Page 21 of 39
5. Data types and structures
Primitive data type: inti, flow, letter,longflow.
Number representation: integer number (inti), floating number
(flow),double precision (longflow).

Data type Description Memory


Requirement

Inti Integer quantity 2 bytes

Letter Single character 1 byte

Flow Floating point number 4 bytes

longflow Double precision 8 bytes


Text representation: character and sentences ie string (letter)
For eg: inti r\\, letter(0) s\\

User defined data type: structure


Structure is the data type used to represent user defined data type
For eg: structure complex
[ inti r\\ flow i\\ ]
VARIABLES AND THEIR DECLARTIONS
Identifier used to represent a single data item. Its value can be changed
anywhere in the program but its data type cannot be changed.

All variables must be declared before they can appear in executable


statements

It consists of a data type, followed by one or more variables then


terminating by \\ .

ASSIGNING A VALUE

Values are assigned to variables using assignment operator (:=).

For eg: inti r\\

Page 22 of 39
r:=10\\

READING DATA FROM KEYBOARD

Syntax : in[var1,var2…..,varN] \\

Where “in” is the function name for input and var1,var2 are the
variables.

DISPLAY OUTPUT

Syntax :out[“text” var1,var2…..varN]\\

Where “out” is the function name for output and var1,var2 are the
variables.

EXPRESSIONS:

Expressions are combination of operand with operators.

Arithmetic operators: addition, subtraction, division , multiplication,


modulus

Arithmetic Meaning Data type of operands Examples


operator
+ Addition Inti/flow/longflow 5 + 2 is 7
5.0 + 2.0 is 7.0
- Subtraction Inti/flow/longflow 5 – 2 is 3
5.0 – 2.0 is 3.0
* Multiplication Inti/flow/longflow 5 * 2 is 10
5.0 * 2.0 is 10.0
/ division Inti/flow/longflow 5.0 / 2.0 is 2.5
5/2 is 2 (integer
division)
% remainder Inti 5 % 2 is 1
For eg: a:=b+c\\ g:=b-c\\ r:=e%f\\

Relational operators: greater than(>), lesser than(<), greater than or equal


to(>=), lesser than or equal to(<=),

equal (=) not equal(<>)


Page 23 of 39
6. Programming Language Requirement
Specification

Our language SAW tries to simplify the complexity involved many


programming language regarding composite data structure, by
providing:
Multiple assignment
Data type like Matrix
Matrix Operations – Display, Addition, Multiplication
User defined data types

Description of Programming Language


Requirements
Topic List
S.NO. User Compiler Run-Time

User can declare


Compiler
a variable of should
int(),float(),double(),ch desired data type, Needs to
ar()string(), bool() process the
but the variable allocate
Multiple declarations declaration
name should memory for
1 Data Type and multiple or the
be enclosed with the
assignments are initialization
parenthesis. They variables
allowed. enclosed
can initialize declared.
Ex: int(a,b,c=1,2,3); in
variable while
parenthesis.
declaring them.
User must use
Needs to
matrix to declare
Compiler allocate
Matrix they can different
should contiguous
Special Data matrix(m[ROW][COLU operations data
2 validate the memory
type MN]); type. matrices,
matrix location for
E.g.: matrix(n[2][3]) perform matrix
initialization. this data
on this.
type.
User need to For any given Needs to
 / know expression, allocate
Arithmetic  * that there is no processing memory for
3 precedence, but should be processed
Operators  + done from
it expression
 - follows left to left to to store
 = right right. the result.
Page 24 of 39
associativity. Raising
Exceptions
if any value
is divided by
0.
Compiler will
process
User can perform the logical Logical
! logical NOT, AND,
Logical operation operation
4  && OR
Operators and return will be
 || operations using respective performed.
these operators.
Boolean
value.
User can write
simple Needs to
Operators have no
expressions. For any given allocate
precedence and
Expressions are expression, memory
associativity is from left
having an processing for the
5 Expressions to right.
associativity of should be processed
E.g.: a=9*2-4/2;
left to right, and done from expression
write(a);
arithmetic left to right. to store the
Output: 7
operations have result.
no precedence.
 If statement
Compiler Conditiona
 If-Else User should should l block
statement know process the will be
Conditional  If-Else If ladder the syntax of If- conditional performed
6
Statements  Nested If-else Else block if based on
statement and the Switch the flag
 Switch Statement. condition is Register
true. status.
statement
 for(initialize;co
ndi;update) User should
{ initialize,
//DoSomething provide a loop Will iterate
Should
} through
condition and an iterate the
the loop
 while(condi) update loop block
Loop block, till
7 { operation for the
statements the loop
//DoSomething each followed by value of
condition
} a loop
becomes
 do semicolon in counter.
false.
{ case of
//DoSomething for loop.
}while(condi);
It return values Compiler Assign the
Input to should value to
8 variable=read()
statement the variable, by check for memory
taking the valid data address of

Page 25 of 39
runtime type for that
inputs. inputs. identifier.
write() Print the
Compiler
processed
Output User passes the invokes
9 E.g.: data on
Statement arguments to system call
write(“Hello”); the
for
Output: Hello dialogue.
 datatype(identi
fier1 = value1,
identifier2 = Compiler
value2); will make We can
 datatype(identi User can assign
sure that make
values to the
fier3, the data runtime
Assignment identifier4 = identifiers, they
10 type of assignmen
Statements value3, can also use
value and t using the
value4); multiple
the read()
assignments.
 datatype(identi identifier is function.
fier); same.
identifier =
value;
User should
Compiler Allocates
provide
should contiguous
datatype(indentifier[si size of array, if
validate memory
11 Array or list zeOfArray]); they are not
the array location
int(a[]={1,2,3,4,5,6,7}); initializing the
initialization for this
array at
. data type.
declaration time.
deftype
datatypeName
{
//Predefined
Datatypes
} Allocates
Compiler
E.g.: memory
should
User deftype newType User can create as per the
validate the
Defined { heterogeneous size
12 definition
data int(n); data types using required
of user
types char(m); this feature. by the
defined
} member
type.
//Declaration and data type
Initialization
newType(variable={1,'
A'});
write(variable.n+"
"+variable.m);

Page 26 of 39
All the
User should Compiler parameter
provide a return should values and
returnType
type for a match the the return
functionName(argume
function if there return type address of
Sub nts)
13 is a value of the the sub
programs {
returned, if no function program
//Function Body
value is returned with the are stored
}
then return type returned on the
can be ignored. value. system
stack.

Compiler
should
Actual Parameter:
match the
functionName(indenti User can call sub Parameter
data type,
fierName) programs, and values
number of
14 Parameters functionName(value) pass arguments are stored
parameters
Formal Parameter: either by value in system
passed to
functionName(datatyp or reference. stack.
the sub
e(indentifierName))
program
call.

 Every statement User should end


is terminated by every statement Compiler
a semi-colon. with a semicolon should
Syntax of and
15
Program
 Every block check for N/A
every block
statement is syntax
statement must
enclosed with errors.
be enclosed by
{}. {}.

Page 27 of 39
7. Grammar for Programing Language ‘SAW’

1. <program>-> <declarationList>
2. <declarationList> -> <declarationList> <declaration> | <declaration>
3. <declaration> -> <varDeclaration> | <funDeclaration> | <recDeclaration>
4. <recDeclaration> -> <ID> { <localDeclarations> } | E
5. <varDeclaration> -> <typeSpecifier> <varDeclList>; | <typeSpecifier> {
<varDeclList>; }
6. <scopedVarDeclaration> -> <scopedTypeSpecifier ><varDeclList>
7. <varDeclList> -><varDeclList> , <varDeclInitialize> | <varDeclInitialize>
8. <varDeclInitialize> -> <varDeclId> | <varDeclId> : <simpleExpression> |
<initialize>
9. <varDeclId> -> <ID> | <RECTYPE> <ID> ( <params> ) | <ID> ( <params> )
|E
10.<scopedTypeSpecifier >->static <typeSpecifier> | <typeSpecifier>
11.<typeSpecifier> -><returnTypeSpecifier> | <RECTYPE> | E
12.<returnTypeSpecifier> ->int | bool | char |void
13. <RECTYPE> -> void| char| short| int| long| float| double| signed | mat
|<struct-or-union- specifier>| <enum-specifier> | <typedef-specifier > |
<selectionStmt>
14.<funDeclaration> -> <typeSpecifier> <ID> ( <params> ) <statement> |
<ID> ( <params> ) <statement>
15.<params> -> <paramList> | E
16.<paramList> -><paramList> ; <paramTypeList> | <paramTypeList>
17.<paramTypeList> -> <typeSpecifier> <paramIdList>
18.<paramIdList> -> <paramIdList> , <paramId> | <paramId>
19.<paramId> -> <ID>|E
20.<statement> -> <expressionStmt> | <compoundStmt> | <selectionStmt>
| <iterationStmt> | <returnStmt>| <breakStmt> | <funStmt>
21.<funStmt> -> <ID>(); | <ID>(<funStmt>); | <ID>(<ID>,<funStmt>); |
<ID>(<form>);
22.<form> -> <ID>,<form> | <ID> | “<ID>”,<form> | “<ID>” | <Var> | E
Page 28 of 39
23.<Var> -> +<ID>
24.<compoundStmt> -> { <localDeclarations> <statementList> }
25.<localDeclarations> -> <localDeclarations> <scopedVarDeclaration> | E
26.<statementList>-> <statement> <statementList> | E
27.<expressionStmt> -> <expression> ; | <expression> ; <statement> | E
28.<selectionStmt> ->if(<condition>) <statement> | if (<condition>)
<statement> else <selectionStmt> | <statement> |
29.<condition> -><relop> <condition>|<ID> <relop> <ID>|E
30.<iterationStmt> ->for(<initialize>;<condition>;<update>){ <statement> }|
while(<condition>){ <statement> }|Do{ <statement>
}while(<condition>);
31.<initialize> -> <ID>=<ID>; |<RECTYPE> <ID>=<ID>; | <ID>=<ID> ;
<initialize> | E
32.<update> -> <ID>++ | <ID>--
33.<returnStmt> ->return <ID> ; | return <expression> ;
34.<breakStmt> ->break ;
35.<expression> -> <mutable> = <expression> | <mutable> += <expression>
| <mutable> -= <expression>| <mutable> *= <expression> | <mutable>
/= <expression> | <mutable> ++ | <mutable> -- | <simpleExpression>
36.<simpleExpression> -> <simpleExpression> or <andExpression> |
<andExpression>
37.<andExpression> -> <andExpression> and <unaryRelExpression> |
<unaryRelExpression>
38.<unaryRelExpression> -> &
i. | *
ii. | +
iii. | -
iv. | ~
v. | !| <relExpression>
39.<relExpression> -><sumExpression> <relop> <sumExpression> |
<sumExpression>
40.<relop> -><= | < | > | >= | == | ! =
41.<sumExpression> -> <ID> <sumop> <term> | <term> | E
Page 29 of 39
42.<sumop> -> + | -
43.<term> -><ID> <mulop> <unaryExpression> | <unaryExpression>
44.<mulop> ->* | / | %
45.<unaryExpression> -><unaryop> <unaryExpression> | <factor>
46.<unaryop> ->- | * | ?
47.<factor> ->| <mutable> |E
48.<mutable> -> <ID> | <mutable> [ <expression> ] | <mutable> . <ID>
49.<ID>->[a-z][A-Z][0-9]
50.<call> -><ID> ( <args> )
51.<Assignmentoperator>->=
i. | *=
ii. | /=
iii. | %=
iv. | +=
v. | -=
vi. | <<=
vii. | >>=
viii. | &=
52.<args> -><argList> | E
53.<argList> -><argList> , <expression> | <expression>
54.<constant> ->True | False
55.<Comma>->,/E

Page 30 of 39
8. Test Cases

1) Int max(int a; int b)


{
If(a>b)
return a;
else if(b>a)
return b;
else
while(a==b)
{
write(a);
}
}
Derivation

1. <program>-> <declarationList>
2. <program>-> <declaration>
3. <program>-> <funDeclaration>
4. <program>-> <typeSpecifier> <ID> ( <params> ) <selectionStmt>
5. <program>-><returnTypeSpecifier> <ID> ( <params> ) <selectionStmt>
6. <program>-> int <ID> ( <params> ) <selectionStmt>
7. <program>-> int max ( <params> ) <selectionStmt>
8. <program>-> int max (<paramList> ) <selectionStmt>
9. <program>-> int max (<paramList> ; <paramTypeList> ) <selectionStmt>
10. <program>-> int max (<paramTypeList> ; <paramTypeList> ) <selectionStmt>
11. <program>-> int max (<typeSpecifier> <paramIdList> ; <paramTypeList> )
<selectionStmt>
12. <program>-> int max (<returnTypeSpecifier> <paramIdList> ;
<paramTypeList> ) <selectionStmt>
13. <program>-> int max (int <paramIdList> ; <paramTypeList> )
<selectionStmt>
14. <program>-> int max (int <paramId> ; <paramTypeList> ) <selectionStmt>
15. <program>-> int max (int <ID> ; <paramTypeList> ) <selectionStmt>
16. <program>-> int max (int a ; <paramTypeList> ) <selectionStmt>
17. <program>-> int max (int a ; <typeSpecifier> <paramIdList> )
<selectionStmt>
18. <program>-> int max (int a ; returnTypeSpecifier <paramIdList> )
<selectionStmt>
19. <program>-> int max (int a ; int <paramIdList> ) <selectionStmt>
20. <program>-> int max (int a ; int <paramId> ) <selectionStmt>
21. <program>-> int max (int a ; int <ID> ) <selectionStmt>

Page 31 of 39
22. <program>-> int max (int a ; int b ) <selectionStmt>
23. <program>-> int max (int a ; int b ) <compoundStmt>
24. <program>-> int max (int a ; int b ) { <localDeclarations> <statementList>}
25. <program>-> int max (int a ; int b ) { <localDeclarations>
<scopedVarDeclaration> <statementList>}
26. <program>-> int max (int a ; int b ) { <scopedVarDeclaration>
<statementList>}
27. <program>-> int max (int a ; int b ) { <scopedTypeSpecifier ><varDeclList>
<statementList>}
28. <program>-> int max (int a ; int b ) { <typeSpecifier> <varDeclList>
<statementList>}
29. <program>-> int max (int a ; int b ) { <RECTYPE> <varDeclList>
<statementList>}
30. <program>-> int max (int a ; int b ) { <selectionStmt> <varDeclList>
<statementList>}
31. <program>-> int max (int a ; int b ) { if (<condition>) <selectionStmt> else
<selectionStmt> <varDeclList> <statementList>}
32. <program>-> int max (int a ; int b ) { if (<ID> <relop> <ID>) <selectionStmt>
else <selectionStmt> <varDeclList> <statementList>}
33. <program>-> int max (int a ; int b ) { if (a <relop> <ID>) <selectionStmt> else
<selectionStmt> <varDeclList> <statementList>}
34. <program>-> int max (int a ; int b ) { if (a > <ID>) <statement> else
<selectionStmt> <varDeclList> <statementList>}
35. <program>-> int max (int a ; int b ) { if (a > b) <statement> else
<selectionStmt> <varDeclList> <statementList>}
36. <program>-> int max (int a ; int b ) { if (a > b) <returnStmt> else
<selectionStmt> <varDeclList> <statementList>}
37. <program>-> int max (int a ; int b ) { if (a > b) return <ID> ; else
<selectionStmt> <varDeclList> <statementList>}
38. <program>-> int max (int a ; int b ) { if (a > b) return a ; else
<selectionStmt> <varDeclList> <statementList>}
39. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (<condition>)
<statement> else <selectionStmt> <varDeclList> <statementList>}
40. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (<ID> <relop>
<ID>) <statement> else <selectionStmt> <varDeclList> <statementList>}
41. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b <relop>
<ID>) <statement> else <selectionStmt> <varDeclList> <statementList>}
42. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > <ID>)
<statement> else <selectionStmt> <varDeclList> <statementList>}
43. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a)
<statement> else <selectionStmt> <varDeclList> <statementList>}
44. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a)
<returnStmt> else <selectionStmt> <varDeclList> <statementList>}

Page 32 of 39
45. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
<ID> ; else <selectionStmt> <varDeclList> <statementList>}
46. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else <selectionStmt> <varDeclList> <statementList>}
47. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else <statement> <varDeclList> <statementList>}
48. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else <iterationStmt> <varDeclList> <statementList>}
49. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(<condition>){ <statement> } <varDeclList> <statementList>}
50. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(<ID> <relop> <ID>){ <statement> } <varDeclList>
<statementList>}
51. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a <relop> <ID>){ <statement> } <varDeclList> <statementList>}
52. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == <ID>){ <statement> } <varDeclList> <statementList>}
53. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ <statement> } <varDeclList> <statementList>}
54. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ <funStmt> } <varDeclList> <statementList>}
55. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ <ID>(<form>); } <varDeclList> <statementList>}
56. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ write(<form>); } <varDeclList> <statementList>}
57. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ write(“<ID>”); } <varDeclList> <statementList>}
58. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ write(“Both are equal.”); } <varDeclInitialize>
<statementList>}
59. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ write(“Both are equal.”); } <varDeclId>
<statementList>}
60. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ write(“Both are equal.”); } <statementList>}
61. <program>-> int max (int a ; int b ) { if (a > b) return a ; else if (b > a) return
b ; else while(a == b){ write(“Both are equal.”); } }

Page 33 of 39
2. Matrix Operations
deftype matrices
{
Int MAT(a[2][2],b[2][2],res[2][2]);
}
start()
{
a = {{1, 2}, {3, 4}};
b = {{5, 6}, {7, 8}};
res = a+b;
write("Matrix Addition:"+res);
}

Derivation

1. <program>-> <declarationList>
2. <program>-> <declarationList> <declaration>
3. <program>-> <declaration> <declaration>
4. <program>-> < varDeclaration> <declaration>
5. <program>-> <typeSpecifier> { <varDeclList> ; } <declaration>
6. <program>-> <RECTYPE> { <varDeclList> ; } <declaration>
7. <program>-> <typedef-specifier> { <varDeclList> ; } <declaration>
8. <program>-> typedef { <varDeclList> ; } <declaration>
9. <program>-> typedef { <varDeclInitialize> ; } <declaration>
10. <program>-> typedef { <varDeclId> ; } <declaration>
11. <program>-> typedef { <RECTYPE> <ID> (<params>) ); } <declaration>
12. <program>-> typedef { int <ID> (<params>) ); } <declaration>
13. <program>-> typedef { int MAT( <params> ); } <declaration>
14. <program>-> typedef { int MAT( <paramList> ); } <declaration>
15. <program>-> typedef { int MAT( <paramTypeList> ); } <declaration>
16. <program>-> typedef { int MAT( <paramIdList> ); } <declaration>
17. <program>-> typedef { int MAT( <paramIdList> , <paramId> ); } <declaration>
18. <program>-> typedef { int MAT( <paramIdList> , <paramId> , <paramId> ); }
<declaration>
19. <program>-> typedef { int MAT( <paramId> , <paramId> , <paramId> ); }
<declaration>
20. <program>-> typedef { int MAT( <ID> , <paramId> , <paramId> ); } <declaration>
21. <program>-> typedef { int MAT( a[2][2] , <paramId> , <paramId> ); } <declaration>
22. <program>-> typedef { int MAT( a[2][2] , <ID> , <paramId> ); } <declaration>
23. <program>-> typedef { int MAT( a[2][2] , b[2][2] , <paramId> ); } <declaration>

Page 34 of 39
24. <program>-> typedef { int MAT( a[2][2] , b[2][2] , <ID> ); } <declaration>
25. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } <declaration>
26. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } <funDeclaration>
27. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } <ID> ( <params> )
<statement>
28. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start ( <params> )
<statement>
29. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () <statemen
30. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start ()
<compoundStmt>
31. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () {
<localDeclarations> <statementList> }
32. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () {
<localDeclarations> <scopedVarDeclaration> <statementList> }
33. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () {
<scopedVarDeclaration> <statementList> }
34. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () {
<scopedTypeSpecifier> <varDeclList> <statementList> }
35. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () {
<typeSpecifier> <varDeclList> <statementList> }
36. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { <varDeclList>
<statementList> }
37. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () {
<varDeclInitialize> <statementList> }
38. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { <initialize>
<statementList> }
39. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { <ID> = <ID> ;
<initialize> <statementList> }
40. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; <initialize> <statementList> }
41. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; <ID> = <ID> ; <statementList> }
42. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; <statementList> }

Page 35 of 39
43. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; <statement> <statementList> }
44. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; <expressionStmt> <statementList> }
45. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; <expression> ; <statement> <statementList> }
46. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; <mutable> = <expression> ; <statement> <statementList>
}
47. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; <ID> = <expression> ; <statement> <statementList> }
48. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = <expression> ; <statement> <statementList> }
49. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = <simpleExpression> ; <statement> <statementList> }
50. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = <andExpression> ; <statement> <statementList> }
51. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = <unaryRelExpression> ; <statement>
<statementList> }
52. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = <relExpression> ; <statement> <statementList> }
53. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = <sumExpression> ; <statement> <statementList> }
54. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = <ID> <sumop> <term>; <statement> <statementList>
}
55. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a <sumop> <term>; <statement> <statementList> }
56. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + <term>; <statement> <statementList> }
57. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + <unaryExpression> ; <statement>
<statementList> }
Page 36 of 39
58. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + <factor> ; <statement> <statementList> }
59. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + <mutable> ; <statement> <statementList> }
60. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + <ID> ; <statement> <statementList> }
61. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; <statement> <statementList> }
62. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; <funStmt> <statementList> }
63. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; <ID> ( <form> ) ; <statementList> }
64. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; write ( <form> ) ; <statementList> }
65. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; write (“<ID>”,<form> ) ; <statementList> }
66. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; write (“Matrix Addition:”,<form> ) ;
<statementList> }
67. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; write (“Matrix Addition:”, <Var> ) ;
<statementList> }
68. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; write (“Matrix Addition:”, +<ID>) ;
<statementList> }
69. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; write (“Matrix Addition:”, +res) ;
<statementList> }
70. <program>-> typedef { int MAT( a[2][2] , b[2][2] , res[2][2] ); } start () { a = {{1, 2}, {3,
4}} ; b = {{5, 6}, {7, 8}} ; res = a + b ; write (“Matrix Addition:”, +res) ; }

Page 37 of 39
3. GCD using Euclid’s Algorithm
int gcd(int a,int b)
{
if(a%b==0)
return b;
else
return gcd(b,a%b);
}
start()
{
int(a,b,result);
write("Enter value for a");
a=read();
write("Enter value for b");
b= read();
result=gcd(a,b);
write("The GCD is "+result);
}

4. Bubble Sort
start()
{
int(a[100],n);
write("Enter the number of elements:");
n= read ();
write("Enter the array elements:");
for(int(i=0);i<n;i++)
{
a[i]= read();
}
for(int(i=0);i<n;i++)
{
bool(swapped=false);
for(intj=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
a[j],a[j+1]=a[j+1],a[j];
swapped=true;
}
Page 38 of 39
}
if(!swapped)
break;
}
write("Sorted elements are:\n");
for(inti=0;i<n;i++)
{
write(a[i]+"\t");
}
}

Page 39 of 39

You might also like