Вы находитесь на странице: 1из 48

PRESIDENCY UNIVERSITY

School of Engineering (SOE)


Department of Computer Science and Engineering
CSE214 Principles of programming languages (PPL)

Project
On
Designing own imperative programming language

Name of the Student ID No. Branch


G Nikitha 20171CSE0203 B. Tech Computer Science and Engineering
Deepika E 20171CSE0176 B. Tech Computer Science and Engineering
Divya R 20171CSE0186 B. Tech Computer Science and Engineering
Divya C 20171CSE0185 B. Tech Computer Science and Engineering

Submitted to - Prof.Prasad

DECLARATION
I hereby declare that the project entitled “DND” submitted for the completion of course,
Principles of Programming Languages (CSE-214), is our original work.

Place: BANGALORE Signature of Team members:


Date: 02-12-2019

ACKNOWLEDGEMENTS
I wish to acknowledge my deep gratitude to the entire faculty of “Principles of programming
languages” for their cooperation throughout this project, in helping us to complete this project
successfully.
Our sincere appreciation to all our teammates who actually initiated this project and contributed
their efforts in completion of this project.
Some human errors may have inadvertently occur in this project despite our best efforts to keep
them out.

Abstract
In this project we are introducing 3 already existing programming languages with their scope and
motivation. Here next stop we are conducting a literature review where we are comparing these 3
programming languages in terms of datatypes, variables, operators,

Expression evaluation, looping statements, functions and parameter passing mechanisms after this we
are deriving the inferences on the literature review. After this process we are doing a requirements
specification where we are introducing 2 new datatypes and operators as part of our own language. The
main objective here is that while comparing the three languages we need to understand the differences
and the similarities along with their working by referencing this we need to design our own
programming language.

Next this we will be following this up with our own grammar for programming language along with test
cases and nay future scope and finally the conclusion.

Table of Contents
Title Page i
Declaration of the Student ii
Acknowledgement iii
Abstract iii

1. INTRODUCTION TO PROGRAMMING LANGUAGE 1


2. LITERATURE REVIEW (Comparison of PL’s)
3. REQUIREMENT SPECIFICATION
4. PROGRAMMING LANGUAGE DESIGN (Grammar)
5. TEST CASES
6. DERIVATIONS
7. LIMITATIONS OF LANGUAGE
8. FUTURE SCOPE
Parameters HASKELL

Data types Note: In Haskell, all datatypes start with a Capital letter, e.g.: Bool instead of bool.
Int, Integer, Float, Char, String, Bool, Double.

Variables For longer calculations and for writing Haskell programs, we want to keep track of intermediate results.
We can store intermediate results by assigning them names. These names are called variables. When a
program runs, each variable is substituted for the value to which it refers. For instance, consider the
following calculation

Prelude> 3.141592653 * 5^2


78.539816325

That is the approximate area of a circle with radius 5 , according to the formula

Operators  Arithmetic “operators” +, -, *, /

 Boolean “operators” &&, ||, ==, /=, not

 String concatenation ++

 List concatenation ++

 Note:

 The “not-equal” operator in Haskell is /=, which is unlike most other languages which use! = for
the same purpose.

 The Boolean negation operation in Haskell is not, which is unlike most other languages which
use! for the same purpose.
Expression
Haskell code will also work with parentheses, but we omit them as a convention. Haskell uses
evaluation
functions all the time, and whenever possible we want to minimize extra symbols.
(Precedence
and We still use parentheses for grouping expressions (any code that gives a value) that must be evaluated
association together. Note how the following expressions are parsed differently:
rules)
5*3+2 -- 15 + 2 = 17 (multiplication is done before addition)
5 * (3 + 2) -- 5 * 5 = 25 (thanks to the parentheses)
area 5 * 3 -- (area 5) * 3
area (5 * 3) -- area 15
Note that Haskell functions take precedence over all other operators such as + and *, in the same way
that, for instance, multiplication is done before addition in mathematic s.

Selection
The following flowchart shows the decision-making structure of Haskell −
statement

Looping In Haskell, there are no looping constructs. Instead, there are two alternatives: there are
statements
list iteration constructs (like fold which we've seen before), and tail recursion. ... But there are always
cases where you need to write something like a loop for yourself, and tail recursion is the way to do it
in Haskell.
Nested Loops in Haskell
For example, if I have this basic nested loop structure, how would I go about implementing this in
Haskell?
list = []
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {

if board[i][j] == Nothing

list.append([i,j, 'X'])
}
}
return list
Functions play a major role in Haskell, as it is a functional programming language. Like other
Functions
languages, Haskell does have its own functional definition and declaration.
 Function declaration consists of the function name and its argument list along with its output.
 Function definition is where you actually define a function.
EX:
add :: Integer -> Integer -> Integer --function declaration
add x y = x + y --function definition

main = do
putStrLn "The addition of the two numbers is:"
print (add 2 5) --calling a function
The addition of the two numbers is:
7

Parameter  Haskell: uses pass-by-need


