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

Assignment No.

02 Total Marks: 20
Semester: Fall 2021 BC180407494
CS508 – Modern Programming Languages Due Date: Dec 24, 2021

Problem Statement:
You are required to write a program in SNOBOL4 which will take input from user, store in an array and then
print elements of the array in reverse order; the last element should be displayed first, followed by second
last element and so on.

 At start, write your own VU Student ID using SNOBOL comments.


 Take a string as input from user.
 Check input's length using SNOBOL4 built-in functions as given below; less than 1 or more
than 50 characters is an invalid length.
 Define an array of size 50 and initialize with hyphen "-".
 Design a pattern, which should contain alphanumeric characters only (i.e., A to Z, a to z and
0 to 9).
 Create a loop using 'Go to field', which will match characters of input with pattern:
o If any character is matched then store it in array.
o Also store that character in a separate variable using concatenation feature.
o If not matched, then ignore it.
o Move to the next character.
 Now create two more loops using 'Go to field':
o First loop will take all elements (except hyphen "-") from array in original order and store
them in a separate variable using concatenation feature.
o Second loop will also take all elements (except hyphen "-") from array, but in reverse
order, and store them in a separate variable using concatenation feature.
 At end, simply print all the characters stored in three different variables on console with
appropriate message.

For example, if input string is


A quick brown fox jumps over the lazy dog.

Then your program must print on console,

1
Assignment No. 02 Total Marks: 20
Semester: Fall 2021 BC180407494
CS508 – Modern Programming Languages Due Date: Dec 24, 2021

Valid Characters: Aquickbrownfoxjumpsoverthelazydog


Original Order: A, q, u, i, c, k, b, r, o, w, n, f, o, x, j, u, m, p, s, o, v, e, r, t, h, e, l, a, z, y, d, o, g,
Reverse Order: g, o, d, y, z, a, l, e, h, t, r, e, v, o, s, p, m, u, j, x, o, f, n, w, o, r, b, k, c, i, u, q, A,

However, in case, if input length is smaller than 1 or greater than 50 then following message should
be displayed.
Invalid: input should contain 1 to 50 characters.

Note:
It is required to make sure that the program should consider both small and capital alphabets ( i.e., a
to z & A to Z) and numbers (i.e., 0 to 9) as valid characters. Spaces and punctuation marks (! . , ; : ? etc.) must
be ignored. For example, the output of program for following string should be;

Input:
"Help!" she cried. "I can't swim!"

Output:
Valid Characters: HelpshecriedIcantswim
Original Order: H, e, l, p, s, h, e, c, r, i, e, d, I, c, a, n, t, s, w, i, m,
Reverse Order: m, i, w, s, t, n, a, c, I, d, e, i, r, c, e, h, s, p, l, e, H,

Compiler:

For compilation purpose, you can consult any online compiler, like
https://tio.run/#snobol4

Valid Characters:

Type Characters
Numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Small Alphabets a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
Capital Alphabets A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
SNOBOL4 Built-in Functions:

2
Assignment No. 02 Total Marks: 20
Semester: Fall 2021 BC180407494
CS508 – Modern Programming Languages Due Date: Dec 24, 2021

Function Description
SIZE(S) Return the number of characters in string S.
GT(X, Y) Integer X is greater than integer Y.
GE(X, Y) Integer X is greater than or equal to integer Y.
LT(X, Y) Integer X is less than integer Y.
LE(X, Y) Integer X is less than or equal to integer Y.

Sample Output:

Fig. Sample Output

Solution Code:

*bc180407494
STRING = INPUT
MSG = STRING
COUNT = SIZE(MSG)

CHAR_ARRAY = DUPL('-',50 - SIZE(50))

3
Assignment No. 02 Total Marks: 20
Semester: Fall 2021 BC180407494
CS508 – Modern Programming Languages Due Date: Dec 24, 2021

VALID_ARRAY = ''
ORIGNAL_ORDER = ''
REVERSE_ORDER = ''

PATTERN = ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' |
'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | 'a' | 'b' | 'c' | 'd' |
'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z') $ A
HYPHEN = ('-') $ H

LT(COUNT,1) :S(E2) F(E1)


E1 GT(COUNT,50) :S(E2) F(P1)
E2 MSG = 'Invalid characters' :(S3)

P1 STRING PATTERN = :S(P2) F(P3)


P2 CHAR_ARRAY = CHAR_ARRAY '' A :(P1)

P3 CHAR_ARRAY HYPHEN = :S(P3)F(P4)


P4 CHAR_ARRAY PATTERN = :S(V1)F(P5)
V1 VALID_ARRAY = VALID_ARRAY '' A :(O1)
O1 ORIGNAL_ORDER = ORIGNAL_ORDER A ', ' :(R1)
R1 REVERSE_ORDER = REVERSE_ORDER ' ,' A :(P4)

P5 REVERSE_ORDER = REVERSE(REVERSE_ORDER) :(M1)

M1 MSG = 'Valid Characters : ' VALID_ARRAY '' :(S1)


S1 OUTPUT = MSG

4
Assignment No. 02 Total Marks: 20
Semester: Fall 2021 BC180407494
CS508 – Modern Programming Languages Due Date: Dec 24, 2021

MSG = 'Orignal Order : ' ORIGNAL_ORDER '' :(S2)


S2 OUTPUT = MSG

MSG = 'Reverse Order : ' REVERSE_ORDER '' :(S3)


S3 OUTPUT = MSG

END

You might also like