Sei sulla pagina 1di 15

A

Lab Manual
On
Principle of Programming
Language
(NCS-553)
Prepared By:
Rajeev Kumar
Asst. Professor
Department of IT

Hindustan College of Science & Technology, Farah, Mathura-281122


Department of Information Technology

Table of Content:1)
2)
3)
4)
5)

Syllabus
Time Table
Academic Calendar
List of Program
Lab Program

NCS- 503 Principle of Programming Language


Unit 1: Introduction
The Role of Programming Languages: Why Study Programming Languages, Towards Higher-Level
languages, Programming paradigms, Programming environments
Language Description: Syntactic structure, language Translation Issues: Programming language
Syntax, Stages in translation, Formal translation Models
Unit 2: Language Properties
Modeling Language Properties, Elementary Data Types, Encapsulation, Inheritance, Sequence
Control, Subprogram Control
Unit 3: Programming Paradigms
Imperative Programming: Statements, Types, Procedure Activations Object-Oriented Programming:
Grouping of Data and Operations, object oriented programming
Functional Programming: Elements, Programming in a typed language, Programming with lists
Unit 4: Other Programming Paradigms
Logic Programming, Concurrent Programming, Network Programming, Language Description:
Semantic Methods
Unit 5: Lambda Calculus
Introduction to Lambda Calculus, Simple types, Sub typing
Text books:
1. Programming Languages: Design and Implementations, Terrance W. Pratt, Marvin V.
Zelkowitz, T.V.Gopal,Fourth ed.,Prentice Hall
2. Programming languages: Concepts and Constucts, Ravi Sethi, Second Ed.,Pearson.
3. Types and programming Languages, Benjamin C. Pierce. The MIT Press Cambridge,
Massachusetts London, England
4. Programming Language Pragmatics Micheal Scott
References:
1. Concepts of Programming Languages, Robert W. Sebesta, 10th Ed.,Pearson

Hindustan College of Science & Technology, Farah, Mathura


Department of Information Technology
List of program for Principles of programming languages (NCS 553)
1. Define a LISP function to compute sum of squares.
2. Define a LISP function to compute difference of squares. (if x > y return x 2 -y 2 , otherwise y2
- x2 )
3. Define a Recursive LISP function to solve Ackermanns Function.
4. Define a Recursive LISP function to compute factorial of a given number.
5. Define a Recursive LISP function which takes one argument as a list and returns last element
of the list. (do not use last predicate)
6. Define a Recursive LISP function which takes one argument as a list and returns a list except
last element of the list. (do not use but last predicate)
7. Define a Recursive LISP function which takes one argument as a list and returns reverse of
the list. (do not use reverse predicate)
8. Define a Recursive LISP function which takes two arguments first, an atom, second, a list,

returns a list after removing first occurrence of that atom within the list.

9. Define a Recursive LISP function which appends two lists together.


10. Define a recursive LISP function which takes 2 lists as arguments and returns a list
containing alternate elements from each list.

Program No. 1
Objective-Define a LISP function to compute sum of squares
>>(defun sumsqr(x y)
(+(* x x)(* y y)))
SUMSQR
>>(sumsqr 2 3)
13

Program No. 2
Objective-Define a LISP function to compute difference of squares.(if x
> y return x2 y2 , Otherwise y2 x2 )
>(defun diffsqr(x y)
(if(> x y)
(-(* x x)(* y y))
(-(* y y)(* x x))))
DIFFSQR
>(diffsqr 2 3)
5
>(diffsqr 4 3)
7

Program No. 3
Objective-Define a Recursive LISP function to solve Ackermanns
Function.
>(defun ackermann (m n) "The Ackermann Function"
(cond ((= m 0) (+ n 1))
((= m 1) (+ n 2))
((= m 2) (+ 3 (* n 2)))
((= m 3) (+ 5 (* 8 (- (expt 2 n) 1))))
(t (cond ((= n 0) (ackermann (- m 1) 1))
(t (ackermann (- m 1) (ackermann m (- n 1))))
))
))
ACKERMANN
>>(ackermann 2 3 )
9
>>(defun digits (num) "number of digits of num"
(setq a 0)
(loop
(setq a (+ a 1))
(setq num (floor (/ num 10)))
(when (= num 0) (return a))
))
DIGITS
>>(digits (ackermann 2 3))
1

Program No. 4
Objective-Define a Recursive LISP function to compute the factorial of
given number.
>>(defun factorial (N)
"Compute the factorial of N."
(if (= N 1)
1
(* N (factorial (- N 1)))))
FACTORIAL
>>(factorial 5)
120

Program No. 5
Objective-Define a Recursive LISP function which takes one argument
as a list and return last element of the list. (Do not use last predicate.)
>(defun last_element(ab_list)
(first(reverse ab_list)))
LAST_ELEMENT
>(last_element '(a b c d))
D

Program No. 6
Objective- Define a Recursive LISP function which takes one argument
as a list and return list except last element of the list.(do not use butlast.)
>(defun not_last(ab_list)
(reverse(rest(reverse ab_list))))
NOT_LAST
>(not_last '(a b c d e))
(A B C D)

Program No. 7
Objective- Define a Recursive LISP function which takes one argument
as a list and return reverse of the list. (Do not use reverse predicate).
>>(defun list-append (L1 L2)
"Append L1 by L2."
(if (null L1)
L2
(cons (first L1) (list-append (rest L1) L2))))
LIST-APPEND
>>(defun show-list-reverse (L)
"Create a new list containing the elements of L in reversed order."
(if (null L)
nil
(list-append (show-list-reverse (rest L))
(list (first L)))))
SHOW-LIST-REVERSE
>>(show-list-reverse '(1 2 3 4))
(4 3 2 1)

Program No. 8
Objective- Define a Recursive LISP function which takes two
arguments first an atom second a list returns a list after removing first
occurrence of that atom within the list.
>(defun remove(lst elt)
(cond((null lst)nil)
((equal(first lst)elt)(rest lst))
(elt(cons(first lst)
(remove(rest lst)elt)))))
REMOVE
>>(remove '(1 2 3 3 4 4)'3)
(1 2 3 4 4)

Program No. 9
Objective-Define a Recursive LISP function which appends two lists
together.
>(defun list-append (L1 L2)
"Append L1 by L2."
(if (null L1)
L2
(cons (first L1) (list-append (rest L1) L2))))
LIST-APPEND
>>(list-append '(a b c) '(c d e))
(A B C C D E)

Program No. 10
Objective-Define a recursive LISP function which takes 2 lists as
arguments and returns a list containing alternate elements from each list.
>(defun alt(A B)
(cond
(( and (endp A) (endp B)) NIL)
(( endp A) B)
((endp B) A)
(T (cons (car A) (alt B (cdr A)))))
)
ALT
>(alt '(1 3 5) '(6 8 9))
(1 6 3 8 5 9)
>(alt '(a b c) '(d e g))
(A D B E C G)

Potrebbero piacerti anche