passing
mechanisms (* This will print `0` *)

fun pass_by_function (cond, a1, a2) =


if cond then a1
else a2

val e1 = fn () => 1 * 0
val e2 = fn () => 1 div 0

val _ = print (Int.toString (pass_by_function (true, e1, e2) ()))

(* This will fail with a divide error *)

fun pass_by_value (cond, a1, a2) =


if cond then a1
else a2

val _ = print (Int.toString (pass_by_value (true, 1 * 0, 1 div 0)))


It's a big matter for Haskell to be call-by-need.

Sample main = putStrLn "Hello World"


program
Once the Haskell compiler encounters the above piece of code, it promptly yields the
following output −
Hello World
Parameters SWIFT
Data types
Built-in Data Types
Swift offers the programmer a rich assortment of built-in as well as user-defined data types. The following types
of basic data types are most frequently when declaring variables −
 Int or UInt − This is used for whole numbers. More specifically, you can use Int32, Int64 to define 32 or
64 bit signed integer, whereas UInt32 or UInt64 to define 32 or 64 bit unsigned integer variables. For
example, 42 and -23.
 Float − This is used to represent a 32-bit floating-point number and numbers with smaller decimal
points. For example, 3.14159, 0.1, and -273.158.
 Double − This is used to represent a 64-bit floating-point number and used when floating-point values
must be very large. For example, 3.14159, 0.1, and -273.158.
 Bool − This represents a Boolean value which is either true or false.
 String − This is an ordered collection of characters. For example, "Hello, World!"
 Character − This is a single-character string literal. For example, "C"
 Optional − This represents a variable that can hold either a value or no value.
 Tuples − This is used to group multiple values in single Compound Value

Type Typical Bit Width Typical Range

Int8 1byte -127 to 127

UInt8 1byte 0 to 255

Int32 4bytes -2147483648 to 2147483647

UInt32 4bytes 0 to 4294967295

Int64 8bytes -9223372036854775808 to 9223372036854775807

UInt64 8bytes 0 to 18446744073709551615


Float 4bytes 1.2E-38 to 3.4E+38 (~6 digits)

Double 8bytes 2.3E-308 to 1.7E+308 (~15 digits)

Variables Variable Declaration


A variable declaration tells the compiler where and how much to create the storage for the variable.
Before you use variables, you must declare them using var keyword as follows −
var variableName = <initial value>
The following example shows how to declare a variable in Swift −

var varA = 42
print(varA)

When we run the above program using playground, we get the following result −
42

Operators
Types of operators

We can categorize operators broadly in two basic categories based on the:


Number of operands
Operation of an operator
According to the number of operands an operator operates on, operators can be categorized as:
1. Unary operator

This operators operate on a single operand.

2. Binary operator

This operator operates on two operands.

3. Ternary Operators
This operator operates on three operands. Visit Swift Ternary Conditional Operator to learn more about
it.

According to the operation a operator does, it can be categorized as:

1. Assignment operators
Operator Meaning

= Simple assignment operator, Assigns values from right side operands to left side operand

Add AND assignment operator, It adds right operand to the left operand and assigns the result
+= to left operand

Subtract AND assignment operator, It subtracts right operand from the left operand and assigns
-= the result to left operand

Multiply AND assignment operator, It multiplies right operand with the left operand and assigns
*= the result to left operand

Divide AND assignment operator, It divides left operand with the right operand and assigns the
/= result to left operand

Modulus AND assignment operator, It takes modulus using two operands and assigns the
%= result to left operand

<<= Left shift AND assignment operator

>>= Right shift AND assignment operator

&= Bitwise AND assignment operator

^= bitwise exclusive OR and assignment operator

|= bitwise inclusive OR and assignment operator

Arithmetic operators

These operators are used to perform mathematical operations that includes multiplication,
division, addition and subtraction etc. This operators fall into category of binary operator that
takes two operands.

Operator Meaning

+ Addition (also used for string concatenation)

- Subtraction Operator

* Multiplication Operator
Operator Meaning

/ Division Operator

% Remainder Operator

Comparison Operators

These operators allow you to compare two values. Each of the comparison operators returns a Bool
value to indicate whether or not the statement is true. Swift supports following types of comparison
operators:

Operator Meaning Example

== equal to 5 == 3 is evaluated to false

!= not equal to 5 != 3 is evaluated to true

> greater than 5 > 3 is evaluated to true

< less than 5 < 3 is evaluated to false

>= greater than or equal to 5 >= 5 is evaluated to true

<= less than or equal to 4 <= 5 is evaluated to true

Logical Operators

These operators are used with Boolean (logical) values and returns a Boolean value. It is mainly used to
control program flow with if else, while, or some other control statement.

Operator Meaning Example

|| Logical-OR; true if either of the boolean expression is true false || true is evaluated to true
Operator Meaning Example

&& Logical-AND; true if all boolean expressions are true false && true is evaluated to false

