Docsity

Assignment 1 for Program Languages Concepts | COP 4020, Assignments of Computer Science

Toggle sidebar
bg1
Assignment 1
COP-4020
Spring 2009
Assigned : Wednesday, February 04, 2009
Due Date : Wednesday, February 18, 2009 at 11:59 PM
1. Write a perl program which takes a line of input from the user and gives you all the
identifiers, integers, floating points, and operators also known as tokens. The tokens in
given input must be separated by a space. Definition of the various tokens is given below:
• Identifiers: Any sequence of characters which may only contains alphabets,
number of an underscore. The sequence must start with an alphabet or an
underscore.
• Integers: A sequence of characters which may only contain numbers from 0 to 9.
• Floating points: Any sequence of characters containing only numbers from 0 to 9
and one single dot operator.
• Operators: Any single character containing +, -, *, /, %, = or a two characters
containing ++, --, ==
Please make sure you put a space after every token in the input.
The following example will illustrate how your program is supposed to work when
executed:
$ Enter any string: sum12 = 99 + 23.5
Result:
Identifier: sum12
Integer: 99
Operators: =, +
Floating point : 23.5
$ Enter any string: _hello123 = 99 + 23.5 – 5687 * 0.345
/ 5673
Result:
Identifier: _hello123
Integer: 99, 5687, 5673
Operators: =, +, -, *, /
Floating point : 23.5, 0.345
Your program must be able to compile and execute under perl version 5.8.8 on
CISE machines. Please also note that your program must use regular expression to
analyze the tokens.

Partial preview of the text

Download Assignment 1 for Program Languages Concepts | COP 4020 and more Assignments Computer Science in PDF only on Docsity!

Assignment 1

COP-

Spring 2009

Assigned : Wednesday, February 04, 2009 Due Date : Wednesday, February 18, 2009 at 11:59 PM

1. Write a perl program which takes a line of input from the user and gives you all the

identifiers, integers, floating points, and operators also known as tokens. The tokens in given input must be separated by a space. Definition of the various tokens is given below:

  • Identifiers: Any sequence of characters which may only contains alphabets, number of an underscore. The sequence must start with an alphabet or an underscore.
  • Integers: A sequence of characters which may only contain numbers from 0 to 9.
  • Floating points: Any sequence of characters containing only numbers from 0 to 9 and one single dot operator.
  • Operators: Any single character containing +, -, *, /, %, = or a two characters containing ++, --, ==

Please make sure you put a space after every token in the input. The following example will illustrate how your program is supposed to work when executed:

$ Enter any string: sum12 = 99 + 23.

Result: Identifier: sum Integer: 99 Operators: =, + Floating point : 23.

$ Enter any string: _hello123 = 99 + 23.5 – 5687 * 0. / 5673

Result: Identifier: _hello Integer: 99, 5687, 5673 Operators: =, +, -, *, / Floating point : 23.5, 0.

Your program must be able to compile and execute under perl version 5.8.8 on

CISE machines. Please also note that your program must use regular expression to

analyze the tokens.