Expression Operator precedence determines the grouping of terms in an expression. This affects how an expression is
evaluation evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has
(Precedenc higher precedence than the addition operator.
e and
association For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it
first gets multiplied with 3*2 and then adds into 7.
rules)
Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the
bottom. Within an expression, higher precedence operators will be evaluated first.
Operator Description Example

Primary Expression Operators () [] . expr++ expr-- left-to-right

* & + - ! ~ ++expr --expr


*/%

Unary Operators +-
right-to-left
>> <<
< > <= >=
== !=

&
^
Binary Operators | left-to-right
&&
||

Ternary Operator ?: right-to-left

Assignment Operators = += -= *= /= %= >>= <<= &=^= |= right-to-left

Comma , left-to-right
Selection Loop control statements change execution from its normal sequence. When execution leaves a scope, all
statement automatic objects that were created in that scope are destroyed.
Swift supports the following control statements.

Sr.No Control Statement & Description

1 continue statement

This statement tells a loop to stop what it is doing and start again at the
beginning of the next iteration through the loop.

2 break statement
Terminates the loop statement and transfers execution to the statement
immediately following the loop.

3 fallthrough statement
The fallthrough statement simulates the behavior of Swift 4 switch to C-
style switch.

Looping A loop statement allows us to execute a statement or group of statements multiple times.
statements Following is the general from of a loop statement in most of the programming languages −

Swift 4 programming language provides the following kinds of loop to handle looping
requirements
Functions
In Swift , a function is defined by the "func" keyword. When a function is newly defined, it may take one
or several values as input 'parameters' to the function and it will process the functions in the main body
and pass back the values to the functions as output 'return types'.
Every function has a function name, which describes the task that the function performs. To use a
function, you "call" that function with its name and pass input values (known as arguments) that match
the types of the function's parameters. Function parameters are also called as 'tuples'.
A function's arguments must always be provided in the same order as the function's parameter list and
the return values are followed by →.

Syntax
func funcname(Parameters) -> returntype {
Statement1
Statement2
---
Statement N
return parameters
}

Parameter
passing Parameters can provide default values to simplify function calls and can be passed as in-out parameters,
mechanism which modify a passed variable once the function has completed its execution. Every function
s in Swift has a type, consisting of the function's parameter types and return type.

Example 1: No Parameters passed and no return value


1. func greetUser() {
2. print("Good Morning!")
3. }
4. greetUser()

When you run the above program, the output will be:

Good Morning!
Sample 1. // Hello, World! Program
program 2. import Swift
3. print("Hello, World!")
// Hello, World! Program

In Swift, any line starting with two slashes // is a comment. They are completely ignored by the compiler.

import Swift

import keyword allows you to access all the symbols defined inside a framework.For now, just remember
this line is required to use print("Hello, World!") in our program. You’ll learn more about it in the later
tutorials.

print("Hello, World!")

The above line is called a function in Swift. More specifically, a print function.

In swift, print means "show on the screen". The above code prints the string inside quotation marks, i.e
"Hello, World!" on the screen

Paramete
rs
1.Value data Types
a. Predefined Data Types
Integer
Boolean
Float
b. User defined Data Types
Enumerations
Structure
2.Pointer Data Type
3.Reference data Types
a. Predefined Data Types
Objects
Strings
b. User defined Data Types
Classes
Interface
Bool, byte, char, decimal, double, float, int, long, sbyte, short, uint, ulong, ushort

Variables

Operators
1. Basic Assignment Operator
double x;
x=50.05;

2. Arithmetic Operators

+,-,*,/,%,**
3. Relational Operators
==,>,<,<=,>=,!=

4. Logical Operators
AND(&&),OR(| |)

5. Unary Operators
+,-,++,--,!

6. Ternary Operator

Variable = Condition? Expression1 : Expression2;

7. Bitwise and Bit Shift Operators


~,&,|,^,<<,>>

8. Compound Assignment Operators


+=,-=,*=,/=,%=,&=,|=,^=,<<=,>>=,=>

Expression
evaluation
(Precedence Category Operators Associativity
and
association Postfix Increment and Decrement ++, -- Left to Right
rules)
Prefix Increment, Decrement and
Unary ++, --, +, -, !, ~ Right to Left

Multiplicative *, /, % Left to Right

Additive +, - Left to Right

Shift <<, >> Left to Right

Relational <, <=, >, >= Left to Right

Equality ==, != Left to Right

Bitwise AND & Left to Right

Bitwise XOR ^ Left to Right

Bitwise OR | Left to Right

Logical AND && Left to Right


Category Operators Associativity

Logical OR || Left to Right

Ternary ?: Right to Left

Assignment =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= Right to Left

Selection
statement

If statements, else if statements, Switch statements

Sr.No. Statement & Description

1 if–else statement

One if statement with an else statement. The instruction in


the else block will execute only when the given Boolean
condition fails to satisfy.

2 simple if statement

only if statements.
Looping
statements
Sr.No. Loop Type & Description

1 while loop

It repeats a statement or a group of statements while a given condition is true. It tests


the condition before executing the loop body.

2 for loop
It executes a sequence of statements multiple times and abbreviates the code that
manages the loop variable.

3 do...while loop
It is similar to a while statement, except that it tests the condition at the end of the loop
body

4 nested loops
You can use one or more loop inside any another while, for or do..while loop.

With respect to Object Oriented programming the term "Method" is used, not functions. When a function
Functions is a part of a class, it's called a method. C# is an OOP language and doesn't have functions that are
declared outside of classes, that's why all functions in C# are actually methods.

Here is the list of Method type in C#.

a. Pure virtual method.


b. Virtual method.
c. Abstract method.
d. Partial method.
e. Extension method.
f. Instance method.
g. Static method.

Parameter In C#, arguments can be passed to parameters either by value or by reference. Passing by reference
passing enables function members, methods, properties, indexers, operators, and constructors to change the
mechanisms value of the parameters and have that change persist in the calling environment. To pass a parameter by
reference with the intent of changing the value, use the ref, or out keyword. To pass by reference with the
intent of avoiding copying but not changing the value, use the in modifier
Sample using System;
program using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpTutorials
{
class Program
{
static void Main(string[] args)
{
string message = "Hello World!!";

Console.WriteLine(message);
}
}
}

Hello World

Requirements Specification - (minimum 2 new data types and 2 new operators is to be introduced as a
part of your language

Requirements Specification:

Datatypes:
Datatype: Memory: Format Specifier: Type of datatype:

Intger 4 %int Datatype for


Integer number
Flot 6 %flo Datatype for
Floating number
Charcter 3 %ctr Datatype for
Character
Lintger 8 %lint Datatype for long
integer

Operators:
Precedence Operator Description Associativity
1 <-1 Decrement (as i--) Left to right
1 >+1 Increment (as i+ Left to right
+)
3 ^ Multiplication Left to right
3 -:- Division Left to right
2 ++ Addition Left to right
2 -- subtraction Left to right

PROGRAMMING LANGUAGE DESIGN (Grammar)


<program> --> <functions>begin<functionbody>end<functions>

<functions> --> <function><functions>/ ε

<function> --> <funsignature>do<functionbody>;/<funsignature>;<function>/ε

<funsignature> --> <type> id ( <params> )

<params> --> <type> id<params>/,<params>/ε

<functionbody> --> <declaration> <statements>/ε

<declaration> --><type><var> <variable>; <declaration>/ε

<type> --> alpha/num/line/circle/void/table/Array/ε

<var> --> id/ id[ id ][ id ] /id[ id ] /id(id)(id)/id=id/ id<par>:=id<par>

<variable> --> ,<var><variable>/,id = id <variable>/ε

<statements> --> <iostatement>;<statements>/<assignstatement>;<statements>

/<loopstatement><statements>/<conditionstatement><statements>/return<more>;

/<parallel>;<statements>/ ε

12. <iostatement> --> outln(<stdout>)/ out(<stdout>)/in(<var>= ?<stdin>)

13. <stdout> --> id<st>/id

14. <st> --> ,id<st>/ε

15. <stdin> --> ,id= ?<stdin>/ε

16. <assignstatement> --> <var> = <more>/ id <assign>


id/<op>/id<par>:=id<par>/id(id)(id)/<td>
17. <more> --> <expression>/<E>/<td>/!<id>/[id<st>]

18. <expression> --> <sub><plus>

19. <plus> --> +<sub><plus>/ε

20. <sub> --> <mul><minus>

21. <minus> --> -<mul><minus>/ε

22. <mul> --> <div><mult>

23. <mult> --> *<div><mult>/ε

24. <div> --> <mod><divs>

25. <divs> --> /<mod><divs>/ε

26. <mod> --> <power><mods>

27. <mods> --> %<power><mods>/ε

28. <power> --> <root>^<power>/<root>

29. <root> --> (expression)/id/<expression>

30. <assign> --> += /-= / *= / /= / %=

31. <par> --> ,id<par>/ε

32. <E> --> id[id][id]<ev>/id(id)(id)<ev>

33. <ev> --> +<E><ev>/X<E><ev>/ε

34. <op> --> id++/id--

35. <loopstatements> --> for(<conditions>)do<statements>;/for(<conditions>)<statement>

/while(id<eq>)do<statements>;/while(id<eq>)<statement>

36. <conditions> --> <decl>;<exp>

37. <decl> --> <type> id=id

38. <exp> --> id <eq>;<op>

39. <eq> --> < <td>/> <td>/<= <td>/>= <td>/==<td>/!=<td>

40. <td> -->id/id(id<par>)

41. <statement> --> <iostatement><more>;/<assignstatement>;/<loopstatement>

/<conditionstatement>/return<more>; / ε
42. <conditionstatement> -->
when(<bool>)<statement><con>/when(<bool>)do<statements>;<con>

43. <bool> --> <ex>||<bool>/<ex>&&<bool>/<ex>/ε

44. <ex> --> id<eq>

45. <con> --> when else(<bool>)do<statements>;<els>/when else(<bool><statement>


<els>/ε

46. <els> --> else do<staements>;/else <statement>/ε

47. <parallel> --> start(id)/stopid

48. <id> --> [a-z]+ [A-Z] [0-9]*[a-z]*[A-Z]*(0-9)*/ <integerliteral>/<floatliteral>/<stringliteral>

TEST CASES

1.To add the two array's and print the resultant array.
begin
num a[25],b[25],c[25],n;
outln("Enter the number of element in array");
in(n=?);
outln("Enter the elements into array a");
for(i=0;i<n;i++)
do
in(a[i]=?);
;
outln("Enter the elements into array b");
for(i=0;i<n;i++)
do
in(b[i]=?);
;
for(i=0;i<n;i++)
do
c[i]=a[i]+b[i];
;
outln("The resultant array is c=?",c);
end

Input : Enter the number of elements in array


5
Enter the elements into array a
13254
Enter the elements into array b
12345
Output : The resultant array is c= [2,5,5,9,9]

2. To find the factorial of the given number.


num fact(num a);
begin
num fact, n;
out("Enter the number to find it's factorial");
in(n=?);
fact=fact(n);
outln("The factorial of ? is ? ",n,fact);
end
num fact(num a)
do
when(a==1¦¦a==0)
return 1;
else
return a*fact(a-1);
;

Input : Enter the number to find it's factorial


6
Output : The factorial of 6 is 720

3. To check the given numbers are equal or not.


begin
num a=15,b=15;
when (a==b)
outln(“both the numbers are equal”);
when else(a>b)
outln(“a is greater than b”);
else
outln(“b is greater than a”);
end
Output: both the numbers are equal

4. To swap the two given numbers.


void swap(num a, num b);
begin
num m=55 ,n=44;
outln(“values before swap m=? and n=?”,m,n);
swap(m,n);
end
void swap(num a, num b)
do
num temp;
temp=a;
a=b;
b=temp;
outln(“values after swap m=? and n=?”,a , b);
;
Output: values after swap m=44 and n=55

5.Example for all assignment operators


begin
num a = 5, c;
num x,y:= 2,4;
outln("x = ? y=?", x,y);
c = a;
outln("c = ?", c);
c += a; // c = c+a
outln("c = ?", c);
c -= a; // c = c-a
outln("c = ?", c);
c *= a; // c = c*a
outln("c = ?", c);
c /= a; // c = c/a
outln("c = ?", c);
c %= a; // c = c%a
outln("c = ?", c);
end
Output : x=2 y=4 c = 5
c = 10
c=5
c = 25
c=5
c=0
6. program to calculate the given expression a*b+c/d%e-f
begin
num a,b,c,d,e,f,sum=0;
outln(“Enter the values”);
in(a=?,b=?,c=?,d=?,e=?,f=?);
sum=a*b+c/d%e-f;
outln(“sum=?”,sum);
end
Input : Enter the values
1 2 3 4 5 6
Output : sum= -4

DERIVATIONS
1.To add the two array's and print the resultant array.

begin

num a[25],b[25],c[25],n;

outln("Enter the number of element in array");

in(n=?);

outln("Enter the elements into array a");

for(i=0;i<n;i++)

do

in(a[i]=?);

outln("Enter the elements into array b");

for(i=0;i<n;i++)

do

in(b[i]=?);

for(i=0;i<n;i++)

do

c[i]=a[i]+b[i];

outln("The resultant array is c=?",c);


end

<program> --> <functions>begin<functionbody>end<functions>

-->begin<declaration> <statements>end<functions>

-->begin<type><var> <variable>; <declaration><statements>end<functions>

-->begin num<var> <variable>; <declaration><statements>end<functions>

-->begin num a[25] <variable>; <declaration><statements>end<functions>

-->begin num a[25] ,b[25]<variable>; <declaration><statements>end<functions>

-->begin num a[25] ,b[25],<var><variable>; <declaration><statements>end<functions>

-->begin num a[25] ,b[25],c[25]<variable>; <declaration><statements>end<functions>

-->begin num a[25] ,b[25],c[25],<var><variable>; <declaration><statements>end<functions>

-->begin num a[25] ,b[25],c[25],n<variable>; <declaration><statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; <declaration><statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; <statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(<stdout>);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(id);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in


array”);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”);


<iostatement>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(id= ?
<stdin>);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?
<stdin>);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?);
outln(<stdout>);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?);
outln(id);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(<conditions>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(<type> id=id;<exp>)do<statements>;<statements>end<functions>
-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(id=id;<exp>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0;<exp>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; id <eq>;<op>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; id< <td>;<op>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; id< id;<op>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;<op>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;id++)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i+
+)do<iostatement>;<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(id= ?
<stdin>);<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?
<stdin>);<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln(<stdout>);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln(id);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array
b");<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for(<decl>;<exp>)do<statements>;<statements>end<functions>
-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for(<type> id=id;<exp>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( id=id;<exp>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0;i<n;i++)do<iostatement>;<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(id= ?<stdin>);<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; <loopstatement><statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(<conditions>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(<decl>;<exp>)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(i=0;i<n;i++)do<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(i=0;i<n;i+
+)do<assignstatement>;<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(i=0;i<n;i++)do id = <more>;<statements>;<statements>end<functions>
-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(i=0;i<n;i++)do c[i]=a[i]+b[i];<statements>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(i=0;i<n;i++)do c[i]=a[i]+b[i];;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(i=0;i<n;i++)do c[i]=a[i]+b[i];;
<iostatement>;<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(i=0;i<n;i++)do c[i]=a[i]+b[i];;
outln(<stdout>);<statements>end<functions>

-->begin num a[25] ,b[25],c[25],n; outln(“Enter the number of element in array”); in(n= ?); outln("Enter
the elements into array a"); for(i=0; i< n;i++)do in(a[i]=?);; outln("Enter the elements into array b");
for( i=0 i<n;i++)do in(b[i]=?);; for(i=0;i<n;i++)do c[i]=a[i]+b[i];; outln("The resultant array is c=?",c); end

2. To find the factorial of the given number.

num fact(num a);

begin

num fact, n;

out("Enter the number to find it's factorial");

in(n=?);

fact=fact(n);

outln("The factorial of ? is ? ",n,fact);

end

num fact(num a)

do

when(a==1¦¦a==0)

return 1;

else
return a*fact(a-1);

<program> --> <functions>begin<functionbody>end<functions>

--> <function><functions>begin<functionbody>end<functions>

--> <funsignature>;<function><functions>begin<functionbody>end<functions>

--> <type> id ( <params> );<function><functions>begin<functionbody>end<functions>

--> num fact(<type> id<params>);<function><functions>begin<functionbody>end<functions>

--> num fact (num a); <function><functions>begin<functionbody>end<functions>

--> num fact (num a);<function><functions>begin<functionbody>end<functions>

--> num fact (num a);begin<functionbody>end<functions>

--> num fact (num a);begin <declaration> <statements>end<functions>

--> num fact (num a);begin<type><var> <variable>; <declaration> <statements>end<functions>

--> num fact (num a);begin num fact,n; <declaration><statements>end<functions>

--> num fact (num a);begin num fact,n;<declaration><statements>end<functions>

--> num fact (num a);begin num fact,n;<iostatement>;<statements>end<functions>

--> num fact (num a);begin num fact,n; outln(<stdout>);<statements>end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's
factorial");<statements>end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's
factorial");<statements>end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's
factorial");<iostatement>;<statements>end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);

;<statements>end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);

;<assignstatements>;<statements>end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n);<statements>end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); <iostatement>;<statements>end<functions>
--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact);<statements>end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end <function><functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end <funsignature>do<functionbody>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end <type> id ( <params> )
do<functionbody>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do<functionbody>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do <declaration>
<statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do<statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num
a)do<conditionstatement><statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do
when(<bool>)<statements><con><statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do when(<ex>||
<bool>)<statements><con><statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do when(a==1||
<ex>)<statements><con><statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do when(a==1||
a==0)<statements><con><statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do when(a==1||a==0)
return<more>;<con><statements>;<functions>
--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do when(a==1||a==0) return
1;<con><statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do when(a==1||a==0) return
1;else return a*fact(a-1);<statements>;<functions>

--> num fact (num a);begin num fact,n;outln("Enter the number to find it's factorial"); in(n=?);
fact=fact(n); outln("The factorial of ? is ? ",n,fact); end num fact(num a)do when(a==1||a==0) return
1;else return a*fact(a-1);;

3. To check the given number is equal or not.

begin

num a=15,b=15;

when (a==b)

outln(“both the numbers are equal”);

when else(a>b)

outln(“a is greater than b”);

else

outln(“b is greater than a”);

end

<program> --> <functions>begin<functionbody>end<functions>

-->begin<declaration> <statements>end<functions>

-->begin<type><var> <variable>; <declaration><statements>end<functions>

-->begin num<var> <variable>; <declaration><statements>end<functions>

-->begin num a=15 <variable>; <declaration><statements>end<functions>

-->begin num a=15,<var><variable>; <declaration><statements>end<functions>

-->begin num a=15,id<variable>; <declaration><statements>end<functions>

-->begin num a=15,b=15; <declaration><statements>end<functions>

-->begin num a=15,b=15; <statements>end<functions>


-->begin num a=15,b=15; <conditionstatement><statements>end<functions>

-->begin num a=15,b=15; when(<bool>)<statement><con><statements>end<functions>

-->begin num a=15,b=15; when(a==b)<statement><con><statements>end<functions>

-->begin num a=15,b=15; when(a==b) <iostatement>;<con><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(<stdout>);<con><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are


equal”);<con><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when
else(<bool>)<statement><els><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when
else(a>b)<statement><els><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b)
<iostatement>;<statements><els><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b)
outln(<stdout>);<statements><els><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b) outln(“a is
greater than b”);<statements><els><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b) outln(“a is
greater than b”); <els><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b) outln(“a is
greater than b”); else <statement><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b) outln(“a is
greater than b”); else <iostatement>;<statements><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b) outln(“a is
greater than b”); else outln(<stdout>);<statements><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b) outln(“a is
greater than b”); else outln(“b is greater than
a”);<statements><statements><statements>end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b) outln(“a is
greater than b”); else outln(“b is greater than a”); end<functions>

-->begin num a=15,b=15; when(a==b) outln(“both the numbers are equal”); when else(a>b) outln(“a is
greater than b”); else outln(“b is greater than a”); end

4. To swap the two given numbers.


void swap(num a, num b);

begin

num m=55 ,n=44;

outln(“values before swap m=? and n=?”,m,n);

swap(m,n);

outln(“values after swap m=? and n=?”,a , b);

end

void swap(num a, num b)

do

num temp;

temp=a;

a=b;

b=temp;

<program> --> <functions>begin<functionbody>end<functions>

--> <function><functions>begin<functionbody>end<functions>

--> <funsignature>;<function><functions>begin<functionbody>end<functions>

--> <type> id ( <params> );<function><functions>begin<functionbody>end<functions>

--> void swap(<type> id<params>);<function><functions>begin<functionbody>end<functions>

--> void swap(num a, <type> id<params>); <function><functions>begin<functionbody>end<functions>

--> void swap(num a,num b); <function><functions>begin<functionbody>end<functions>

--> void swap(num a,num b); begin<functionbody>end<functions>

--> void swap(num a,num b); begin <declaration> <statements>end<functions>

--> void swap(num a,num b); begin<type><var> <variable>; <declaration> <statements>end<functions>

--> void swap(num a,num b); begin num m=22,id=id <variable>;


<declaration><statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; <declaration><statements>end<functions>
--> void swap(num a,num b); begin num m=22, n=44; <iostatement>;<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(<stdout>);<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(id<st>);<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and
n=?”,id<st>);<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and
n=?”,m,id<st>);<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and
n=?”,m,n);<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
<assignstatement>;<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
<td>;<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
id(id<par>);<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,id<par>);<statements>end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end<function><functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end <funsignature>do<functionbody>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end <type> id ( <params> )do<functionbody>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do<functionbody>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do<declaration> <statements><functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do <type><var> <variable>; <declaration>
<statements><functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; <statements><functions>
--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; <assignstatement>;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; <var> = <more>;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a;
<assignstatement>;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; <var> =
<more>;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b;
<assignstatement>;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b; <var> =
<more>;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b; b =
temp;<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b; b = temp; <iostatement>;
<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b; b = temp;
outln(<stdout>);<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b; b = temp; outln(“values after
swap m=? and n=?”,id<st>);<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b; b = temp; outln(“values after
swap m=? and n=?”,a,id);<statements>;<functions>

--> void swap(num a,num b); begin num m=22, n=44; outln(“values before swap m=? and n=?”,m,n);
swap(m,n);end void swap(num a, num b)do num temp; temp = a; a = b; b = temp; outln(“values after
swap m=? and n=?”,a,id);;
5. Example for all assignment operators

begin

num a = 5, c;

num x,y:= 2,4;

outln("x = ? y=?", x,y);

c = a;

outln("c = ?", c);

c += a; // c = c+a

outln("c = ?", c);

c -= a; // c = c-a

outln("c = ?", c);

c *= a; // c = c*a

outln("c = ?", c);

c /= a; // c = c/a

outln("c = ?", c);

c %= a; // c = c%a

outln("c = ?", c);

end

<program> --> <functions>begin<functionbody>end<functions>

-->begin<declaration> <statements>end<functions>

-->begin<type><var> <variable>; <declaration><statements>end<functions>

--> begin num id=id,<var><variable>; <declaration><statements>end<functions>

--> begin num a=5,c; <declaration><statements>end<functions>

--> begin num a=5,c; <type><var> <variable>; <declaration><statements>end<functions>

--> begin num a=5,c; num id<par>:=id<par><variable>; <declaration><statements>end<functions>

--> begin num a=5,c; num x,id<par>:=id<par><variable>; <declaration><statements>end<functions>

--> begin num a=5,c; num x,y:=id<par><variable>; <declaration><statements>end<functions>

--> begin num a=5,c; num x,y:=2,id<par><variable>; <declaration><statements>end<functions>


--> begin num a=5,c; num x,y:=2,4; <declaration><statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; <iostatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln(<stdout>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln(id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y);


<assignstatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); id = <more>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a;


<iostatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a;


outln(<stdout>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a;


outln(id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c
= ?",id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c
= ?",c);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c);
<assignstatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); id <assign> id
;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a
;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a
;<iostatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ;
outln(<stdout>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ;
outln(id<st>);<statements>end<functions>
--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c
= ?",id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
<assignstatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
id <assign> id ;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; ;<iostatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln(<stdout>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln(id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); <assignstatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); id <assign> id ;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;<iostatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln(<stdout>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln(id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c);<statements>end<functions>
--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c);
<assignstatement>;<statements>end<functions>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); id <assign> id ;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c *= a;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; <iostatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln(<stdout>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln(id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c);
<assignstatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c); id <assign> id
;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c); c %= a;
<iostatement>;<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c); c %= a;
outln(<stdout>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c); c %= a;
outln(id<st>);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c); c %= a; outln("c
= ?",c);<statements>end<functions>

--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c); c %= a; outln("c = ?",c);
end<functions>
--> begin num a=5,c; num x,y:=2,4; outln("x = ? y=?", x,y); c = a; outln("c = ?",c); c += a ; outln("c = ?",c);
c -= a; outln("c = ?",c); c *= a;outln("c = ?",c); c /= a; outln("c = ?",c); c %= a; outln("c = ?",c); end

6. program to calculate the given expression a*b+c/d%e-f

begin

num a,b,c,d,e,f,sum=0;

outln(“Enter the values”);

in(a=?,b=?,c=?,d=?,e=?,f=?);

sum=a*b+c/d%e-f;

outln(“sum=?”,sum);

end

<program> --> <functions>begin<functionbody>end<functions>

-->begin<declaration> <statements>end<functions>

-->begin<type><var> <variable>; <declaration><statements>end<functions>

-->begin num id ,<var><variable>; <declaration><statements>end<functions>

-->begin num a ,b,<var><variable>; <declaration><statements>end<functions>

-->begin num a ,b,c,<var><variable>; <declaration><statements>end<functions>

-->begin num a ,b,c,d,<var><variable>; <declaration><statements>end<functions>

-->begin num a ,b,c,d,e,<var><variable>; <declaration><statements>end<functions>

-->begin num a ,b,c,d,e,f,id = id <variable>; <declaration><statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0 <variable>; <declaration><statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; <declaration><statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; <statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; <iostatement>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(<stdout>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”);


<iostatement>;<statements>end<functions>
-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(id= ?
<stdin>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,id= ?


<stdin>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,id= ?


<stdin>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,id= ?


<stdin>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,id= ?


<stdin>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,id= ?


<stdin>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ?


,b=?,c=?,d=?,e=?,f= ?);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?);


<assignstatement>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); id =


<more>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
<expressin>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
<sub><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
<mul><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
<div><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
<mod><divs><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
<power><mods><divs><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
<root><mods><divs><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
id<mods><divs><mult><minus><plus>;<statements>end<functions>
-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
a<mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum =
a*<div><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
<mod><divs><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
<power><mods><divs><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
<root><mods><divs><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b<mods><divs><mult><minus><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b<plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+<sub><plus>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+c/d%e-f;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+c/d%e-f; <iostatement>;<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+c/d%e-f; outln(<stdout>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+c/d%e-f; outln(id<st>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+c/d%e-f; outln(“sum=?”,id<st>);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+c/d%e-f; outln(“sum=?”,sum);<statements>end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+c/d%e-f; outln(“sum=?”,sum); end<functions>

-->begin num a ,b,c,d,e,f,sum = 0; outln(“Enter the values”); in(a= ? ,b=?,c=?,d=?,e=?,f= ?); sum = a*
b+c/d%e-f; outln(“sum=?”,sum); enden
LIMITATIONS OF PROGRAMMING LANGUAGE

This programming language is not suitable for the 3D objects like circle, sphere.
It is just for those objects which are having lines like square, rectangle, triangle etc.
It finds an angle which approximately correct no exact values in decimal is possible to find.
No multiple inheritance is allowed.
More memory consumption.
Thinking functionally can be difficult for some tasks and applications.

FUTURE SCOPE

Faster, smarter programming, with fewer bugs.


Fast, stable, and solid algorithms for complex math.
The newer approaches include more structure and more abstraction.
Will be simpler language for manipulating data.

CONCLUSION
A programming language is a computer language engineered to create a standard form of
commands. These commands can be interpreted into a code understood by a machine.
Programming languages are always associated to one domain. This report will give an idea of a
programming language associated to 3D objects. Also it will give the specification required for
the development of a programming language. In this a line is shown how it is joined by
connecting two points. For that line, there are few test cases and the derivations for each test
cases. Different data types are used for defining functions like points, line, the angle on which it
is inclined. Some of the different terms are used for printing the output that is displaying on the
screen, for reading the input, also for conditions used.

References:
https://home.deib.polimi.it/pradella/PL.html
https://medium.com/@ibrahimgrses/contemporary-issues-in-the-design-of-a-new-language-
6b64d00a3c51
https://tomassetti.me/resources-create-programming-languages/
https://www.quora.com/How-can-you-design-a-new-programming-language
https://hackernoon.com/considerations-for-programming-language-design-a-rebuttal-
5fb7ef2fd4ba

Вам также может понравиться